libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef cmMidiPort_h
  2. #define cmMidiPort_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef unsigned cmMpRC_t;
  7. // Flags used to identify input and output ports on MIDI devices
  8. enum
  9. {
  10. kInMpFl = 0x01,
  11. kOutMpFl = 0x02
  12. };
  13. enum
  14. {
  15. kOkMpRC = cmOkRC,
  16. kCfStringErrMpRC,
  17. kLHeapErrMpRC,
  18. kThreadErrMpRC,
  19. kSysErrMpRC,
  20. kInvalidArgMpRC,
  21. kMemAllocFailMpRC,
  22. kNotImplMpRC,
  23. kCbNotFoundMpRC
  24. };
  25. typedef void (*cmMpCallback_t)( const cmMidiPacket_t* pktArray, unsigned pktCnt );
  26. //===============================================================================================
  27. // MIDI Parser
  28. //
  29. typedef cmHandle_t cmMpParserH_t;
  30. // 'cbFunc' and 'cbDataPtr' are optional. If 'cbFunc' is not supplied in the call to
  31. // cmMpParserCreate() it may be supplied later by cmMpParserInstallCallback().
  32. // 'bufByteCnt' defines is the largest complete system-exclusive message the parser will
  33. // by able to transmit. System-exclusive messages larger than this will be broken into
  34. // multiple sequential callbacks.
  35. cmMpParserH_t cmMpParserCreate( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned bufByteCnt, cmRpt_t* rpt );
  36. void cmMpParserDestroy( cmMpParserH_t* hp );
  37. unsigned cmMpParserErrorCount( cmMpParserH_t h );
  38. void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiByte_t* buf, unsigned bufByteCnt );
  39. // The following two functions are intended to be used togetther.
  40. // Use cmMpParserMidiTriple() to insert pre-parsed msg's to the output buffer,
  41. // and then use cmMpParserTransmit() to send the buffer via the parsers callback function.
  42. // Set the data bytes to 0xff if they are not used by the message.
  43. cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, unsigned deltaMicroSecs, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 );
  44. cmMpRC_t cmMpParserTransmit( cmMpParserH_t h );
  45. // Install/Remove additional callbacks.
  46. cmMpRC_t cmMpParserInstallCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
  47. cmMpRC_t cmMpParserRemoveCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
  48. // Returns true if the parser uses the given callback.
  49. bool cmMpParserHasCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
  50. //===============================================================================================
  51. // MIDI Device Interface
  52. //
  53. // 'cbFunc' and 'cbDataPtr' are optional (they may be set to NULL). In this case
  54. // 'cbFunc' and 'cbDataPtr' may be set in a later call to cmMpInstallCallback().
  55. cmMpRC_t cmMpInitialize( cmCtx_t* ctx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr );
  56. cmMpRC_t cmMpFinalize();
  57. bool cmMpIsInitialized();
  58. unsigned cmMpDeviceCount();
  59. const char* cmMpDeviceName( unsigned devIdx );
  60. unsigned cmMpDeviceNameToIndex(const cmChar_t* name);
  61. unsigned cmMpDevicePortCount( unsigned devIdx, unsigned flags );
  62. const char* cmMpDevicePortName( unsigned devIdx, unsigned flags, unsigned portIdx );
  63. unsigned cmMpDevicePortNameToIndex( unsigned devIdx, unsigned flags, const cmChar_t* name );
  64. cmMpRC_t cmMpDeviceSend( unsigned devIdx, unsigned portIdx, cmMidiByte_t st, cmMidiByte_t d0, cmMidiByte_t d1 );
  65. cmMpRC_t cmMpDeviceSendData( unsigned devIdx, unsigned portIdx, const cmMidiByte_t* dataPtr, unsigned byteCnt );
  66. // Set devIdx to -1 to assign the callback to all devices.
  67. // Set portIdx to -1 to assign the callback to all ports on the specified devices.
  68. //
  69. cmMpRC_t cmMpInstallCallback( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr );
  70. cmMpRC_t cmMpRemoveCallback( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr );
  71. bool cmMpUsesCallback( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr );
  72. void cmMpReport( cmRpt_t* rpt );
  73. void cmMpTest( cmCtx_t* ctx );
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif