bool MidiControlAction::processIncomingMessage(const MidiMessage& message) { if (isLearning) { isLearning = false; messageTemplate = message; return true; } else if (message.isForChannel(messageTemplate.getChannel())) { if (messageTemplate.isNoteOnOrOff() && message.isNoteOnOrOff() && message.getNoteNumber() == messageTemplate.getNoteNumber()) { // toggle! if (message.isNoteOn() && message.getNoteNumber() == messageTemplate.getNoteNumber()) { getMappedComponent()->setValue(getMappedComponent()->getValue() >= 0.5f?0.f:1.f); getMappedComponent()->triggerAsyncUpdate(); } return true; } else if (messageTemplate.isController() && message.isController() && messageTemplate.getControllerNumber() == message.getControllerNumber()) { //setValue(message.getControllerValue() / 127.0f); getMappedComponent()->setValue(message.getControllerValue() / 127.0f); getMappedComponent()->triggerAsyncUpdate(); return true; } } return false; }
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:[----]"); }
void Synthesiser::handleMidiEvent (const MidiMessage& m) { if (m.isNoteOn()) { noteOn (m.getChannel(), m.getNoteNumber(), m.getFloatVelocity()); } else if (m.isNoteOff()) { noteOff (m.getChannel(), m.getNoteNumber(), true); } else if (m.isAllNotesOff() || m.isAllSoundOff()) { allNotesOff (m.getChannel(), true); } else if (m.isPitchWheel()) { const int channel = m.getChannel(); const int wheelPos = m.getPitchWheelValue(); lastPitchWheelValues [channel - 1] = wheelPos; handlePitchWheel (channel, wheelPos); } else if (m.isController()) { handleController (m.getChannel(), m.getControllerNumber(), m.getControllerValue()); } }
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 MPESynthesiser::handleMidiEvent (const MidiMessage& m) { if (m.isController()) handleController (m.getChannel(), m.getControllerNumber(), m.getControllerValue()); else if (m.isProgramChange()) handleProgramChange (m.getChannel(), m.getProgramChangeNumber()); MPESynthesiserBase::handleMidiEvent (m); }
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 Pfm2AudioProcessor::handleIncomingMidiBuffer(MidiBuffer &buffer, int numberOfSamples) { if (!buffer.isEmpty()) { MidiBuffer newBuffer; MidiMessage midiMessage; int samplePosition; MidiBuffer::Iterator midiIterator(buffer); while (midiIterator.getNextEvent(midiMessage, samplePosition)) { bool copyMessageInNewBuffer = true; if (midiMessage.isController() && midiMessage.getChannel() == currentMidiChannel) { switch (midiMessage.getControllerNumber()) { case 99: currentNrpn.paramMSB = midiMessage.getControllerValue(); copyMessageInNewBuffer = false; break; case 98: currentNrpn.paramLSB = midiMessage.getControllerValue(); copyMessageInNewBuffer = false; break; case 6: currentNrpn.valueMSB = midiMessage.getControllerValue(); copyMessageInNewBuffer = false; break; case 38: { currentNrpn.valueLSB = midiMessage.getControllerValue(); copyMessageInNewBuffer = false; int param = (int)(currentNrpn.paramMSB << 7) + currentNrpn.paramLSB; int value = (int)(currentNrpn.valueMSB << 7) + currentNrpn.valueLSB; const MessageManagerLock mmLock; handleIncomingNrpn(param, value); break; } } } if (copyMessageInNewBuffer) { newBuffer.addEvent(midiMessage, samplePosition); } } buffer.swapWith(newBuffer); } }
//============================================================================== void MPEZoneLayout::processNextMidiEvent (const MidiMessage& message) { if (! message.isController()) return; MidiRPNMessage rpn; if (rpnDetector.parseControllerMessage (message.getChannel(), message.getControllerNumber(), message.getControllerValue(), rpn)) { processRpnMessage (rpn); } }
//============================================================================== void MidiSequencePlugin::getControllerIndexed (const int index, int& controllerNum, double& value, double& beat) { int numNoteOn = 0; for (int i = 0; i < midiSequence->getNumEvents (); i++) { MidiMessageSequence::MidiEventHolder* eventOn = midiSequence->getEventPointer (i); MidiMessage* msgOn = & eventOn->message; if (eventOn->message.isController ()) { if (index == numNoteOn) { controllerNum = msgOn->getControllerNumber(); value = msgOn->getControllerValue () / 127.0; beat = msgOn->getTimeStamp (); break; } numNoteOn++; } } }
void Synthesiser::handleMidiEvent (const MidiMessage& m) { const int channel = m.getChannel(); if (m.isNoteOn()) { noteOn (channel, m.getNoteNumber(), m.getFloatVelocity()); } else if (m.isNoteOff()) { noteOff (channel, m.getNoteNumber(), m.getFloatVelocity(), true); } else if (m.isAllNotesOff() || m.isAllSoundOff()) { allNotesOff (channel, true); } else if (m.isPitchWheel()) { const int wheelPos = m.getPitchWheelValue(); lastPitchWheelValues [channel - 1] = wheelPos; handlePitchWheel (channel, wheelPos); } else if (m.isAftertouch()) { handleAftertouch (channel, m.getNoteNumber(), m.getAfterTouchValue()); } else if (m.isChannelPressure()) { handleChannelPressure (channel, m.getChannelPressureValue()); } else if (m.isController()) { handleController (channel, m.getControllerNumber(), m.getControllerValue()); } else if (m.isProgramChange()) { handleProgramChange (channel, m.getProgramChangeNumber()); } }
void Gear_Slider::runAudio() { bool accept_midi = _settings.get(Gear_Slider::SETTING_ACCEPTMIDI)->valueBool(); if(accept_midi) { MidiMessage* msg; std::vector<MidiMessage*> messages = MidiEngine::getInstance().getMessages(); if(messages.size()) { int channel = _settings.get(Gear_Slider::SETTING_MIDICHANNEL)->valueInt(); int controller = _settings.get(Gear_Slider::SETTING_MIDICONTROLLER)->valueInt(); // we only consider the LAST controller value float low = _settings.get(Gear_Slider::SETTING_LOWERBOUND)->valueFloat(); float hi = _settings.get(Gear_Slider::SETTING_HIGHERBOUND)->valueFloat(); float lastValue = -1,lastStamp; for(unsigned int i=0;i<messages.size();i++) { msg = messages[i]; if(msg->isControllerChange() && msg->getChannel()==channel && msg->getController()==controller) { lastValue = (float)msg->getControllerValue() / 127; lastStamp = msg->getStamp(); } } if(lastValue!=-1) { //std::cout<<"set Value !! :"<<lastValue<<" "<<lastStamp<<std::endl; setValue(low + (hi-low)*lastValue); // can't call this from here since we're in a different thread than the GUI //getGearGui()->reDraw(); } } } }
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()); }
static String getMidiMessageDescription (const MidiMessage& m) { if (m.isNoteOn()) return "Note on " + MidiMessage::getMidiNoteName (m.getNoteNumber(), true, true, 3); if (m.isNoteOff()) return "Note off " + MidiMessage::getMidiNoteName (m.getNoteNumber(), true, true, 3); if (m.isProgramChange()) return "Program change " + 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 name (MidiMessage::getControllerName (m.getControllerNumber())); if (name.isEmpty()) name = "[" + String (m.getControllerNumber()) + "]"; return "Controler " + name + ": " + String (m.getControllerValue()); } return String::toHexString (m.getRawData(), m.getRawDataSize()); }
//============================================================================== void MidiSequencePlugin::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { MidiSequencePluginBase::processBlock(buffer, midiMessages); MidiMessageSequence sourceMidi = *midiSequence; std::vector<int> doneTheseControllers; if (transport->isPlaying () && getBoolValue(PROP_SEQENABLED, true)) { const int blockSize = buffer.getNumSamples (); MidiBuffer* midiBuffer = midiBuffers.getUnchecked (0); const int frameCounter = transport->getPositionInFrames (); const int framesPerBeat = transport->getFramesPerBeat (); const int nextBlockFrameNumber = frameCounter + blockSize; const int seqIndex = getLoopRepeatIndex(); const double beatCount = getLoopBeatPosition(); const double frameLenBeatCount = (nextBlockFrameNumber - frameCounter) / (double)framesPerBeat; double frameEndBeatCount = beatCount + frameLenBeatCount; if (frameEndBeatCount > getLengthInBeats()) frameEndBeatCount -= getLengthInBeats(); // loop for each controller we need to interpolate MidiMessage* lastCtrlEvent = NULL; do { lastCtrlEvent = NULL; // hunt for a controller event before now int i; for (i = 0; i < sourceMidi.getNumEvents (); i++) { int timeStampInSeq = roundFloatToInt (sourceMidi.getEventTime (i) * framesPerBeat); int timeStamp = timeStampInSeq + (seqIndex * getLengthInBeats() * framesPerBeat); MidiMessage* midiMessage = &sourceMidi.getEventPointer (i)->message; if (timeStamp >= nextBlockFrameNumber || !midiMessage) break; // event is after now, leave //if (midiMessage->isController() && (std::find(doneTheseControllers.begin(), doneTheseControllers.end(), midiMessage->getControllerNumber()) == doneTheseControllers.end())) // lastCtrlEvent = midiMessage; } // hunt for a matching event after that one if (lastCtrlEvent) { // store the controller number so we know which controllers we've done doneTheseControllers.push_back(lastCtrlEvent->getControllerNumber()); MidiMessage* nextCtrlEvent = NULL; for (; i < sourceMidi.getNumEvents (); i++) { MidiMessage* midiMessage = &sourceMidi.getEventPointer (i)->message; if (midiMessage->isController() && midiMessage->getControllerNumber() == lastCtrlEvent->getControllerNumber()) { nextCtrlEvent = midiMessage; break; } } // render an interpolated event!... if (nextCtrlEvent) { double bt = nextCtrlEvent->getTimeStamp(); double at = lastCtrlEvent->getTimeStamp(); double deltaBeats = bt - at; int a = lastCtrlEvent->getControllerValue(); int b = nextCtrlEvent->getControllerValue(); double now = beatCount + (frameEndBeatCount - beatCount) / 2.0; double interpRemainBeats = deltaBeats - (now - at); if (deltaBeats > 0) { double nextPart = interpRemainBeats / deltaBeats; nextPart = 1 - nextPart; double interpdVal = a + nextPart * (b - a); MidiMessage interpy = MidiMessage::controllerEvent(lastCtrlEvent->getChannel(), lastCtrlEvent->getControllerNumber(), static_cast<int>(interpdVal)); midiBuffer->addEvent (interpy, (nextBlockFrameNumber - frameCounter) / 2); } else { DBG ("Negative delta beats when rendering automation!!"); } } } // now we also need to do that again if there are multiple events per frame AND we are interpolating multiple times per frame // (at the moment only interpolating once per audio frame) } while (lastCtrlEvent != NULL); } }
//============================================================================== bool MidiSequencePlugin::eventMoved ( const int controllerNum, const double oldValue, const float oldBeat, const double automationValue, const float beatNumber) { DBG ("Moving:" + String (oldValue) + " " + String (oldBeat)); double noteOnBeats = oldBeat - NOTE_PREFRAMES; int eventIndex = midiSequence->getNextIndexAtTime (noteOnBeats); while (eventIndex < midiSequence->getNumEvents ()) { MidiMessage* eventOn = &midiSequence->getEventPointer (eventIndex)->message; if (eventOn->isController() && eventOn->getControllerNumber() == controllerNum && eventOn->getControllerValue() == floor(oldValue * 127)) // should make this a "matches controller" method { MidiMessage msgOn = MidiMessage::controllerEvent (NOTE_CHANNEL, controllerNum, automationValue * 127); msgOn.setTimeStamp (beatNumber); { const ScopedLock sl (parentHost->getCallbackLock()); // remove old events midiSequence->deleteEvent (eventIndex, true); midiSequence->addEvent (msgOn); } return true; } eventIndex++; } DBG (">>> Move failed:" + String (oldValue) + " @ " + String (oldBeat)); return false; }
//============================================================================== bool MidiSequencePlugin::eventRemoved (const int controller, const double automationValue, const float beatNumber) { DBG ("Removing:" + String (automationValue) + " " + String (beatNumber)); double noteOnBeats = beatNumber - NOTE_PREFRAMES; int eventIndex = midiSequence->getNextIndexAtTime (noteOnBeats); while (eventIndex < midiSequence->getNumEvents ()) { MidiMessage* eventOn = &midiSequence->getEventPointer (eventIndex)->message; if (eventOn->isController() && eventOn->getControllerNumber() == controller && eventOn->getControllerValue() == floor(automationValue * 127)) { { const ScopedLock sl (parentHost->getCallbackLock()); midiSequence->deleteEvent (eventIndex, true); } DBG ("Removed:" + String (eventIndex) + " > " + String (automationValue) + " @ " + String (beatNumber)); if (transport->isPlaying ()) doAllNotesOff = true; return true; } eventIndex++; } DBG (">>> Remove failed:" + String (automationValue) + " @ " + String (beatNumber)); return false; }
//------------------------------------------------------------------------------ void MidiMappingManager::midiCcReceived(const MidiMessage& message, double secondsSinceStart) { if(message.isController()) { multimap<int, MidiMapping *>::iterator it; multimap<int, MidiAppMapping *>::iterator it2; int cc = message.getControllerNumber(); int value = message.getControllerValue(); //Check if it matches any MidiMappings. for(it=mappings.lower_bound(cc); it!=mappings.upper_bound(cc); ++it) { it->second->ccReceived(value); } if(value > 64) { //Check if it matches any MidiAppMappings. for(it2=appMappings.lower_bound(cc); it2!=appMappings.upper_bound(cc); ++it2) { CommandID id = it2->second->getId(); MainPanel *panel = dynamic_cast<MainPanel *>(appManager->getFirstCommandTarget(MainPanel::TransportPlay)); if(panel) { if(id != MainPanel::TransportTapTempo) panel->invokeCommandFromOtherThread(id); else { double tempo = tapHelper.updateTempo(secondsSinceStart); if(tempo > 0.0) panel->updateTempoFromOtherThread(tempo); } } } } } else if(message.isMidiMachineControlMessage()) { if(PropertiesSingleton::getInstance().getUserSettings()->getBoolValue(L"mmcTransport", false)) { CommandID id = -1; MainPanel *panel = dynamic_cast<MainPanel *>(appManager->getFirstCommandTarget(MainPanel::TransportPlay)); switch(message.getMidiMachineControlCommand()) { case MidiMessage::mmc_stop: id = MainPanel::TransportPlay; break; case MidiMessage::mmc_play: id = MainPanel::TransportPlay; break; case MidiMessage::mmc_rewind: id = MainPanel::TransportRtz; break; case MidiMessage::mmc_pause: id = MainPanel::TransportPlay; break; default: break; } if((id > -1) && panel) panel->invokeCommandFromOtherThread(id); } } else if(message.isProgramChange()) { if(PropertiesSingleton::getInstance().getUserSettings()->getBoolValue(L"midiProgramChange", false)) { int newPatch; MainPanel *panel = dynamic_cast<MainPanel *>(appManager->getFirstCommandTarget(MainPanel::TransportPlay)); newPatch = message.getProgramChangeNumber(); if(panel) panel->switchPatchFromProgramChange(newPatch); } } }
//============================================================================== 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 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); }
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 MidiControllerAutomationHandler::handleParameterData(MidiBuffer &b) { const bool bufferEmpty = b.isEmpty(); const bool noCCsUsed = !anyUsed && !unlearnedData.used; if (bufferEmpty || noCCsUsed) return; tempBuffer.clear(); MidiBuffer::Iterator mb(b); MidiMessage m; int samplePos; while (mb.getNextEvent(m, samplePos)) { bool consumed = false; if (m.isController()) { const int number = m.getControllerNumber(); if (isLearningActive()) { setUnlearndedMidiControlNumber(number, sendNotification); } for (auto& a : automationData[number]) { if (a.used) { jassert(a.processor.get() != nullptr); auto normalizedValue = (double)m.getControllerValue() / 127.0; if (a.inverted) normalizedValue = 1.0 - normalizedValue; const double value = a.parameterRange.convertFrom0to1(normalizedValue); const float snappedValue = (float)a.parameterRange.snapToLegalValue(value); if (a.macroIndex != -1) { a.processor->getMainController()->getMacroManager().getMacroChain()->setMacroControl(a.macroIndex, (float)m.getControllerValue(), sendNotification); } else { if (a.lastValue != snappedValue) { a.processor->setAttribute(a.attribute, snappedValue, sendNotification); a.lastValue = snappedValue; } } consumed = true; } } } if (!consumed) tempBuffer.addEvent(m, samplePos); } b.clear(); b.addEvents(tempBuffer, 0, -1, 0); }
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 MiditoOscAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { static float cv[8], shiftcv[8]; static bool _calibMode; MidiBuffer processedMidi; MidiMessage m; int time; char oscBuffer[IP_MTU_SIZE]; osc::OutboundPacketStream p(oscBuffer, IP_MTU_SIZE); if (calibMode) // Calibration Mode A440Hz(MIDI number 69) { p << osc::BeginBundleImmediate << osc::BeginMessage( "/fader1" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader2" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader3" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader4" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader5" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader6" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader7" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/fader8" ) << calibMap[69] << osc::EndMessage << osc::BeginMessage( "/gate1" ) << 1 << osc::EndMessage << osc::BeginMessage( "/gate2" ) << 1 << osc::EndMessage << osc::EndBundle; sendOSCData(p); _calibMode = true; return; } else { if (_calibMode) { p << osc::BeginBundleImmediate << osc::BeginMessage( "/gate1" ) << 0 << osc::EndMessage << osc::BeginMessage( "/gate2" ) << 0 << osc::EndMessage << osc::EndBundle; sendOSCData(p); _calibMode = false; } } for (MidiBuffer::Iterator i (midiMessages); i.getNextEvent (m, time);) { p.Clear(); usleep(30); if (m.isNoteOn()) { if (monoMode) // mono Mode { uint32_t midiCh = m.getChannel(); if (midiCh == 0 || midiCh > 7) { midiCh = 1; } cv[midiCh - 1] = calibMap[m.getNoteNumber()]; switch (midiCh) { case 1: p << osc::BeginMessage("/fader1") << cv[0] << osc::EndMessage; break; case 2: p << osc::BeginMessage("/fader2") << cv[1] << osc::EndMessage; break; case 3: p << osc::BeginMessage("/fader3") << cv[2] << osc::EndMessage; break; case 4: p << osc::BeginMessage("/fader4") << cv[3] << osc::EndMessage; break; case 5: p << osc::BeginMessage("/fader5") << cv[4] << osc::EndMessage; break; case 6: p << osc::BeginMessage("/fader6") << cv[5] << osc::EndMessage; break; case 7: p << osc::BeginMessage("/fader7") << cv[6] << osc::EndMessage; break; case 8: p << osc::BeginMessage("/fader8") << cv[7] << osc::EndMessage; break; default: break; } sendOSCData(p); } else if (shiftMode) { // shift Mode cv[0] = calibMap[m.getNoteNumber()]; for (int i = 7; i > 0; i--) { shiftcv[i] = shiftcv[i-1]; } p << osc::BeginBundleImmediate << osc::BeginMessage( "/fader1" ) << cv[0] << osc::EndMessage << osc::BeginMessage( "/fader2" ) << shiftcv[1] << osc::EndMessage << osc::BeginMessage( "/fader3" ) << shiftcv[2] << osc::EndMessage << osc::BeginMessage( "/fader4" ) << shiftcv[3] << osc::EndMessage << osc::BeginMessage( "/fader5" ) << shiftcv[4] << osc::EndMessage << osc::BeginMessage( "/fader6" ) << shiftcv[5] << osc::EndMessage << osc::BeginMessage( "/fader7" ) << shiftcv[6] << osc::EndMessage << osc::BeginMessage( "/fader8" ) << shiftcv[7] << osc::EndMessage << osc::BeginMessage( "/gate1" ) << 1 << osc::EndMessage << osc::BeginMessage( "/gate2" ) << 1 << osc::EndMessage << osc::EndBundle; sendOSCData(p); shiftcv[0] = cv[0]; } else { // poly Mode cv[ch] = calibMap[m.getNoteNumber()]; if (currentMaxPoly == 1) { cv[1] = cv[0]; } p << osc::BeginBundleImmediate << osc::BeginMessage( "/fader1" ) << cv[0] << osc::EndMessage << osc::BeginMessage( "/fader2" ) << cv[1] << osc::EndMessage << osc::BeginMessage( "/fader3" ) << cv[2] << osc::EndMessage << osc::BeginMessage( "/fader4" ) << cv[3] << osc::EndMessage << osc::BeginMessage( "/fader5" ) << cv[4] << osc::EndMessage << osc::BeginMessage( "/fader6" ) << cv[5] << osc::EndMessage << osc::BeginMessage( "/fader7" ) << m.getFloatVelocity() << osc::EndMessage << osc::BeginMessage( "/gate1" ) << 1 << osc::EndMessage << osc::BeginMessage( "/gate2" ) << 1 << osc::EndMessage << osc::EndBundle; sendOSCData(p); ch++; gateCount++; if (ch >= currentMaxPoly) { ch = 0; } } } else if (m.isNoteOff()) { if (monoMode) { switch (m.getChannel()) { case 1: p << osc::BeginMessage( "/gate1" ) << 0 << osc::EndMessage; break; case 2: p << osc::BeginMessage( "/gate2" ) << 0 << osc::EndMessage; break; case 3: p << osc::BeginMessage( "/gate3" ) << 0 << osc::EndMessage; break; case 4: p << osc::BeginMessage( "/gate4" ) << 0 << osc::EndMessage; break; default: break; } sendOSCData(p); } else if (shiftMode) { p << osc::BeginBundleImmediate << osc::BeginMessage( "/gate1" ) << 0 << osc::EndMessage << osc::BeginMessage( "/gate2" ) << 0 << osc::EndMessage << osc::EndBundle; sendOSCData(p); } else { gateCount --; if (gateCount <= 0) { p << osc::BeginBundleImmediate << osc::BeginMessage( "/gate1" ) << 0 << osc::EndMessage << osc::BeginMessage( "/gate2" ) << 0 << osc::EndMessage << osc::EndBundle; sendOSCData(p); gateCount = 0; } ch--; if (ch == -1) { ch = 0; } } } else if (m.isControllerOfType(1)) { // Modulation Wheel float modulation = m.getControllerValue(); if (!monoMode && !shiftMode) { p << osc::BeginMessage("/fader8") << (modulation / 127) << osc::EndMessage; sendOSCData(p); } } processedMidi.addEvent (m, time); } midiMessages.swapWith (processedMidi); buffer.clear(); for (int channel = 0; channel < getNumInputChannels(); ++channel) { float* channelData = 0; } }