1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added new helper function MidiMessage::getDescription(), replacing some code that was previously in the Juce Demo.

This commit is contained in:
Timur Doumler 2016-03-02 16:53:23 +00:00
parent 5854829fcf
commit 497f286b53
3 changed files with 32 additions and 27 deletions

View file

@ -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<int> (width, height).reduced (4, 0),
Justification::centredLeft, true);
}

View file

@ -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();

View file

@ -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.