Copyright (C) Kevin Larke 2009-2020

This file is part of libcm.

libcm is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

libcm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See the GNU General Public License distributed with the libcm package or look here: .


cmMidiFilePlay : Device indepenent MIDI file player.

typedef cmHandle_t cmMfpH_t;
typedef cmRC_t     cmMfpRC_t;

typedef void (*cmMfpCallback_t)( void* userCbPtr, unsigned dmicros, const cmMidiTrackMsg_t* msgPtr );

enum
{
  kOkMfpRC = cmOkRC,             // 0
  kInvalidHandleMfpRC,           // 1
  kFileOpenFailMfpRC,            // 2 
  kInvalidFileMfpRC,             // 3
  kMemAllocFailMfpRC,            // 4
  kSmpteTickNotImpleMfpRC,       // 5
  kEndOfFileMfpRC,               // 6
  kSmpteTickNotImplMfpRC         // 7
  
};

extern cmMfpH_t cmMfpNullHandle;

cmMfpRC_t cmMfpCreate(     cmMfpH_t* hp, cmMfpCallback_t cbFunc, void* userCbPtr, cmCtx_t* ctx );
cmMfpRC_t cmMfpDestroy(    cmMfpH_t* hp );
bool      cmMfpIsValid(    cmMfpH_t h );

// Load a MIDI file into the player. This MIDI file will be automatically
// closed when a new file is loaded at a later time or the MIDI file player handle is destroyed.
cmMfpRC_t cmMfpLoadFile(   cmMfpH_t h, const char* fn );

// Load a MIDI file into the player using a file owned by the host.
// This file will NOT be closed when a new file is loaded at a later time
// or the MIDI file player handle is destroyed.
cmMfpRC_t cmMfpLoadHandle( cmMfpH_t h, cmMidiFileH_t mfH );

// Reset the play position of the player to an offset in microseconds from 
// the beginning of the file.  If there are no message at or after 'offsMicrosecs'
// then the function will return kEndOfFileMfpRC.
cmMfpRC_t cmMfpSeek(       cmMfpH_t h, unsigned offsMicrosecs );

// This is the driving clock call for the player. 'deltaMicroSecs' is the
// elapsed time in microseconds since the last call to this function.
// Call to 'cbFunc', as set in by cmMfpCreate() occur from this function.
cmMfpRC_t cmMfpClock(      cmMfpH_t h, unsigned deltaMicroSecs );

cmMfpRC_t cmMfpTest( const char* fn, cmCtx_t* ctx );

cmRC_t cmMfpTest2( const char* midiFn, const char* audioFn, cmCtx_t* ctx );