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 MidiThread::run() { midiPort = MidiOutput::openDevice(0); map<double, double>::iterator tempoIterator = tempos.begin(); double tickLength = tempoIterator->second; double initTempo = 60000 / (tickLength * ppq); tempoIterator++; map<double, std::pair<int, int>>::iterator timeSigIterator = timeSigs.begin(); int timeSigNumerator = timeSigIterator->second.first; int timeSigDenominator = timeSigIterator->second.second; timeSigIterator++; MidiMessage message; // MIDI click intro File clickFile("Click120.mid"); ScopedPointer<FileInputStream> clickStream = clickFile.createInputStream(); double eventTick; double prevTick = 0; double prevDelta = 0; int now = Time::getMillisecondCounter(); if (clickStream) { click.readFrom(*clickStream); short clickPpq = click.getTimeFormat(); MidiMessageSequence clickSequence = MidiMessageSequence(); clickSequence = *click.getTrack(0); int i = 0; while (i < clickSequence.getNumEvents()) { message = clickSequence.getEventPointer(i)->message; eventTick = message.getTimeStamp(); double origBpm = 60000 / (tickLength * clickPpq); double delta = prevDelta + ((eventTick - prevTick) * (origBpm / initTempo)) * tickLength; Time::waitForMillisecondCounter(now + delta); midiPort->sendMessageNow(message); i++; prevTick = eventTick; prevDelta = delta; } } now = Time::getMillisecondCounter(); prevTick = 0; prevDelta = 0; int currentBar = 1; int currentBeat = 1; int currentTick = 0; int quartersPerBar = timeSigNumerator * (timeSigDenominator / 4); int tickStartOfBar = 0; int tickStartNextBar = quartersPerBar * ppq; currentBpm = initTempo; int i = 0; while (i < midiSequence.getNumEvents() && !threadShouldExit()) { std::stringstream ss; ss << currentBpm; content->updateBpm(ss.str()); message = midiSequence.getEventPointer(i)->message; eventTick = message.getTimeStamp(); // number of midi ticks until note if (tempoIterator != tempos.end() && eventTick >= tempoIterator->first) { tickLength = tempoIterator->second; tempoIterator++; } if (timeSigIterator != timeSigs.end() && eventTick >= timeSigIterator->first) { timeSigNumerator = timeSigIterator->second.first; timeSigDenominator = timeSigIterator->second.second; quartersPerBar = timeSigNumerator * (4 / timeSigDenominator); timeSigIterator++; } if (eventTick >= tickStartNextBar) { tickStartOfBar = tickStartNextBar; tickStartNextBar = tickStartOfBar + quartersPerBar * ppq; currentBar = currentBar + static_cast<int> (std::floor((eventTick - tickStartOfBar) / (ppq * quartersPerBar))) + 1; } currentBeat = static_cast<int> (std::floor((eventTick - tickStartOfBar)/ ppq)) % timeSigNumerator + 1; currentTick = static_cast<int> (eventTick) % ppq; if (!message.isMetaEvent() && (currentTick == 0 || currentTick == 120 || currentTick == 240 || currentTick == 360)) { std::stringstream ss; ss << currentBar << ":" << currentBeat << ":" << setfill('0') << setw(3) << currentTick; content->updateBbt(ss.str()); } double origBpm = 60000 / (tickLength * ppq); double delta = prevDelta + ((eventTick - prevTick) * (origBpm / currentBpm)) * tickLength; Time::waitForMillisecondCounter(now + delta); midiPort->sendMessageNow(message); i++; prevTick = eventTick; prevDelta = delta; } delete midiPort; return; }
const String getName(const MidiMessage &m) { if (m.isActiveSense()) { return (" [Active Sense]"); } if (m.isAftertouch()) { return (" [Aftertouch]"); } if (m.isAllNotesOff()) { return (" [All notes off]"); } if (m.isAllSoundOff()) { return (" [All sound off]"); } if (m.isChannelPressure()) { return (" [Channel pressure]"); } if (m.isController()) { return (" [Controller]"); } if (m.isFullFrame()) { return (" [Full frame]"); } if (m.isMetaEvent()) { return (" [Meta event]"); } if (m.isMidiClock()) { return (" [MIDI Clock]"); } if (m.isMidiContinue()) { return (" [MIDI Continue]"); } if (m.isMidiStart()) { return (" [MIDI Start]"); } if (m.isMidiStop()) { return (" [MIDI Stop]"); } if (m.isNoteOff()) { return (" [Note off]"); } if (m.isNoteOn()) { return (" [Note on]"); } if (m.isPitchWheel()) { return (" [Pitch wheel]"); } if (m.isProgramChange()) { return (" [Program change]"); } if (m.isQuarterFrame()) { return (" Quarter frame]"); } if (m.isSysEx()) { return (" [System exclusive]"); } return (" [Yet unknown]"); }