Browse Source

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

tags/2021-05-28
Timur Doumler 9 years ago
parent
commit
497f286b53
3 changed files with 32 additions and 27 deletions
  1. +1
    -27
      examples/Demo/Source/Demos/MidiDemo.cpp
  2. +25
    -0
      modules/juce_audio_basics/midi/juce_MidiMessage.cpp
  3. +6
    -0
      modules/juce_audio_basics/midi/juce_MidiMessage.h

+ 1
- 27
examples/Demo/Source/Demos/MidiDemo.cpp View File

@@ -24,32 +24,6 @@
#include "../JuceDemoHeader.h" #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. */ /** Simple list box that just displays a StringArray. */
class MidiLogListBoxModel : public ListBoxModel class MidiLogListBoxModel : public ListBoxModel
{ {
@@ -77,7 +51,7 @@ public:
((int) (time / 3600.0)) % 24, ((int) (time / 3600.0)) % 24,
((int) (time / 60.0)) % 60, ((int) (time / 60.0)) % 60,
((int) time) % 60) ((int) time) % 60)
+ " - " + getMidiMessageDescription (message),
+ " - " + message.getDescription(),
Rectangle<int> (width, height).reduced (4, 0), Rectangle<int> (width, height).reduced (4, 0),
Justification::centredLeft, true); Justification::centredLeft, true);
} }


+ 25
- 0
modules/juce_audio_basics/midi/juce_MidiMessage.cpp View File

@@ -309,6 +309,31 @@ uint8* MidiMessage::allocateSpace (int bytes)
return preallocatedData.asBytes; 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 int MidiMessage::getChannel() const noexcept
{ {
const uint8* const data = getRawData(); const uint8* const data = getRawData();


+ 6
- 0
modules/juce_audio_basics/midi/juce_MidiMessage.h View File

@@ -125,6 +125,12 @@ public:
*/ */
int getRawDataSize() const noexcept { return size; } 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. /** Returns the timestamp associated with this message.


Loading…
Cancel
Save