00001 #ifndef PORT_MIDI_H
00002 #define PORT_MIDI_H
00003 #ifdef __cplusplus
00004 extern "C" {
00005 #endif
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #ifndef WIN32
00096
00097 #include <stdint.h>
00098 #else
00099 #ifndef INT32_DEFINED
00100
00101
00102
00103 typedef int int32_t;
00104 typedef unsigned int uint32_t;
00105 #define INT32_DEFINED
00106 #endif
00107 #endif
00108
00109 #ifdef _WINDLL
00110 #define PMEXPORT __declspec(dllexport)
00111 #else
00112 #define PMEXPORT
00113 #endif
00114
00115 #ifndef FALSE
00116 #define FALSE 0
00117 #endif
00118 #ifndef TRUE
00119 #define TRUE 1
00120 #endif
00121
00122
00123 #define PM_DEFAULT_SYSEX_BUFFER_SIZE 1024
00124
00126 typedef enum {
00127 pmNoError = 0,
00128 pmNoData = 0,
00129 pmGotData = 1,
00130 pmHostError = -10000,
00131 pmInvalidDeviceId,
00136 pmInsufficientMemory,
00137 pmBufferTooSmall,
00138 pmBufferOverflow,
00139 pmBadPtr,
00140
00141
00142
00143 pmBadData,
00144 pmInternalError,
00145 pmBufferMaxSize
00146
00147 } PmError;
00148
00153 PMEXPORT PmError Pm_Initialize( void );
00154
00159 PMEXPORT PmError Pm_Terminate( void );
00160
00163 typedef void PortMidiStream;
00164 #define PmStream PortMidiStream
00165
00180 PMEXPORT int Pm_HasHostError( PortMidiStream * stream );
00181
00182
00187 PMEXPORT const char *Pm_GetErrorText( PmError errnum );
00188
00193 PMEXPORT void Pm_GetHostErrorText(char * msg, unsigned int len);
00194
00195 #define HDRLENGTH 50
00196 #define PM_HOST_ERROR_MSG_LEN 256u
00197
00198
00205 typedef int PmDeviceID;
00206 #define pmNoDevice -1
00207 typedef struct {
00208 int structVersion;
00209 const char *interf;
00210 const char *name;
00211 int input;
00212 int output;
00213 int opened;
00215 } PmDeviceInfo;
00216
00218 PMEXPORT int Pm_CountDevices( void );
00261 PMEXPORT PmDeviceID Pm_GetDefaultInputDeviceID( void );
00263 PMEXPORT PmDeviceID Pm_GetDefaultOutputDeviceID( void );
00264
00269 typedef int32_t PmTimestamp;
00270 typedef PmTimestamp (*PmTimeProcPtr)(void *time_info);
00271
00273 #define PmBefore(t1,t2) ((t1-t2) < 0)
00274
00287 PMEXPORT const PmDeviceInfo* Pm_GetDeviceInfo( PmDeviceID id );
00288
00353 PMEXPORT PmError Pm_OpenInput( PortMidiStream** stream,
00354 PmDeviceID inputDevice,
00355 void *inputDriverInfo,
00356 int32_t bufferSize,
00357 PmTimeProcPtr time_proc,
00358 void *time_info );
00359
00360 PMEXPORT PmError Pm_OpenOutput( PortMidiStream** stream,
00361 PmDeviceID outputDevice,
00362 void *outputDriverInfo,
00363 int32_t bufferSize,
00364 PmTimeProcPtr time_proc,
00365 void *time_info,
00366 int32_t latency );
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00390 #define PM_FILT_ACTIVE (1 << 0x0E)
00391
00392 #define PM_FILT_SYSEX (1 << 0x00)
00393
00394 #define PM_FILT_CLOCK (1 << 0x08)
00395
00396 #define PM_FILT_PLAY ((1 << 0x0A) | (1 << 0x0C) | (1 << 0x0B))
00397
00398 #define PM_FILT_TICK (1 << 0x09)
00399
00400 #define PM_FILT_FD (1 << 0x0D)
00401
00402 #define PM_FILT_UNDEFINED PM_FILT_FD
00403
00404 #define PM_FILT_RESET (1 << 0x0F)
00405
00406 #define PM_FILT_REALTIME (PM_FILT_ACTIVE | PM_FILT_SYSEX | PM_FILT_CLOCK | \
00407 PM_FILT_PLAY | PM_FILT_UNDEFINED | PM_FILT_RESET | PM_FILT_TICK)
00408
00409 #define PM_FILT_NOTE ((1 << 0x19) | (1 << 0x18))
00410
00411 #define PM_FILT_CHANNEL_AFTERTOUCH (1 << 0x1D)
00412
00413 #define PM_FILT_POLY_AFTERTOUCH (1 << 0x1A)
00414
00415 #define PM_FILT_AFTERTOUCH (PM_FILT_CHANNEL_AFTERTOUCH | PM_FILT_POLY_AFTERTOUCH)
00416
00417 #define PM_FILT_PROGRAM (1 << 0x1C)
00418
00419 #define PM_FILT_CONTROL (1 << 0x1B)
00420
00421 #define PM_FILT_PITCHBEND (1 << 0x1E)
00422
00423 #define PM_FILT_MTC (1 << 0x01)
00424
00425 #define PM_FILT_SONG_POSITION (1 << 0x02)
00426
00427 #define PM_FILT_SONG_SELECT (1 << 0x03)
00428
00429 #define PM_FILT_TUNE (1 << 0x06)
00430
00431 #define PM_FILT_SYSTEMCOMMON (PM_FILT_MTC | PM_FILT_SONG_POSITION | PM_FILT_SONG_SELECT | PM_FILT_TUNE)
00432
00433
00434 PMEXPORT PmError Pm_SetFilter( PortMidiStream* stream, int32_t filters );
00435
00436 #define Pm_Channel(channel) (1<<(channel))
00437
00452 PMEXPORT PmError Pm_SetChannelMask(PortMidiStream *stream, int mask);
00453
00462 PMEXPORT PmError Pm_Abort( PortMidiStream* stream );
00463
00469 PMEXPORT PmError Pm_Close( PortMidiStream* stream );
00470
00494 PmError Pm_Synchronize( PortMidiStream* stream );
00495
00496
00504 #define Pm_Message(status, data1, data2) \
00505 ((((data2) << 16) & 0xFF0000) | \
00506 (((data1) << 8) & 0xFF00) | \
00507 ((status) & 0xFF))
00508 #define Pm_MessageStatus(msg) ((msg) & 0xFF)
00509 #define Pm_MessageData1(msg) (((msg) >> 8) & 0xFF)
00510 #define Pm_MessageData2(msg) (((msg) >> 16) & 0xFF)
00511
00512 typedef int32_t PmMessage;
00578 typedef struct {
00579 PmMessage message;
00580 PmTimestamp timestamp;
00581 } PmEvent;
00582
00613 PMEXPORT int Pm_Read( PortMidiStream *stream, PmEvent *buffer, int32_t length );
00614
00619 PMEXPORT PmError Pm_Poll( PortMidiStream *stream);
00620
00634 PMEXPORT PmError Pm_Write( PortMidiStream *stream, PmEvent *buffer, int32_t length );
00635
00642 PMEXPORT PmError Pm_WriteShort( PortMidiStream *stream, PmTimestamp when, int32_t msg);
00643
00647 PMEXPORT PmError Pm_WriteSysEx( PortMidiStream *stream, PmTimestamp when, unsigned char *msg);
00648
00651 #ifdef __cplusplus
00652 }
00653 #endif
00654 #endif