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

MidiMessage: moved two useful helper functions into the public interface; minor cleanup of some member function declarations.

This commit is contained in:
Timur Doumler 2016-05-25 15:54:07 +01:00
parent 968cee4ad2
commit 07bc151ce3
2 changed files with 28 additions and 10 deletions

View file

@ -33,11 +33,22 @@ namespace MidiHelpers
{
return (uint8) jlimit (0, 127, v);
}
}
inline uint8 floatVelocityToByte (const float v) noexcept
{
return validVelocity (roundToInt (v * 127.0f));
}
//==============================================================================
uint8 MidiMessage::floatValueToMidiByte (const float v) noexcept
{
return MidiHelpers::validVelocity (roundToInt (v * 127.0f));
}
uint16 MidiMessage::pitchbendToPitchwheelPos (const float pitchbend,
const float pitchbendRange) noexcept
{
// can't translate a pitchbend value that is outside of the given range!
jassert (std::abs (pitchbend) <= pitchbendRange);
return pitchbend > 0.0f ? jmap (pitchbend, 0.0f, pitchbendRange, 8192.0f, 16383.0f)
: jmap (pitchbend, -pitchbendRange, 0.0f, 0.0f, 8192.0f);
}
//==============================================================================
@ -416,7 +427,7 @@ float MidiMessage::getFloatVelocity() const noexcept
void MidiMessage::setVelocity (const float newVelocity) noexcept
{
if (isNoteOnOrOff())
getData()[2] = MidiHelpers::floatVelocityToByte (newVelocity);
getData()[2] = floatValueToMidiByte (newVelocity);
}
void MidiMessage::multiplyVelocity (const float scaleFactor) noexcept
@ -563,7 +574,7 @@ MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const
MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const float velocity) noexcept
{
return noteOn (channel, noteNumber, MidiHelpers::floatVelocityToByte (velocity));
return noteOn (channel, noteNumber, floatValueToMidiByte (velocity));
}
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, uint8 velocity) noexcept
@ -577,7 +588,7 @@ MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, uint8
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, float velocity) noexcept
{
return noteOff (channel, noteNumber, MidiHelpers::floatVelocityToByte (velocity));
return noteOff (channel, noteNumber, floatValueToMidiByte (velocity));
}
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber) noexcept
@ -1010,7 +1021,7 @@ String MidiMessage::getMidiNoteName (int note, bool useSharps, bool includeOctav
return String();
}
double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOfA) noexcept
double MidiMessage::getMidiNoteInHertz (const int noteNumber, const double frequencyOfA) noexcept
{
return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0);
}