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.

cmMidiPort.h 4.4KB

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