X-Git-Url: https://hackdaworld.org/gitweb/?p=sound-tools%2Fossmidi.git;a=blobdiff_plain;f=midiio.c;fp=midiio.c;h=8414a975ec2f3a669e6b6a0baa23f5bb07385408;hp=dc4cd78ac56dc85eccb4086ee3a0c833e10713ab;hb=bc1a171461ae70604afcd46eaa969f23597aa1a4;hpb=47eeeaf31e9ffc066a7282fc85e216e544a3612e diff --git a/midiio.c b/midiio.c index dc4cd78..8414a97 100644 --- a/midiio.c +++ b/midiio.c @@ -18,13 +18,16 @@ #include "midiio.h" /* soem defines */ -#define MIDI_DEVICE /dev/midi +#define MIDI_DEVICE "/dev/midi" #define NOTE_ON 0x90 #define NOTE_OFF 0x80 #define NOTE_DATA 0x7F #define CH_MASK 0x0F #define VEL_MASK 0x7F +#define MSB_MASK 0xF0 +#define LSB_MASK 0x0F + /* global, do we need sockets global? */ int midi_fd; @@ -64,31 +67,64 @@ int note_off(int fd,int chan,int note,int vel) { return 0; } -int midi_read_msg(int fd,char *buf) { +int midi_read(int fd,char *buf) { int bytes_read; - bytes_read=read(fd,buf,10); + bytes_read=read(fd,buf,1); return bytes_read; } +int midi_read_msg(int fd,char *buf) { + char tmp_buf; + int i; + midi_read(fd,&tmp_buf); + buf[0]=tmp_buf; + + /* decide how much to read */ + if(((buf[0]&MSB_MASK)==PROGRAM_CHANGE) || ((buf[0]&MSB_MASK)==CHANNEL_PRESSURE)) { + printf("debug: program change or channel pressure event detected\n"); + midi_read(fd,&tmp_buf); + buf[1]=tmp_buf; + return 2; + } else { + printf("debug: none program change or channel pressure event detected\n"); + for(i=0;i<2;i++) { + midi_read(fd,&tmp_buf); + buf[i+1]=tmp_buf; + } + return 3; + } +} + + + + #ifdef TEST_API /* test the io api ... */ int main(int argc,char **argv) { - int note,channel,i,j; - char my_buf[10]="MIDIMIDI"; + int note,channel,i,j,k; + char my_buf[3]; if(argc>1) { note=atoi(argv[2]); channel=atoi(argv[1]); } - midi_fd=open("/dev/sound/midi",O_RDWR); + midi_fd=open(MIDI_DEVICE,O_RDWR); + printf("debug: midi_fd = %d\n",midi_fd); printf("reading ...\n"); - i=midi_read_msg(midi_fd,my_buf); - for(j=0;j=0;j--) printf("%s%d%s",(j==7?"|":""), + (((int)my_buf[k] & (1<0?1:0), + (j==0?"|\t":"|")); + } printf("\n"); + printf("sleep for 3 secs ...\n"); + sleep(3); all_stop(midi_fd); sleep(2);