Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31098
Modified Files: Tag: desiredata s_midi_pm.c Log Message: cleanup
Index: s_midi_pm.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_midi_pm.c,v retrieving revision 1.4.4.1.2.8.2.1 retrieving revision 1.4.4.1.2.8.2.2 diff -C2 -d -r1.4.4.1.2.8.2.1 -r1.4.4.1.2.8.2.2 *** s_midi_pm.c 30 Nov 2006 03:57:10 -0000 1.4.4.1.2.8.2.1 --- s_midi_pm.c 28 Jun 2007 05:29:19 -0000 1.4.4.1.2.8.2.2 *************** *** 28,124 **** static int mac_nmidioutdev;
! void sys_do_open_midi(int nmidiin, int *midiinvec, ! int nmidiout, int *midioutvec) ! { int i = 0, j, devno; - int n = 0; PmError err; - Pt_Start(1, 0, 0); /* start a timer with millisecond accuracy */ - mac_nmidiindev = 0; ! for (i = 0; i < nmidiin; i++) ! { ! int found = 0,count = Pm_CountDevices(); ! for (j = 0, devno = 0; j < count && !found; j++) ! { const PmDeviceInfo *info = Pm_GetDeviceInfo(j); ! if (info->input) ! { ! if (devno == midiinvec[i]) ! { err = Pm_OpenInput(&mac_midiindevlist[mac_nmidiindev], j, NULL, 100, NULL, NULL); if (err != pmNoError) ! post("could not open midi input %d (%s): %s", ! j, info->name, Pm_GetErrorText(err)); ! ! else ! { ! if (sys_verbose) ! post("Midi Input (%s) opened.", ! info->name); mac_nmidiindev++; } ! found = 1; } devno++; } } ! if(!found) ! post("could not find midi device %d",midiinvec[i]); ! } ! mac_nmidioutdev = 0; ! for (i = 0; i < nmidiout; i++) ! { ! int found = 0,count = Pm_CountDevices(); ! for (j = 0, devno = 0; j < count && !found; j++) ! { const PmDeviceInfo *info = Pm_GetDeviceInfo(j); ! if (info->output) ! { ! if (devno == midioutvec[i]) ! { ! err = Pm_OpenOutput( ! &mac_midioutdevlist[mac_nmidioutdev], ! j, NULL, 0, NULL, NULL, 0); if (err != pmNoError) ! post("could not open midi output %d (%s): %s", ! j, info->name, Pm_GetErrorText(err)); ! else ! { ! if (sys_verbose) ! post("Midi Output (%s) opened.", ! info->name); mac_nmidioutdev++; } ! found = 1; } devno++; } } ! if(!found) ! post("could not find midi device %d",midioutvec[i]); ! } }
! void sys_close_midi( void) ! { int i; ! for (i = 0; i < mac_nmidiindev; i++) ! Pm_Close(mac_midiindevlist[i]); mac_nmidiindev = 0; ! for (i = 0; i < mac_nmidioutdev; i++) ! Pm_Close(mac_midioutdevlist[i]); ! mac_nmidioutdev = 0; }
! void sys_putmidimess(int portno, int a, int b, int c) ! { PmEvent buffer; /* fprintf(stderr, "put 1 msg %d %d\n", portno, mac_nmidioutdev); */ ! if (portno >= 0 && portno < mac_nmidioutdev) ! { buffer.message = Pm_Message(a, b, c); buffer.timestamp = 0; --- 28,92 ---- static int mac_nmidioutdev;
! void sys_do_open_midi(int nmidiin, int *midiinvec, int nmidiout, int *midioutvec) { int i = 0, j, devno; PmError err; Pt_Start(1, 0, 0); /* start a timer with millisecond accuracy */ mac_nmidiindev = 0; ! for (i = 0; i < nmidiin; i++) { ! int found = 0,count = Pm_CountDevices(); ! for (j = 0, devno = 0; j < count && !found; j++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(j); ! if (info->input) { ! if (devno == midiinvec[i]) { err = Pm_OpenInput(&mac_midiindevlist[mac_nmidiindev], j, NULL, 100, NULL, NULL); if (err != pmNoError) ! post("could not open midi input %d (%s): %s", j, info->name, Pm_GetErrorText(err)); ! else { ! if (sys_verbose) post("Midi Input (%s) opened.", info->name); mac_nmidiindev++; } ! found = 1; } devno++; } } ! if (!found) post("could not find midi device %d",midiinvec[i]); ! } mac_nmidioutdev = 0; ! for (i = 0; i < nmidiout; i++) { ! int found = 0,count = Pm_CountDevices(); ! for (j = 0, devno = 0; j < count && !found; j++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(j); ! if (info->output) { ! if (devno == midioutvec[i]) { ! err = Pm_OpenOutput(&mac_midioutdevlist[mac_nmidioutdev],j,NULL,0,NULL,NULL,0); if (err != pmNoError) ! post("could not open midi output %d (%s): %s",j,info->name,Pm_GetErrorText(err)); ! else { ! if (sys_verbose) post("Midi Output (%s) opened.",info->name); mac_nmidioutdev++; } ! found = 1; } devno++; } } ! if (!found) post("could not find midi device %d",midioutvec[i]); ! } }
! void sys_close_midi (void) { int i; ! for (i = 0; i < mac_nmidiindev; i++) Pm_Close(mac_midiindevlist[i]); mac_nmidiindev = 0; ! for (i = 0; i < mac_nmidioutdev; i++) Pm_Close(mac_midioutdevlist[i]); ! mac_nmidioutdev = 0; }
! void sys_putmidimess(int portno, int a, int b, int c) { PmEvent buffer; /* fprintf(stderr, "put 1 msg %d %d\n", portno, mac_nmidioutdev); */ ! if (portno >= 0 && portno < mac_nmidioutdev) { buffer.message = Pm_Message(a, b, c); buffer.timestamp = 0; *************** *** 128,212 **** }
! static void writemidi4(PortMidiStream* stream, int a, int b, int c, int d) ! { PmEvent buffer; buffer.timestamp = 0; ! buffer.message = ((a & 0xff) | ((b & 0xff) << 8) ! | ((c & 0xff) << 16) | ((d & 0xff) << 24)); Pm_Write(stream, &buffer, 1); }
! ! void sys_putmidibyte(int portno, int byte) ! { ! /* try to parse the bytes into MIDI messages so they can ! fit into PortMidi buffers. */ static int mess[4]; static int nbytes = 0, sysex = 0, i; if (byte >= 0xf8) /* MIDI real time */ writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0); ! else if (byte == 0xf0) ! { mess[0] = 0xf7; nbytes = 1; sysex = 1; ! } ! else if (byte == 0xf7) ! { mess[nbytes] = byte; ! for (i = nbytes+1; i < 4; i++) ! mess[i] = 0; ! writemidi4(mac_midioutdevlist[portno], ! mess[0], mess[1], mess[2], mess[3]); sysex = 0; nbytes = 0; ! } ! else if (byte >= 0x80) ! { sysex = 0; ! if (byte == 0xf4 || byte == 0xf5 || byte == 0xf6) ! { writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0); nbytes = 0; ! } ! else ! { mess[0] = byte; nbytes = 1; } ! } ! else if (sysex) ! { mess[nbytes] = byte; nbytes++; ! if (nbytes == 4) ! { writemidi4(mac_midioutdevlist[portno], mess[0], mess[1], mess[2], mess[3]); nbytes = 0; } ! } ! else if (nbytes) ! { int status = mess[0]; ! if (status < 0xf0) ! status &= 0xf0; ! /* 2 byte messages: */ ! if (status == 0xc0 || status == 0xd0 || ! status == 0xf1 || status == 0xf3) ! { ! writemidi4(mac_midioutdevlist[portno], ! mess[0], byte, 0, 0); nbytes = (status < 0xf0 ? 1 : 0); ! } ! else ! { ! if (nbytes == 1) ! { mess[1] = byte; nbytes = 2; ! } ! else ! { writemidi4(mac_midioutdevlist[portno], mess[0], mess[1], byte, 0); --- 96,151 ---- }
! static void writemidi4(PortMidiStream* stream, int a, int b, int c, int d) { PmEvent buffer; buffer.timestamp = 0; ! buffer.message = ((a & 0xff) | ((b & 0xff) << 8) | ((c & 0xff) << 16) | ((d & 0xff) << 24)); Pm_Write(stream, &buffer, 1); }
! void sys_putmidibyte(int portno, int byte) { ! /* try to parse the bytes into MIDI messages so they can fit into PortMidi buffers. */ static int mess[4]; static int nbytes = 0, sysex = 0, i; if (byte >= 0xf8) /* MIDI real time */ writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0); ! else if (byte == 0xf0) { mess[0] = 0xf7; nbytes = 1; sysex = 1; ! } else if (byte == 0xf7) { mess[nbytes] = byte; ! for (i = nbytes+1; i < 4; i++) mess[i] = 0; ! writemidi4(mac_midioutdevlist[portno], mess[0], mess[1], mess[2], mess[3]); sysex = 0; nbytes = 0; ! } else if (byte >= 0x80) { sysex = 0; ! if (byte == 0xf4 || byte == 0xf5 || byte == 0xf6) { writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0); nbytes = 0; ! } else { mess[0] = byte; nbytes = 1; } ! } else if (sysex) { mess[nbytes] = byte; nbytes++; ! if (nbytes == 4) { writemidi4(mac_midioutdevlist[portno], mess[0], mess[1], mess[2], mess[3]); nbytes = 0; } ! } else if (nbytes) { int status = mess[0]; ! if (status < 0xf0) status &= 0xf0; ! /* 2 byte messages: */ ! if (status == 0xc0 || status == 0xd0 || status == 0xf1 || status == 0xf3) { ! writemidi4(mac_midioutdevlist[portno], mess[0], byte, 0, 0); nbytes = (status < 0xf0 ? 1 : 0); ! } else { ! if (nbytes == 1) { mess[1] = byte; nbytes = 2; ! } else { writemidi4(mac_midioutdevlist[portno], mess[0], mess[1], byte, 0); *************** *** 217,273 **** }
! void sys_poll_midi(void) ! { ! int i, j, nmess; PmEvent buffer; ! for (i = 0; i < mac_nmidiindev; i++) ! { int nmess = Pm_Read(mac_midiindevlist[i], &buffer, 1); ! if (nmess > 0) ! { ! PmMessage msg = buffer.message; int status = Pm_MessageStatus(msg); ! if(status == 0xf0 || !(status&0x80)) { ! /* sysex header or data */ ! for(j = 0; j < 4; ++j,msg >>= 8) { ! int data = msg&0xff; ! sys_midibytein(i, data); ! if(data == 0xf7) break; /* sysex end */ ! } ! } ! else { ! /* non-sysex */ ! sys_midibytein(i, status); ! ! switch(status>>4) ! { ! case 0x8: /* note off */ ! case 0x9: /* note on */ ! case 0xa: /* poly pressure */ ! case 0xb: /* control change */ ! case 0xe: /* pitch bend */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! sys_midibytein(i, Pm_MessageData2(msg)); ! break; ! case 0xc: /* program change */ ! case 0xd: /* channel pressure */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! break; ! case 0xf: /* system common/realtime messages */ ! switch(status) ! { ! case 0xf1: /* time code */ ! case 0xf3: /* song select */ ! case 0xf6: /* tune request */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! break; ! case 0xf2: /* song position pointer */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! sys_midibytein(i, Pm_MessageData2(msg)); ! break; ! } ! break; ! } } } } --- 156,205 ---- }
! void sys_poll_midi(void) { ! int i, j; PmEvent buffer; ! for (i = 0; i < mac_nmidiindev; i++) { int nmess = Pm_Read(mac_midiindevlist[i], &buffer, 1); ! if (nmess > 0) { ! PmMessage msg = buffer.message; int status = Pm_MessageStatus(msg); ! if(status == 0xf0 || !(status&0x80)) { ! /* sysex header or data */ ! for(j = 0; j < 4; ++j,msg >>= 8) { ! int data = msg&0xff; ! sys_midibytein(i, data); ! if(data == 0xf7) break; /* sysex end */ ! } ! } else { ! /* non-sysex */ ! sys_midibytein(i, status); ! switch(status>>4) { ! case 0x8: /* note off */ ! case 0x9: /* note on */ ! case 0xa: /* poly pressure */ ! case 0xb: /* control change */ ! case 0xe: /* pitch bend */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! sys_midibytein(i, Pm_MessageData2(msg)); ! break; ! case 0xc: /* program change */ ! case 0xd: /* channel pressure */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! break; ! case 0xf: /* system common/realtime messages */ ! switch(status) { ! case 0xf1: /* time code */ ! case 0xf3: /* song select */ ! case 0xf6: /* tune request */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! break; ! case 0xf2: /* song position pointer */ ! sys_midibytein(i, Pm_MessageData1(msg)); ! sys_midibytein(i, Pm_MessageData2(msg)); ! break; } + break; + } + } } } *************** *** 275,283 ****
#if 0 ! void sys_listmididevs(void) /* lifted from pa_devs.c in portaudio */ ! { int i,j; ! for (i = 0; i < Pm_CountDevices(); i++) ! { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); printf("%d: %s, %s", i, info->interf, info->name); --- 207,214 ----
#if 0 ! /* lifted from pa_devs.c in portaudio */ ! void sys_listmididevs(void) { int i,j; ! for (i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); printf("%d: %s, %s", i, info->interf, info->name); *************** *** 289,308 **** #endif
! void midi_getdevs(char *indevlist, int *nindevs, ! char *outdevlist, int *noutdevs, int maxndev, int devdescsize) ! { int i, nindev = 0, noutdev = 0; ! for (i = 0; i < Pm_CountDevices(); i++) ! { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); /* post("%d: %s, %s (%d,%d)", i, info->interf, info->name, info->input, info->output); */ ! if (info->input && nindev < maxndev) ! { strcpy(indevlist + nindev * devdescsize, info->name); nindev++; } ! if (info->output && noutdev < maxndev) ! { strcpy(outdevlist + noutdev * devdescsize, info->name); noutdev++; --- 220,234 ---- #endif
! void midi_getdevs(char *indevlist, int *nindevs, char *outdevlist, int *noutdevs, int maxndev, int devdescsize) { int i, nindev = 0, noutdev = 0; ! for (i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); /* post("%d: %s, %s (%d,%d)", i, info->interf, info->name, info->input, info->output); */ ! if (info->input && nindev < maxndev) { strcpy(indevlist + nindev * devdescsize, info->name); nindev++; } ! if (info->output && noutdev < maxndev) { strcpy(outdevlist + noutdev * devdescsize, info->name); noutdev++;