void SoftSynthAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { MidiBuffer processedMidi; int time; MidiMessage m; for (MidiBuffer::Iterator i(midiMessages); i.getNextEvent(m, time);) { if (m.isNoteOn()) { m = MidiMessage::noteOn(m.getChannel(), m.getNoteNumber(), m.getVelocity()); synth.keyPressed(m.getNoteNumber(), m.getVelocity()); } else if (m.isNoteOff()) { m = MidiMessage::noteOff(m.getChannel(), m.getNoteNumber(), m.getVelocity()); synth.keyReleased(m.getNoteNumber()); } processedMidi.addEvent(m, time); } auto synthBuffer = synth.getNextBuffer(buffer.getNumSamples()); float *leftData = buffer.getWritePointer(0); float *rightData = buffer.getWritePointer(1); for (int i = 0; i < buffer.getNumSamples(); ++i) { leftData[i] = synthBuffer[i]; rightData[i] = synthBuffer[i]; } midiMessages.swapWith(processedMidi); }
static void RT_MIDI_send_msg_to_patch(struct Patch *patch, MidiMessage message, int64_t seq_time){ if (message.isNoteOn()) RT_PATCH_play_note(patch, message.getNoteNumber(), -1, message.getVelocity() / 127.0f, 0.0f, seq_time); else if (message.isNoteOff()) RT_PATCH_stop_note(patch, message.getNoteNumber(), -1, seq_time); else if (message.isAftertouch()) RT_PATCH_change_velocity(patch, message.getNoteNumber(), -1, message.getChannelPressureValue() / 127.0f, seq_time); else { const uint8_t *raw_data = message.getRawData(); int len = message.getRawDataSize(); R_ASSERT_RETURN_IF_FALSE(len>=1 && len<=3); uint32_t msg; if (len==3) msg = MIDI_msg_pack3(raw_data[0],raw_data[1],raw_data[2]); else if (len==2) msg = MIDI_msg_pack2(raw_data[0],raw_data[1]); else if (len==1) msg = MIDI_msg_pack1(raw_data[0]); else return; RT_PATCH_send_raw_midi_message(patch, msg, seq_time); } }
const String getMidiValue(const MidiMessage &m) { if (m.isAftertouch()) { return (String::formatted (" Val:[%4d]", m.getAfterTouchValue())); } if (m.isController()) { return (String::formatted (" Val:[%4d]", m.getControllerValue())); } if (m.isNoteOnOrOff()) { return (String::formatted (" Val:[%4d]", m.getVelocity())); } if (m.isPitchWheel()) { return (String::formatted (" Val:[%4d]", m.getPitchWheelValue())); } if (m.isChannelPressure()) { return (String::formatted (" Val:[%4d]", m.getChannelPressureValue())); } return (" Val:[----]"); }
static PyObject * PyMidiMessage_str(PyObject *self) { MidiMessage *m = ((PyMidiMessage*)self)->m; static char s[256]; if(m->isNoteOn()) { sprintf(s, "<NOTE ON, note: %d (%s), velocity: %d, channel: %d>", m->getNoteNumber(), m->getMidiNoteName(m->getNoteNumber(), true, true, 3), m->getVelocity(), m->getChannel()); } else if(m->isNoteOff()) { sprintf(s, "<NOTE OFF, note: %d (%s), channel: %d>", m->getNoteNumber(), m->getMidiNoteName(m->getNoteNumber(), true, true, 3), m->getChannel()); } else if(m->isProgramChange()) { sprintf(s, "<PROGRAM CHANGE: program: %d, channel: %d>", m->getProgramChangeNumber(), m->getChannel()); } else if(m->isPitchWheel()) { sprintf(s, "<PITCH WHEEL: value: %d, channel: %d>", m->getPitchWheelValue(), m->getChannel()); } else if(m->isAftertouch()) { sprintf(s, "<AFTERTOUCH: note: %d (%s) value: %d, channel: %d>", m->getNoteNumber(), m->getMidiNoteName(m->getNoteNumber(), true, true, 3), m->getAfterTouchValue(), m->getChannel()); } else if(m->isChannelPressure()) { sprintf(s, "<CHANNEL PRESSURE: pressure: %d, channel: %d>", m->getChannelPressureValue(), m->getChannel()); } else if(m->isController()) { const char *name = m->getControllerName(m->getControllerNumber()); if(strlen(name) > 0) { sprintf(s, "<CONTROLLER: %d (\"%s\"), value: %d, channel: %d>", m->getControllerNumber(), m->getControllerName(m->getControllerNumber()), m->getControllerValue(), m->getChannel()); } else { sprintf(s, "<CONTROLLER: %d, value: %d, channel: %d>", m->getControllerNumber(), m->getControllerValue(), m->getChannel()); } } else { sprintf(s, "<MidiMessage (misc type)>"); } return PK_STRING(s); }
void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample_position) { if (midi_message.isProgramChange()) { current_patch_ = midi_message.getProgramChangeNumber(); File patch = LoadSave::loadPatch(current_bank_, current_folder_, current_patch_, synth_, *gui_state_); PatchLoadedCallback* callback = new PatchLoadedCallback(listener_, patch); callback->post(); return; } if (midi_message.isNoteOn()) { engine_->noteOn(midi_message.getNoteNumber(), midi_message.getVelocity() / (mopo::MIDI_SIZE - 1.0), 0, midi_message.getChannel() - 1); } else if (midi_message.isNoteOff()) engine_->noteOff(midi_message.getNoteNumber()); else if (midi_message.isAllNotesOff()) engine_->allNotesOff(); else if (midi_message.isSustainPedalOn()) engine_->sustainOn(); else if (midi_message.isSustainPedalOff()) engine_->sustainOff(); else if (midi_message.isAftertouch()) { mopo::mopo_float note = midi_message.getNoteNumber(); mopo::mopo_float value = (1.0 * midi_message.getAfterTouchValue()) / mopo::MIDI_SIZE; engine_->setAftertouch(note, value); } else if (midi_message.isPitchWheel()) { double percent = (1.0 * midi_message.getPitchWheelValue()) / PITCH_WHEEL_RESOLUTION; double value = 2 * percent - 1.0; engine_->setPitchWheel(value, midi_message.getChannel()); } else if (midi_message.isController()) { int controller_number = midi_message.getControllerNumber(); if (controller_number == MOD_WHEEL_CONTROL_NUMBER) { double percent = (1.0 * midi_message.getControllerValue()) / MOD_WHEEL_RESOLUTION; engine_->setModWheel(percent, midi_message.getChannel()); } else if (controller_number == BANK_SELECT_NUMBER) current_bank_ = midi_message.getControllerValue(); else if (controller_number == FOLDER_SELECT_NUMBER) current_folder_ = midi_message.getControllerValue(); midiInput(midi_message.getControllerNumber(), midi_message.getControllerValue()); } }
void VoicerUGenInternal::handleIncomingMidiMessage (MidiInput* /*source*/, const MidiMessage& message) throw() { if(message.isForChannel(midiChannel_) == false) return; if(message.isNoteOnOrOff()) { const ScopedLock sl(lock); sendMidiNote(message.getChannel(), message.getNoteNumber(), message.getVelocity()); } else if(message.isController()) { if((message.getControllerNumber() == 123) && (message.getControllerValue() == 0)) { const ScopedLock sl(lock); initEvents(); } getController(message.getControllerNumber()) = (message.getControllerValue() * (1.f / 127.f)); } else if(message.isPitchWheel()) { getPitchWheel() = (jlimit(-8191, 8191, message.getPitchWheelValue() - 8192) * (1.f / 8191.f)); } else if(message.isChannelPressure()) { getChannelPressure() = (message.getChannelPressureValue() * (1.f / 127.f)); } else if(message.isAftertouch()) { getKeyPressure(message.getNoteNumber()) = (message.getAfterTouchValue() * (1.f / 127.f)); } else if(message.isProgramChange()) { getProgram() = (message.getProgramChangeNumber()); } else if(message.isAllNotesOff()) { const ScopedLock sl(lock); initEvents(); } }
void Tunefish4AudioProcessor::processEvents(MidiBuffer &midiMessages, eU32 messageOffset, eU32 frameSize) { MidiBuffer::Iterator it(midiMessages); MidiMessage midiMessage; int samplePosition; it.setNextSamplePosition(messageOffset); while (it.getNextEvent(midiMessage, samplePosition)) { if (samplePosition >= messageOffset + frameSize) break; if (midiMessage.isNoteOn()) { eU8 velocity = midiMessage.getVelocity(); eU8 note = midiMessage.getNoteNumber(); eTfInstrumentNoteOn(*tf, note, velocity); } else if (midiMessage.isNoteOff()) { eU8 note = midiMessage.getNoteNumber(); eTfInstrumentNoteOff(*tf, note); } else if (midiMessage.isAllNotesOff()) { eTfInstrumentAllNotesOff(*tf); } else if (midiMessage.isPitchWheel()) { eS32 bend_lsb = midiMessage.getRawData()[1] & 0x7f; eS32 bend_msb = midiMessage.getRawData()[2] & 0x7f; eTfInstrumentPitchBend(*tf, ((eF32(bend_msb) / 127.0f) - 0.5f) * 2.0f, ((eF32(bend_lsb) / 127.0f) - 0.5f) * 2.0f); } } }
//============================================================================== void MidiMonitorEditor::timerCallback () { MidiBuffer tmpBuffer; int hours, minutes, seconds, frames; MidiMessage::SmpteTimecodeType timeCode; MidiMessageCollector* collector = owner->getMessageCollector (); collector->removeNextBlockOfMessages (tmpBuffer, 1024); if (! tmpBuffer.isEmpty()) { String midiLine; int samplePos = 0; MidiMessage msg (0xf4, 0.0); MidiBuffer::Iterator eventIterator (tmpBuffer); while (eventIterator.getNextEvent (msg, samplePos)) { midiLine.printf (T("[CH: %d] "), msg.getChannel()); if (msg.isNoteOnOrOff ()) { midiLine += MidiMessage::getMidiNoteName (msg.getNoteNumber(), true, true, 0); midiLine += " "; midiLine += String ((int) msg.getVelocity ()); if (msg.isNoteOn()) { midiLine += " ON"; } else { midiLine += " OFF"; } } else if (msg.isAllNotesOff()) { midiLine += "ALL NOTES OFF"; } else if (msg.isAllSoundOff()) { midiLine += "ALL SOUND OFF"; } else if (msg.isPitchWheel()) { midiLine += "PITCHWEEL: "; midiLine += String (msg.getPitchWheelValue()); } else if (msg.isAftertouch()) { midiLine += "AFTERTOUCH: "; midiLine += String (msg.getAfterTouchValue()); } else if (msg.isChannelPressure()) { midiLine += "CHANNELPRESSURE: "; midiLine += String (msg.getChannelPressureValue()); } else if (msg.isSysEx()) { midiLine += "SYSEX: "; midiLine += String (msg.getSysExDataSize()); midiLine += " bytes"; } else if (msg.isProgramChange()) { midiLine += "PROGRAM CHANGE: "; midiLine += String (msg.getProgramChangeNumber()); midiLine += " ("; midiLine += MidiMessage::getGMInstrumentName (msg.getProgramChangeNumber()); midiLine += ")"; } else if (msg.isController()) { midiLine += "CC: #"; midiLine += String (msg.getControllerNumber()); midiLine += " ("; midiLine += MidiMessage::getControllerName (msg.getControllerNumber()); midiLine += ") = "; midiLine += String (msg.getControllerValue()); } else if (msg.isTimeSignatureMetaEvent ()) { int newNumerator, newDenominator; msg.getTimeSignatureInfo (newNumerator, newDenominator); midiLine += "TIME SIGNATURE: "; midiLine += String (newNumerator); midiLine += " / "; midiLine += String (newDenominator); } else if (msg.isTempoMetaEvent ()) { midiLine += "TEMPO: "; midiLine += String (msg.getTempoSecondsPerQuarterNote ()); //midiLine += " "; //midiLine += String (msg.getTempoMetaEventTickLength (ticksPerQuarterNote)); } else if (msg.isMidiMachineControlMessage()) { midiLine += "MIDI CONTROL: "; switch (msg.getMidiMachineControlCommand()) { case MidiMessage::mmc_stop: midiLine += "stop"; break; case MidiMessage::mmc_play: midiLine += "play"; break; case MidiMessage::mmc_deferredplay: midiLine += "deferredplay"; break; case MidiMessage::mmc_fastforward: midiLine += "fastforward"; break; case MidiMessage::mmc_rewind: midiLine += "rewind"; break; case MidiMessage::mmc_recordStart: midiLine += "recordStart"; break; case MidiMessage::mmc_recordStop: midiLine += "recordStop"; break; case MidiMessage::mmc_pause: midiLine += "pause"; break; } } else if (msg.isMidiStart ()) { midiLine += "MIDI START: "; } else if (msg.isMidiContinue ()) { midiLine += "MIDI CONTINUE: "; } else if (msg.isMidiStop ()) { midiLine += "MIDI STOP: "; } else if (msg.isSongPositionPointer ()) { midiLine += "SONG POSITION: "; midiLine += String (msg.getSongPositionPointerMidiBeat ()); } else if (msg.isQuarterFrame ()) { midiLine += "QUARTER FRAME: "; midiLine += String (msg.getQuarterFrameSequenceNumber ()); midiLine += " "; midiLine += String (msg.getQuarterFrameValue ()); } else if (msg.isFullFrame ()) { midiLine += "FULL FRAME: "; msg.getFullFrameParameters (hours, minutes, seconds, frames, timeCode); midiLine += String (hours); midiLine += ":"; midiLine += String (minutes); midiLine += ":"; midiLine += String (seconds); midiLine += ":"; midiLine += String (frames); midiLine += " timecode: "; switch (timeCode) { case MidiMessage::fps24: midiLine += "fps24"; break; case MidiMessage::fps25: midiLine += "fps25"; break; case MidiMessage::fps30drop: midiLine += "fps30drop"; break; case MidiMessage::fps30: midiLine += "fps30"; break; } } else if (msg.isMidiMachineControlGoto (hours, minutes, seconds, frames)) { midiLine += "MIDI CONTROL GOTO: "; midiLine += String (hours); midiLine += ":"; midiLine += String (minutes); midiLine += ":"; midiLine += String (seconds); midiLine += ":"; midiLine += String (frames); } midiOutputEditor->insertTextAtCursor (midiLine + T("\n")); } } }
//============================================================================== void MidiTransform::processEvents (MidiBuffer& midiMessages, const int blockSize) { int timeStamp; MidiMessage message (0xf4, 0.0); MidiBuffer::Iterator it (midiMessages); MidiBuffer midiOutput; switch (command) { case MidiTransform::KeepEvents: break; case MidiTransform::DiscardEvents: { midiMessages.clear (); break; } case MidiTransform::RemapChannel: { while (it.getNextEvent (message, timeStamp)) { message.setChannel (channelNumber); midiOutput.addEvent (message, timeStamp); } midiMessages = midiOutput; break; } case MidiTransform::ScaleNotes: { while (it.getNextEvent (message, timeStamp)) { if (message.isNoteOnOrOff ()) { message.setNoteNumber (roundFloatToInt (message.getNoteNumber () * noteScale)); midiOutput.addEvent (message, timeStamp); } } midiMessages = midiOutput; break; } case MidiTransform::InvertNotes: { while (it.getNextEvent (message, timeStamp)) { if (message.isNoteOnOrOff ()) { message.setNoteNumber (127 - message.getNoteNumber ()); midiOutput.addEvent (message, timeStamp); } } midiMessages = midiOutput; } case MidiTransform::TransposeNotes: { while (it.getNextEvent (message, timeStamp)) { if (message.isNoteOnOrOff ()) { message.setNoteNumber (jmax (0, jmin (127, message.getNoteNumber () - noteTranspose))); midiOutput.addEvent (message, timeStamp); } } midiMessages = midiOutput; break; } case MidiTransform::ScaleVelocity: { while (it.getNextEvent (message, timeStamp)) { if (message.isNoteOn ()) { message.setVelocity ((message.getVelocity () / 127.0f) * velocityScale); midiOutput.addEvent (message, timeStamp); } } midiMessages = midiOutput; break; } case MidiTransform::InvertVelocity: { while (it.getNextEvent (message, timeStamp)) { if (message.isNoteOn ()) { message.setVelocity ((uint8) (127 - message.getVelocity ())); midiOutput.addEvent (message, timeStamp); } } midiMessages = midiOutput; break; } case MidiTransform::TransposeVelocity: { while (it.getNextEvent (message, timeStamp)) { if (message.isNoteOn ()) { message.setVelocity (jmax (0, jmin (127, message.getVelocity () - velocityTranspose))); midiOutput.addEvent (message, timeStamp); } } midiMessages = midiOutput; break; } case MidiTransform::TriggerCC: { break; } case MidiTransform::TriggerNote: { break; } } }
String ZenMidiVisualiserComponent::getMidiMessageDescription(const MidiMessage& m) { if (m.isNoteOn()) return "Note on: " + S(m.getNoteNumber()) + " (" + MidiMessage::getMidiNoteName(m.getNoteNumber(), true, true, 3) + ") Vel: " + S(m.getVelocity()); if (m.isNoteOff()) return "Note off: " + S(m.getNoteNumber()) + " (" + MidiMessage::getMidiNoteName(m.getNoteNumber(), true, true, 3) + ")"; if (m.isProgramChange()) return "Program change (Number): " + String(m.getProgramChangeNumber()); if (m.isPitchWheel()) return "Pitch wheel: " + String(m.getPitchWheelValue()); if (m.isAftertouch()) return "After touch: " + MidiMessage::getMidiNoteName(m.getNoteNumber(), true, true, 3) + ": " + String(m.getAfterTouchValue()); if (m.isChannelPressure()) return "Channel pressure: " + String(m.getChannelPressureValue()); if (m.isAllNotesOff()) return "All notes off"; if (m.isAllSoundOff()) return "All sound off"; if (m.isMetaEvent()) return "Meta event"; if (m.isController()) { String temp = MidiMessage::getControllerName(m.getControllerNumber()); String name = "Controller [" + S(m.getControllerNumber()) + "]"; if (!temp.isEmpty()) name += " " + temp; return name + ": " + String(m.getControllerValue()); } return String::toHexString(m.getRawData(), m.getRawDataSize()); }
void PatternRecording::recordPattern(MidiBuffer &midiMessages, const int &numSamples) { // if we are recording the pattern, just rip the // MIDI messages from the incoming buffer if (isPatternRecording) { // get the iterator for the incoming buffer // so we can check through the messages MidiBuffer::Iterator i(midiMessages); MidiMessage message (0xf4, 0.0); int time; // if we are still during the precount, do nothing if (patternPrecountPosition > numSamples) patternPrecountPosition -= numSamples; // if the precount finishes during this buffer else if (patternPrecountPosition > 0) { // TODO: overdub could be option here? midiPattern.clear(); const int numSamplesToAdd = numSamples - patternPrecountPosition; // DBG("#1 recording " << numSamplesToAdd << " of midi, pos: " << patternPrecountPosition); // get messages from the main MIDI message queue while(i.getNextEvent(message, time)) { // and add them if they occur after the precount runs out if (time > patternPrecountPosition) { midiPattern.addEvent(message, time - patternPrecountPosition); // store noteOffs to fire at end if (message.isNoteOn()) { MidiMessage tempNoteOff = MidiMessage::noteOff(message.getChannel(), message.getNoteNumber(), message.getVelocity()); noteOffs.addEvent(tempNoteOff, 0); } } } // the precount has finished patternPrecountPosition = 0; // we are now numSamplesToAdd into the buffer patternPosition = numSamplesToAdd; } else { // if we are during recording (and not near the end), just // add the current input into the record buffer if (numSamples + patternPosition < patternLengthInSamples) { // DBG("#2 recording " << numSamples << " of midi, pos: " << patternPosition); // get messages from the main MIDI message queue while(i.getNextEvent(message, time)) { midiPattern.addEvent(message, time + patternPosition); // store noteOffs to fire at end if (message.isNoteOn()) { MidiMessage tempNoteOff = MidiMessage::noteOff(message.getChannel(), message.getNoteNumber(), message.getVelocity()); noteOffs.addEvent(tempNoteOff, 0); } } //midiPattern.addEvents(midiMessages, 0, numSamples, -patternPosition); patternPosition += numSamples; } // otherwise we are finishing up else { const int numSamplesLeftToRecord = patternLengthInSamples - patternPosition; // add remaining messages from the main MIDI message queue while(i.getNextEvent(message, time)) { if (time < numSamplesLeftToRecord) midiPattern.addEvent(message, time + patternPosition); // store noteOffs to fire at end if (message.isNoteOn()) { MidiMessage tempNoteOff = MidiMessage::noteOff(message.getChannel(), message.getNoteNumber(), message.getVelocity()); noteOffs.addEvent(tempNoteOff, 0); } } // add the note offs to clear any "phantom notes" midiPattern.addEvents(noteOffs, 0, 1, patternLengthInSamples - 1); // we are no longer recording isPatternRecording = false; // if we finish recording, let any listeners know // so they can redraw representations of the pattern sendChangeMessage(); DBG("pattern " << patternBank << " finished recording."); // start playing back from the start straight away isPatternStopping = false; isPatternPlaying = true; patternPosition = 0; // fill the remaining buffer with the newly recorded sequence const int samplesRemaining = numSamples - numSamplesLeftToRecord; if (patternPosition + samplesRemaining < patternLengthInSamples) { midiMessages.addEvents(midiPattern, patternPosition, samplesRemaining, numSamplesLeftToRecord); patternPosition += samplesRemaining; } } // Let the PatternStripControl know to recache pattern sendChangeMessage(); } } }
void MIDIReceiver::handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message) { DBG("midi in"); // is this midi input source enabled if(_MidiDeviceManager->isMidiInputEnabled(source->getName())) { DBG(source->getName()); if(message.isController() && _MidiDeviceManager->isCcEnabled(source->getName(), true) && appProperties->getUserSettings()->getIntValue("midiInputChannel") == message.getChannel()) { DBG(message.getControllerNumber() ); // reference counted Signal ( string command, string origin ) Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "RCV_MIDI"); ledStateSignal->addStringArg("/nomestate/grid/led/set"); // get the x position: LED bumber % 8 ledStateSignal->addIntArg(message.getControllerNumber() % 8); // get the y position: LED number / 8 ledStateSignal->addIntArg(message.getControllerNumber() / 8); // get the LED state: toggleState int ledState; if (message.getControllerValue() > 0) { ledState = 1; } ledStateSignal->addIntArg(ledState); _mCenter->handleSignal(*ledStateSignal); } else if (message.isNoteOn() && _MidiDeviceManager->isNoteEnabled(source->getName(), true) && appProperties->getUserSettings()->getIntValue("midiInputChannel") == message.getChannel()) { // lets set the color based off MIDI note Velocity int MIDIVelocity = message.getVelocity(); int r = 0; int g = 0; int b = 0; if (MIDIVelocity > 0) { // red if (MIDIVelocity <= 22) { r = 127; } // yellow else if (MIDIVelocity <= 43) { r = 127; g = 127; } // green else if (MIDIVelocity <= 64) { g = 127; } // teal else if (MIDIVelocity <= 85) { g = 127; b = 127; } // blue else if (MIDIVelocity <= 106) { b = 127; } // purple else { b = 127; r = 127; } } // reference counted Signal ( string command, string origin ) Signal::SignalP ledColourSignal = new Signal("SEND_OSC", "RCV_MIDI"); ledColourSignal->addStringArg("/nomestate/grid/led/color"); // get the x position: LED bumber % 8 ledColourSignal->addIntArg(message.getNoteNumber() % 8); // get the y position: LED number / 8 ledColourSignal->addIntArg(message.getNoteNumber() / 8); // get the LED RED: ledColourSignal->addIntArg(r); // get the LED GREEN: ledColourSignal->addIntArg(g); // get the LED BLUE: ledColourSignal->addIntArg(b); _mCenter->handleSignal(*ledColourSignal); // reference counted Signal ( string command, string origin ) Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "RCV_MIDI"); ledStateSignal->addStringArg("/nomestate/grid/led/set"); // get the x position: LED bumber % 8 ledStateSignal->addIntArg(message.getNoteNumber() % 8); // get the y position: LED number / 8 ledStateSignal->addIntArg(message.getNoteNumber() / 8); // get the LED state: toggleState ledStateSignal->addIntArg(1); _mCenter->handleSignal(*ledStateSignal); } else if (message.isNoteOff() && _MidiDeviceManager->isNoteEnabled(source->getName(), true) && appProperties->getUserSettings()->getIntValue("midiInputChannel") == message.getChannel()) { // reference counted Signal ( string command, string origin ) Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "RCV_MIDI"); ledStateSignal->addStringArg("/nomestate/grid/led/set"); // get the x position: LED bumber % 8 ledStateSignal->addIntArg(message.getNoteNumber() % 8); // get the y position: LED number / 8 ledStateSignal->addIntArg(message.getNoteNumber() / 8); // get the LED state: toggleState ledStateSignal->addIntArg(0); _mCenter->handleSignal(*ledStateSignal); } } }
void InstanceProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { for(int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i) { buffer.clear(i, 0, buffer.getNumSamples()); } bool infos = false; AudioPlayHead* playhead = getPlayHead(); if(playhead && m_patch_tie) { infos = playhead->getCurrentPosition(m_playinfos); } lock(); { m_midi.clear(); if(infos) { m_playing_list.setFloat(0, m_playinfos.isPlaying); m_playing_list.setFloat(1, m_playinfos.timeInSeconds); sendMessageAnything(m_patch_tie, s_playing, m_playing_list); m_measure_list.setFloat(0, m_playinfos.bpm); m_measure_list.setFloat(1, m_playinfos.timeSigNumerator); m_measure_list.setFloat(2, m_playinfos.timeSigDenominator); m_measure_list.setFloat(3, m_playinfos.ppqPosition); m_measure_list.setFloat(4, m_playinfos.ppqPositionOfLastBarStart); sendMessageAnything(m_patch_tie, s_measure, m_measure_list); } for(size_t i = 0; i < m_parameters.size() && m_parameters[i].isValid(); ++i) { sendMessageFloat(m_parameters[i].getTie(), m_parameters[i].getValueNonNormalized()); } MidiMessage message; MidiBuffer::Iterator it(midiMessages); int position = midiMessages.getFirstEventTime(); while(it.getNextEvent(message, position)) { if(message.isNoteOnOrOff()) { sendMidiNote(message.getChannel(), message.getNoteNumber(), message.getVelocity()); } else if(message.isController()) { sendMidiControlChange(message.getChannel(), message.getControllerNumber(), message.getControllerValue()); } else if(message.isPitchWheel()) { sendMidiPitchBend(message.getChannel(), message.getPitchWheelValue()); } else if(message.isChannelPressure()) { sendMidiAfterTouch(message.getChannel(), message.getChannelPressureValue()); } else if(message.isAftertouch()) { sendMidiPolyAfterTouch(message.getChannel(), message.getNoteNumber(), message.getAfterTouchValue()); } else if(message.isProgramChange()) { sendMidiProgramChange(message.getChannel(), message.getProgramChangeNumber()); } } } midiMessages.clear(); performDsp(buffer.getNumSamples(), getTotalNumInputChannels(), buffer.getArrayOfReadPointers(), getTotalNumOutputChannels(), buffer.getArrayOfWritePointers()); midiMessages.swapWith(m_midi); unlock(); }
void MIDIInputDevice::handleIncomingMidiMessage(MidiInput * source, const MidiMessage & message) { if (source != device) { DBG("different device"); return; } if (message.isNoteOn()) inputListeners.call(&MIDIInputListener::noteOnReceived, message.getChannel(), message.getNoteNumber(), message.getVelocity()); else if(message.isNoteOff()) inputListeners.call(&MIDIInputListener::noteOffReceived, message.getChannel(), message.getNoteNumber(), 0); //force note off to velocity 0 else if(message.isController()) inputListeners.call(&MIDIInputListener::controlChangeReceived, message.getChannel(), message.getControllerNumber(), message.getControllerValue()); else if(message.isSysEx()) inputListeners.call(&MIDIInputListener::sysExReceived, message); }