int main() { // Setup wiringPi if (wiringPiSetup() == -1) { exit(1); } // Register signal handler signal(SIGINT, signalHandler); // Setup all the pins to use OUTPUT mode setPinModes(OUTPUT); allOff(); // Open a midi port, connect to through port also midi_open(); // Process events forever while (true) { midi_process(midi_read()); } return -1; }
int main() { //Start as a daemon if( daemon(0,0) != 0) { exit(1); } //Setup wiringPi if( wiringPiSetup() == -1) { exit(1); } //Setup all the pins to use OUTPUT mode int i=0; for(i=0; i< MY_NUM_PINS; i++) { pinMode(i, OUTPUT); } clearPinsState(); resetPlayChannels(); //Open a midi port, connect to thru port also midi_open(); //Process events forever while (1) { midi_process(midi_read()); } return -1; }
int main(void) { MidiMessage* msg; // Halt the watchdog timer - According to the datasheet the watchdog timer // starts automatically after powerup. It must be configured or halted at // the beginning of code execution to avoid a system reset. Furthermore, // the watchdog timer register (WDTCTL) is password protected, and requires // the upper byte during write operations to be 0x5A, which is the value // associated with WDTPW. WDTCTL = WDTPW + WDTHOLD; // Initialize MIDI using USCI for input only midi_init(MIDI_MODE_USCI, MIDI_DIR_IN); // Listen to channel 0-15 (first nibble) with a mask including all // channels (second nibble) midi_set_channel_mask(0xFF); while(1) { // Poll for a message, if true we go ahead and read the // prepared MIDI message if (midi_poll()) { msg = (MidiMessage*)midi_read(); } } }
int main(int argc, char *argv[]) { struct midi m; struct pollfd pt[8]; if (argc != 2) { fprintf(stderr, "usage: %s <device>\n", argv[0]); return -1; } if (midi_open(&m, argv[1]) == -1) return -1; for (;;) { ssize_t z; char buf[32]; z = midi_pollfds(&m, pt, ARRAY_SIZE(pt)); if (z == -1) return -1; fputs("poll...\n", stderr); if (poll(pt, z, -1) == -1) { perror("poll"); return -1; } fputs("... return\n", stderr); for (;;) { size_t n; ssize_t z; z = midi_read(&m, buf, sizeof buf); if (z == -1) return -1; if (z == 0) break; for (n = 0; n < z; n++) printf(" %02hhx", buf[n]); z = midi_write(&m, buf, z); printf(" =%d", z); if (z == -1) return -1; } printf("\n"); fflush(stdout); } midi_close(&m); }
int main() { struct midi_buffer buf; midi_buffer_init(&buf); buf.callback = handle_msg; // Set a callback buf.channel_mask = 0xff; // Listen to channels 0 to 7 // Read from stdin while(midi_read(&buf, 0) == 0) { } return 0; }
/* * Read in a midi file from the specified file name. * * Arguments: * name - File name to read */ struct rootElement * midi_read_file(char *name) { FILE *fp; struct rootElement *root; fp = fopen(name, "rb"); if (fp == NULL) except(ioError, "Could not open file %s", name); root = midi_read(fp); fclose(fp); return root; }
/* * Load/process a MIDI file and get ready to play it via Jack's MIDI API. */ jpmidi_root_t* jpmidi_loadfile(char *filename, jack_nframes_t sample_rate) { struct rootElement *proot; struct sequenceState *seq; struct element *el; if (strcmp(filename, "-") == 0) proot = midi_read(stdin); else proot = midi_read_file(filename); if (!proot) return NULL; /* FIXME - free this somewhere */ jpmidi_root_t* root = jpmidi_root_new( filename, proot, sample_rate); /* Process all the elements in the file. */ seq = md_sequence_init(proot); while ((el = md_sequence_next(seq)) != NULL) { jpmidi_process_element(root, el); } // Add an entry point every second to reduce seek time jack_nframes_t epframe; for (epframe = 0; epframe < root->last_frame; epframe += root->sample_rate) { jpmidi_time_t* time = (jpmidi_time_t*)g_tree_lookup( root->data, &epframe); if (time == NULL) { time = jpmidi_time_new( 0, epframe); g_tree_insert( root->data, &time->frame, time); } } // Create the linked list of time structs ordered by time. root->head = NULL; root->tail = NULL; g_tree_foreach( root->data, jpmidi_root_data_traverse, root); jpmidi_call_loadfile_listeners( root); return root; }
int main () { if (gpioSetup() != OK) { dbgPrint(DBG_INFO, "gpioSetup failed. Exiting\n"); return 1; } seq_handle = open_seq(); connect2MidiThroughPort(seq_handle); init_cmd_defaults(); while (1) { midi_read(); } snd_seq_close (seq_handle); gpioCleanup(); return (0); }