diff --git a/examples/Demo/Source/Demos/MidiDemo.cpp b/examples/Demo/Source/Demos/MidiDemo.cpp index fed2a254dc..48b86ddeaa 100644 --- a/examples/Demo/Source/Demos/MidiDemo.cpp +++ b/examples/Demo/Source/Demos/MidiDemo.cpp @@ -24,32 +24,6 @@ #include "../JuceDemoHeader.h" -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()); -} - -//============================================================================== /** Simple list box that just displays a StringArray. */ class MidiLogListBoxModel : public ListBoxModel { @@ -77,7 +51,7 @@ public: ((int) (time / 3600.0)) % 24, ((int) (time / 60.0)) % 60, ((int) time) % 60) - + " - " + getMidiMessageDescription (message), + + " - " + message.getDescription(), Rectangle (width, height).reduced (4, 0), Justification::centredLeft, true); } diff --git a/modules/juce_audio_basics/midi/juce_MidiMessage.cpp b/modules/juce_audio_basics/midi/juce_MidiMessage.cpp index a3867a2890..c0261ab768 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessage.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiMessage.cpp @@ -309,6 +309,31 @@ uint8* MidiMessage::allocateSpace (int bytes) return preallocatedData.asBytes; } +String MidiMessage::getDescription() const +{ + if (isNoteOn()) return "Note on " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel()); + if (isNoteOff()) return "Note off " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel()); + if (isProgramChange()) return "Program change " + String (getProgramChangeNumber()) + " Channel " + String (getChannel()); + if (isPitchWheel()) return "Pitch wheel " + String (getPitchWheelValue()) + " Channel " + String (getChannel()); + if (isAftertouch()) return "Aftertouch " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + ": " + String (getAfterTouchValue()) + " Channel " + String (getChannel()); + if (isChannelPressure()) return "Channel pressure " + String (getChannelPressureValue()) + " Channel " + String (getChannel()); + if (isAllNotesOff()) return "All notes off Channel " + String (getChannel()); + if (isAllSoundOff()) return "All sound off Channel " + String (getChannel()); + if (isMetaEvent()) return "Meta event"; + + if (isController()) + { + String name (MidiMessage::getControllerName (getControllerNumber())); + + if (name.isEmpty()) + name = String (getControllerNumber()); + + return "Controller " + name + ": " + String (getControllerValue()) + " Channel " + String (getChannel()); + } + + return String::toHexString (getRawData(), getRawDataSize()); +} + int MidiMessage::getChannel() const noexcept { const uint8* const data = getRawData(); diff --git a/modules/juce_audio_basics/midi/juce_MidiMessage.h b/modules/juce_audio_basics/midi/juce_MidiMessage.h index 61e084b73b..10fd0b2090 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessage.h +++ b/modules/juce_audio_basics/midi/juce_MidiMessage.h @@ -125,6 +125,12 @@ public: */ int getRawDataSize() const noexcept { return size; } + //============================================================================== + /** Returns a human-readable description of the midi message as a string, + for example "Note On C#3 Velocity 120 Channel 1". + */ + String getDescription() const; + //============================================================================== /** Returns the timestamp associated with this message.