void sillyKeyboard(int key, int chan /* = 0 */) { static int octave = 4; static int newkey = 0; static Voice voice; static MidiMessage message; // check to see if adjusting the octave: if (isdigit(key)) { octave = key - '0'; return; } switch (key) { case 'z': newkey = 12 * octave + 0; break; // C case 's': newkey = 12 * octave + 1; break; // C# case 'x': newkey = 12 * octave + 2; break; // D case 'd': newkey = 12 * octave + 3; break; // D# case 'c': newkey = 12 * octave + 4; break; // E case 'v': newkey = 12 * octave + 5; break; // F case 'g': newkey = 12 * octave + 6; break; // F# case 'b': newkey = 12 * octave + 7; break; // G case 'h': newkey = 12 * octave + 8; break; // G# case 'n': newkey = 12 * octave + 9; break; // A case 'j': newkey = 12 * octave + 10; break; // A# case 'm': newkey = 12 * octave + 11; break; // B case ',': newkey = 12 * octave + 12; break; // C case 'l': newkey = 12 * octave + 12; break; // C# case '.': newkey = 12 * octave + 12; break; // D case '\'': newkey = 12 * octave + 12; break; // D# case '/': newkey = 12 * octave + 12; break; // E default: return; // don't do anything if not a key } newkey = limit(newkey, 0, 127); // put note-off message in synth's input buffer: message.time = t_time; message.p0() = 0x90 | voice.getChan(); message.p1() = voice.getKey(); message.p2() = 0; synth.insert(message); // turn off the last note: voice.off(); // set parameters for next note-on: voice.setChan(chan & 0x0f); // limit channel to range from 0 to 15 voice.setVel(rand() % 127 +1); // random attack in range from 1 to 127 voice.setKey(newkey); // use the newly selected key number // play the MIDI note: voice.play(); // insert the played note into synth's input MIDI buffer: message.command() = 0x90 | voice.getChan(); message.p1() = voice.getKey(); message.p2() = voice.getVel(); synth.insert(message); }
void RadioBaton::interpretCommand(MidiMessage aMessage) { ushort value; // for the buff value receive commands if (aMessage.command() == BAT_MIDI_COMMAND) { switch (aMessage.p1()) { case BAT_STICK1_RESPONSE_X: // stick 1 responding to poll; x s1ps(aMessage.time); s1pd(DATA_X, aMessage.p2()); break; case BAT_STICK1_RESPONSE_Y: // stick 1 responding to poll; y s1pd(DATA_Y, aMessage.p2()); break; case BAT_STICK1_RESPONSE_Z: // stick 1 responding to poll; z s1pd(DATA_Z, aMessage.p2()); break; case BAT_STICK2_RESPONSE_X: // stick 2 responding to poll; x s2ps(aMessage.time); s2pd(DATA_X, aMessage.p2()); break; case BAT_STICK2_RESPONSE_Y: // stick 2 responding to poll; y s2pd(DATA_Y, aMessage.p2()); break; case BAT_STICK2_RESPONSE_Z: // stick 2 responding to poll; z s2pd(DATA_Z, aMessage.p2()); break; case BAT_POT1_RESPONSE: // pot 1 responding to poll d1p = aMessage.p2(); // update global state variable dial1position(); recordState(aMessage.time, DIAL1RECORD, d1p); d1pb.insert(aMessage.p2()); break; case BAT_POT2_RESPONSE: // pot 2 responding to poll d2p = aMessage.p2(); // update global state variable dial2position(); recordState(aMessage.time, DIAL2RECORD, d2p); d2pb.insert(aMessage.p2()); break; case BAT_POT3_RESPONSE: // pot 3 responding to poll d3p = aMessage.p2(); // update global state variable dial3position(); recordState(aMessage.time, DIAL3RECORD, d3p); d3pb.insert(aMessage.p2()); break; case BAT_POT4_RESPONSE: // pot 4 responding to poll d4p = aMessage.p2(); // update global state variable dial4position(); recordState(aMessage.time, DIAL4RECORD, d4p); d4pb.insert(aMessage.p2()); break; case BAT_STICK1_TRIGGER: // stick 1 got triggered s1ts(aMessage.time); s1td(DATA_W, aMessage.p2()); break; case BAT_STICK1_TRIG_X: // stick 1 got triggered s1td(DATA_X, aMessage.p2()); break; case BAT_STICK1_TRIG_Y: // stick 1 got triggered s1td(DATA_Y, aMessage.p2()); break; case BAT_STICK2_TRIGGER: // stick 2 got triggered s2ts(aMessage.time); s2td(DATA_W, aMessage.p2()); break; case BAT_STICK2_TRIG_X: // stick 2 got triggered s2td(DATA_X, aMessage.p2()); break; case BAT_STICK2_TRIG_Y: // stick 2 got triggered s2td(DATA_Y, aMessage.p2()); break; case BAT_BUTTON_FOOT_TRIGGER: // button or pedal was triggered switch (aMessage.p2()) { case BAT_B14p_TRIGGER: // B14+ button pressed b14pt = aMessage.time; b14ptb.insert(b14pt); recordState(aMessage.time, BUTTON1RECORD); b14plustrig(); break; case BAT_B15p_TRIGGER: // B15+ button pressed b15pt = aMessage.time; recordState(aMessage.time, BUTTON2RECORD); b15plustrig(); b15ptb.insert(b15pt); break; case BAT_B14m_DOWN_TRIGGER: // B14- pedal was depressed b14mdt = aMessage.time; b14mdtb.insert(b14mdt); recordState(b14mdt, FOOTPEDAL1RECORD, 1); b14minusdowntrig(); break; case BAT_B14m_UP_TRIGGER: // B14- pedal was released b14mut = aMessage.time; b14mutb.insert(b14mut); recordState(b14mut, FOOTPEDAL1RECORD, 0); b14minusuptrig(); break; case BAT_B15m_DOWN_TRIGGER: // B15- pedal was depressed b15mdt = aMessage.time; b15mdtb.insert(b15mdt); recordState(b15mut, FOOTPEDAL2RECORD, 1); b15minusdowntrig(); break; case BAT_B15m_UP_TRIGGER: // B15- pedal was released b15mut = aMessage.time; b15mutb.insert(b15mut); recordState(b15mut, FOOTPEDAL2RECORD, 0); b15minusuptrig(); break; } break; case BAT_SEND: // ignore this command break; default: if (errorQ) { cerr << "Baton command not recognized: 0x" << hex << (int)aMessage.command() << dec << ", param1 = " << (int)aMessage.p1() << ", param2 = " << (int)aMessage.p2() << endl; } } // end of switch (aMessage.command()) } // end of if a baton command (0xa0) else if (aMessage.command() == 0xa1) { // do nothing: old calibration message } else if (aMessage.command() == 0xa2) { // do nothing: old calibration message } else if (aMessage.command() == 0xa3) { // do nothing: old calibration message } else if (aMessage.command() == 0xa4) { // do nothing: old calibration message } // take care of buf data else if (aMessage.command() == 0xa5) { // if p1 is not in the range from 0 to 15 then ignore the error: if (aMessage.p1() > 15) return; completeBufQ[aMessage.p1()] = 0; value = (ushort)(aMessage.p2() & 0x000f); buf[aMessage.p1()] &= 0x0fff; buf[aMessage.p1()] |= (value << 12); } else if (aMessage.command() == 0xa6) { // if p1 is not in the range from 0 to 15 then ignore the error: if (aMessage.p1() > 15) return; value = (ushort)(aMessage.p2() & 0x000f); buf[aMessage.p1()] &= 0xf0ff; buf[aMessage.p1()] |= (value << 8); } else if (aMessage.command() == 0xa7) { // if p1 is not in the range from 0 to 15 then ignore the error: if (aMessage.p1() > 15) return; value = (ushort)(aMessage.p2() & 0x000f); buf[aMessage.p1()] &= 0xff0f; buf[aMessage.p1()] |= (value << 4); } else if (aMessage.command() == 0xa8) { // if p1 is not in the range from 0 to 15 then ignore the error: if (aMessage.p1() > 15) return; value = (ushort)(aMessage.p2() & 0x000f); buf[aMessage.p1()] &= 0xfff0; buf[aMessage.p1()] |= value; completeBufQ[aMessage.p1()] = 1; // record buffer element to file if recording // NOTE: have to figure out what to put in the time slots below; 0 for now. switch (aMessage.p1()) { case 0: recordState(timer.getTime(), ANTENNA0RECORD, buf[0]); break; case 1: recordState(timer.getTime(), ANTENNA1RECORD, buf[1]); break; case 2: recordState(timer.getTime(), ANTENNA2RECORD, buf[2]); break; case 3: recordState(timer.getTime(), ANTENNA3RECORD, buf[3]); break; case 4: recordState(timer.getTime(), ANTENNA4RECORD, buf[4]); break; case 5: recordState(timer.getTime(), POT4RECORD, buf[5]); break; case 6: recordState(timer.getTime(), ANTENNA5RECORD, buf[6]); break; case 7: recordState(timer.getTime(), ANTENNA6RECORD, buf[7]); break; case 8: recordState(timer.getTime(), ANTENNA7RECORD, buf[8]); break; case 9: recordState(timer.getTime(), ANTENNA8RECORD, buf[9]); break; case 10: recordState(timer.getTime(), ANTENNA9RECORD, buf[10]); break; case 11: recordState(timer.getTime(), POT1RECORD, buf[11]); break; case 12: recordState(timer.getTime(), POT2RECORD, buf[12]); break; case 13: recordState(timer.getTime(), POT3RECORD, buf[13]); break; case 14: recordState(timer.getTime(), B14RECORD, buf[14]); break; case 15: recordState(timer.getTime(), B15RECORD, buf[15]); break; } } else if (aMessage.command() == 0xaa) { // miditest currentmidi = aMessage.p2(); if (currentmidi != 0) { if (currentmidi != lastmidi + 1) { midierrors++; } lastmidi = currentmidi; miditests++; } } else if (aMessage.command() == 0xab) { // miditest currentmidi = aMessage.p2(); if (currentmidi != 0) { if (currentmidi != lastmidi+1) { midierrors++; } lastmidi = currentmidi; miditests++; } } // All other MIDI commands are ignored. Maybe they are // for/from a synthesizer or something like that. }