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

Added a MidiMessage::noteOff method that takes a float velocity parameter.

This commit is contained in:
jules 2015-09-14 20:03:42 +01:00
parent 2877653cc3
commit 3f8b213525
2 changed files with 42 additions and 7 deletions

View file

@ -33,6 +33,11 @@ namespace MidiHelpers
{
return (uint8) jlimit (0, 127, v);
}
inline uint8 floatVelocityToByte (const float v) noexcept
{
return validVelocity (roundToInt (v * 127.0f));
}
}
//==============================================================================
@ -386,7 +391,7 @@ float MidiMessage::getFloatVelocity() const noexcept
void MidiMessage::setVelocity (const float newVelocity) noexcept
{
if (isNoteOnOrOff())
getData()[2] = MidiHelpers::validVelocity (roundToInt (newVelocity * 127.0f));
getData()[2] = MidiHelpers::floatVelocityToByte (newVelocity);
}
void MidiMessage::multiplyVelocity (const float scaleFactor) noexcept
@ -522,11 +527,6 @@ MidiMessage MidiMessage::controllerEvent (const int channel, const int controlle
controllerType & 127, value & 127);
}
MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const float velocity) noexcept
{
return noteOn (channel, noteNumber, (uint8) (velocity * 127.0f + 0.5f));
}
MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const uint8 velocity) noexcept
{
jassert (channel > 0 && channel <= 16);
@ -536,6 +536,11 @@ MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const
noteNumber & 127, MidiHelpers::validVelocity (velocity));
}
MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const float velocity) noexcept
{
return noteOn (channel, noteNumber, MidiHelpers::floatVelocityToByte (velocity));
}
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, uint8 velocity) noexcept
{
jassert (channel > 0 && channel <= 16);
@ -545,6 +550,19 @@ MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, uint8
noteNumber & 127, MidiHelpers::validVelocity (velocity));
}
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, float velocity) noexcept
{
return noteOff (channel, noteNumber, MidiHelpers::floatVelocityToByte (velocity));
}
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber) noexcept
{
jassert (channel > 0 && channel <= 16);
jassert (isPositiveAndBelow (noteNumber, (int) 128));
return MidiMessage (MidiHelpers::initialByte (0x80, channel), noteNumber & 127, 0);
}
MidiMessage MidiMessage::allNotesOff (const int channel) noexcept
{
return controllerEvent (channel, 123, 0);