Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Created September 1, 2009 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atsushieno/179368 to your computer and use it in GitHub Desktop.
Save atsushieno/179368 to your computer and use it in GitHub Desktop.
#include <portmidi.h>
#include <stdio.h>
#include <unistd.h>
PmDeviceInfo *devinfo;
PortMidiStream *outs;
PortMidiStream *ins;
void main (int argc, char **argv)
{
int i, l, count, buflen = 100000;
int ret;
char *sysex = "\xF0\x41\x10\x42\x11\x0C\x00\x01\x00\x00\x00\x73\xF7";
PmEvent buffer [buflen];
FILE *fp;
//for (i = 0; i < buflen; i++)
// buffer [i] = ;
count = Pm_CountDevices ();
for (i = 0; i < count; i++) {
devinfo = Pm_GetDeviceInfo (i);
printf ("%d %s %s\n", i, devinfo->interf, devinfo->name);
}
ret = Pm_OpenOutput (&outs, 2, NULL, 1000, NULL, NULL, 0);
if (ret != pmNoError) {
printf ("failed to open output: %s\n", Pm_GetErrorText (ret));
return;
}
ret = Pm_OpenInput (&ins, 0, NULL, 100000, NULL, NULL);
if (ret != pmNoError) {
printf ("failed to open input: %s\n", Pm_GetErrorText (ret));
return;
}
ret = Pm_WriteSysEx (outs, 0, sysex);
if (ret != pmNoError) {
printf ("failed to write sysex: %s\n", Pm_GetErrorText (ret));
return;
}
fp = fopen ("sc8820.bin", "w");
while (1) {
sleep (10);
if (Pm_Poll (ins) == 0)
break;
l = Pm_Read (ins, buffer, buflen);
printf ("read %d bytes\n", l);
if (ret < 0) {
printf ("failed to write sysex: %s\n", Pm_GetErrorText (ret));
return;
}
for (i = 0; i < l; i++)
printf ("%8x ", buffer [i]);
fwrite (buffer, 4, l, fp);
}
fclose (fp);
Pm_Close (ins);
Pm_Close (outs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment