void mainloopalgorithms(void) { performance.xcheck(); while (midiin.getCount() > 0) { midimessage = midiin.extract(); processMidiCommand(midimessage); } }
void start(void) { comparestate = 1; sentout.reset(); // initialize the MIDI output storage receivedin.reset(); // initialize the MIDI input storage midiinput.setPort(synth.getInputPort()); midiinput.open(); }
int main(void) { MidiInput midiin; MidiOutput midiout; midiout.setPort(0); midiout.open(); midiin.setPort(0); midiin.open(); MidiMessage message; int sysexloc; unsigned char *sysexdata = NULL; int sysexsize = 0; int i; int running = 1; cout << "sysexio -- display and echo SYSEX messages from MIDI input" << endl; cout << "Press Middle C to quit." << endl; while (running) { if (midiin.getCount() > 0) { message = midiin.extract(); if (message.p0() == 0xf0) { sysexloc = message.p1(); sysexdata = midiin.getSysex(sysexloc); sysexsize = midiin.getSysexSize(sysexloc); // print out the sysex data to the screen: for (i=0; i<sysexsize; i++) { cout << hex << (int)sysexdata[i] << " "; if ((i + 1) % 30 == 0) { cout << endl; } } cout << endl; // Now echo the messages to MIDI output (as a demo // for how to send Sysex outputs) midiout.rawsend(sysexdata, sysexsize); // As a courtesy, mark the midiin sysex buffer free // but this is not necessay (it will be erased when // more space is needed for storing a sysex. midiin.clearSysex(sysexloc); } else if ((message.p0() & 0xf0) == 0x90) { // Exit the program when a middle C note is pressed. if (message.p1() == 60 && message.p2() > 0) { running = 0; } } } } return 0; }
int main(int argc, char** argv) { Options options(argc, argv); checkOptions(options); keyboardTimer.setPeriod(10); int command = 0; MidiInput midiin; midiin.setPort(inport); midiin.open(); MidiEvent midimessage; performance.read(options.getArg(1).data()); performance.setPort(outport); performance.setMaxAmp(maxamp); performance.open(); performance.setTempoMethod(tempoMethod); performance.play(); while (command != 'Q') { while (midiin.getCount() > 0) { midiin.extract(midimessage); processMidiCommand(midimessage); } performance.xcheck(); eventIdler.sleep(); if (keyboardTimer.expired()) { keyboardTimer.reset(); command = checkKeyboard(); if (command == 'Q') { break; } else { keyboardCommand(command); } } } return 0; }
void mainloopalgorithms(void) { if (comparestate && notetimer.expired()) { if (notetimer.expired() > 2) { notetimer.reset(); } else { notetimer.update(); } notestate = !notestate; if (notestate == 1 || notestate == -1) { synth.play(0, note, 64); data = 0x90; sentout.insert(data); data = note; sentout.insert(data); data = 64; sentout.insert(data); } else { synth.play(0, note, 0); data = 0x90; sentout.insert(data); data = note; sentout.insert(data); data = 0; sentout.insert(data); note += step * direction; if (note > highestnote) { note = lowestnote; } if (note < lowestnote) { note = highestnote; } } } if (midiinput.getCount() > 0) { message = midiinput.extract(); receivedin.insert(message.p0()); receivedin.insert(message.p1()); receivedin.insert(message.p2()); // check that the messages are identical if (receivedin.getCount() < 3) { cout << "Error: not enough received data" << endl; } else { checkin[0] = receivedin.extract(); checkin[1] = receivedin.extract(); checkin[2] = receivedin.extract(); } if (sentout.getCount() < 3) { cout << "Error: not enough sent data" << endl; } else { checkout[0] = sentout.extract(); checkout[1] = sentout.extract(); checkout[2] = sentout.extract(); } if ((checkout[0] != checkin[0]) || (checkout[1] != checkin[1]) || (checkout[2] != checkin[2])) { synth.rawsend(0xaa, 0x7f, 0x00); cout << "Error " << "output was = (" << hex << (int)checkout[0] << ") " << dec << (int)checkout[1] << " " << dec << (int)checkout[2] << "\tbut input is = (" << hex << (int)checkin[0] << ") " << dec << (int)checkin[1] << " " << dec << (int)checkin[2] << " " << endl; // assume that a note message was missed. if (sentout.getCount() < 3) { cout << "Error: not enough sent data during error" << endl; } else { checkout[0] = sentout.extract(); checkout[1] = sentout.extract(); checkout[2] = sentout.extract(); } stop(); cout << "Press space to restart testing, " "or press 'S' to silence synth" << endl; } } }