#include #include #include #include #include #include #include /*** (^_^;) Bug Recovery of SGI Media Library --> Original MIDI Defines !! (^_^;) ***/ #define MES(x) ( (x[0]).mm.msgbuf ) #define midi_get_status(x) ( ( ( ( MES(x) & 0xf0000000 ) == 0x60000000 ) || \ ( ( MES(x) & 0xf0000000 ) == 0x40000000 ) ) ? \ ( ( MES(x) & 0x00f00000 ) >> 16 ) : 0 ) /* Port #2 */ #define midi_get_channel(x) ( ( MES(x) & 0x000f0000 ) >> 16 ) /* 1 - 16 channel Only ! */ #define midi_get_keyno(x) ( ( MES(x) & 0x00007f00 ) >> 8 ) /* device ID : #1 Only ! */ #define midi_get_velocity(x) ( ( MES(x) & 0x0000007f ) ) char tb[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /****** SPEC : This program only receive MIDI [D8 nn]-[DF nn]. If shell "play_d8_00" exists current directory, it plays when MIDI [D8 00] comes. If not exist, play nothing. Shell script files are "play_d8_00" to "play_df_7f" --- 8 * 128 = 1024. *******/ void main(int argc, char** argv) { unsigned char status, channel, keyno, velocity; int i, j, m[8][128]; FILE *fp; char filename[16]; MIport *midi_port; MIevent midi[10000]; MIconfig *c; c = MInewconfig(); printf("\n[ Asian Edge ] : Let's start MIDI to process control... (^_^)\n"); for(i=0;i<8;i++){ for(j=0;j<128;j++){ m[i][j] = 0; strcpy( filename, "play_d0_00" ); filename[6] = tb[8+i]; filename[8] = tb[j/16]; filename[9] = tb[j%16]; if ( ( fp = fopen( filename, "r" ) ) != NULL ){ m[i][j] = 1; printf(" file [%s] ok. \n", filename ); fclose( fp ); } } } loop: midi_port = MInewport(); if( MIopen( midi_port, "r", &c ) < 0 ) exit(-1); while(1){ if( MIreceive( midi_port, midi, 1 ) > 0 ){ status = midi_get_status( midi ); channel = midi_get_channel( midi ); keyno = midi_get_keyno( midi ); if( ( status == 0xd0 ) && ( channel > 0x07 ) ){ if( m[channel-8][keyno] != 0 ) break; } } } MIclose( midi_port ); MIfreeport( midi_port ); if( fork() == 0 ) { strcpy( filename, "play_d0_00" ); filename[6] = tb[channel]; filename[8] = tb[keyno/16]; filename[9] = tb[keyno%16]; execl( filename, filename, NULL ); exit(0); } goto loop; }