mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Changed the way isPositiveAndBelow is written to avoid needing to cast the second parameter to an int
This commit is contained in:
parent
5b8cf6b932
commit
27a6903cac
13 changed files with 45 additions and 49 deletions
|
|
@ -137,7 +137,7 @@ void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacing<fl
|
|||
// The fast tanh can be used instead of std::tanh to reduce the CPU load
|
||||
auto waveshaperIndex = waveshaperParam->getIndex();
|
||||
|
||||
if (isPositiveAndBelow (waveshaperIndex, (int) numWaveShapers) )
|
||||
if (isPositiveAndBelow (waveshaperIndex, numWaveShapers) )
|
||||
{
|
||||
waveShapers[waveshaperIndex].process (waveshaperContext);
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ private:
|
|||
|
||||
if (selectedNumChannels != bus->getLastEnabledLayout().size())
|
||||
{
|
||||
if (isPositiveAndBelow (selectedNumChannels, (int) AudioChannelSet::maxChannelsOfNamedLayout)
|
||||
if (isPositiveAndBelow (selectedNumChannels, AudioChannelSet::maxChannelsOfNamedLayout)
|
||||
&& bus->setCurrentLayoutWithoutEnabling (bus->supportedLayoutWithChannels (selectedNumChannels)))
|
||||
{
|
||||
if (auto* config = owner.getConfig (! isInput))
|
||||
|
|
|
|||
|
|
@ -44,24 +44,24 @@ bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const noex
|
|||
{
|
||||
jassert (midiChannel >= 0 && midiChannel <= 16);
|
||||
|
||||
return isPositiveAndBelow (n, (int) 128)
|
||||
return isPositiveAndBelow (n, 128)
|
||||
&& (noteStates[n] & (1 << (midiChannel - 1))) != 0;
|
||||
}
|
||||
|
||||
bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const noexcept
|
||||
{
|
||||
return isPositiveAndBelow (n, (int) 128)
|
||||
return isPositiveAndBelow (n, 128)
|
||||
&& (noteStates[n] & midiChannelMask) != 0;
|
||||
}
|
||||
|
||||
void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
|
||||
{
|
||||
jassert (midiChannel >= 0 && midiChannel <= 16);
|
||||
jassert (isPositiveAndBelow (midiNoteNumber, (int) 128));
|
||||
jassert (isPositiveAndBelow (midiNoteNumber, 128));
|
||||
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
if (isPositiveAndBelow (midiNoteNumber, (int) 128))
|
||||
if (isPositiveAndBelow (midiNoteNumber, 128))
|
||||
{
|
||||
const int timeNow = (int) Time::getMillisecondCounter();
|
||||
eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
|
||||
|
|
@ -73,7 +73,7 @@ void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber,
|
|||
|
||||
void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
|
||||
{
|
||||
if (isPositiveAndBelow (midiNoteNumber, (int) 128))
|
||||
if (isPositiveAndBelow (midiNoteNumber, 128))
|
||||
{
|
||||
noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
|
||||
|
||||
|
|
|
|||
|
|
@ -452,8 +452,8 @@ MidiMessage MidiMessage::aftertouchChange (const int channel,
|
|||
const int aftertouchValue) noexcept
|
||||
{
|
||||
jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
|
||||
jassert (isPositiveAndBelow (noteNum, (int) 128));
|
||||
jassert (isPositiveAndBelow (aftertouchValue, (int) 128));
|
||||
jassert (isPositiveAndBelow (noteNum, 128));
|
||||
jassert (isPositiveAndBelow (aftertouchValue, 128));
|
||||
|
||||
return MidiMessage (MidiHelpers::initialByte (0xa0, channel),
|
||||
noteNum & 0x7f,
|
||||
|
|
@ -474,7 +474,7 @@ int MidiMessage::getChannelPressureValue() const noexcept
|
|||
MidiMessage MidiMessage::channelPressureChange (const int channel, const int pressure) noexcept
|
||||
{
|
||||
jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
|
||||
jassert (isPositiveAndBelow (pressure, (int) 128));
|
||||
jassert (isPositiveAndBelow (pressure, 128));
|
||||
|
||||
return MidiMessage (MidiHelpers::initialByte (0xd0, channel), pressure & 0x7f);
|
||||
}
|
||||
|
|
@ -522,7 +522,7 @@ int MidiMessage::getPitchWheelValue() const noexcept
|
|||
MidiMessage MidiMessage::pitchWheel (const int channel, const int position) noexcept
|
||||
{
|
||||
jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
|
||||
jassert (isPositiveAndBelow (position, (int) 0x4000));
|
||||
jassert (isPositiveAndBelow (position, 0x4000));
|
||||
|
||||
return MidiMessage (MidiHelpers::initialByte (0xe0, channel),
|
||||
position & 127, (position >> 7) & 127);
|
||||
|
|
@ -563,7 +563,7 @@ MidiMessage MidiMessage::controllerEvent (const int channel, const int controlle
|
|||
MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const uint8 velocity) noexcept
|
||||
{
|
||||
jassert (channel > 0 && channel <= 16);
|
||||
jassert (isPositiveAndBelow (noteNumber, (int) 128));
|
||||
jassert (isPositiveAndBelow (noteNumber, 128));
|
||||
|
||||
return MidiMessage (MidiHelpers::initialByte (0x90, channel),
|
||||
noteNumber & 127, MidiHelpers::validVelocity (velocity));
|
||||
|
|
@ -577,7 +577,7 @@ MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const
|
|||
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, uint8 velocity) noexcept
|
||||
{
|
||||
jassert (channel > 0 && channel <= 16);
|
||||
jassert (isPositiveAndBelow (noteNumber, (int) 128));
|
||||
jassert (isPositiveAndBelow (noteNumber, 128));
|
||||
|
||||
return MidiMessage (MidiHelpers::initialByte (0x80, channel),
|
||||
noteNumber & 127, MidiHelpers::validVelocity (velocity));
|
||||
|
|
@ -591,7 +591,7 @@ MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, float
|
|||
MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber) noexcept
|
||||
{
|
||||
jassert (channel > 0 && channel <= 16);
|
||||
jassert (isPositiveAndBelow (noteNumber, (int) 128));
|
||||
jassert (isPositiveAndBelow (noteNumber, 128));
|
||||
|
||||
return MidiMessage (MidiHelpers::initialByte (0x80, channel), noteNumber & 127, 0);
|
||||
}
|
||||
|
|
@ -983,7 +983,7 @@ String MidiMessage::getMidiNoteName (int note, bool useSharps, bool includeOctav
|
|||
static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
|
||||
static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" };
|
||||
|
||||
if (isPositiveAndBelow (note, (int) 128))
|
||||
if (isPositiveAndBelow (note, 128))
|
||||
{
|
||||
String s (useSharps ? sharpNoteNames [note % 12]
|
||||
: flatNoteNames [note % 12]);
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ MidiOutput* MidiOutput::openDevice (int index)
|
|||
{
|
||||
MidiOutput* mo = nullptr;
|
||||
|
||||
if (isPositiveAndBelow (index, (int) MIDIGetNumberOfDestinations()))
|
||||
if (isPositiveAndBelow (index, MIDIGetNumberOfDestinations()))
|
||||
{
|
||||
MIDIEndpointRef endPoint = MIDIGetDestination ((ItemCount) index);
|
||||
|
||||
|
|
@ -465,7 +465,7 @@ MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
|
|||
using namespace CoreMidiHelpers;
|
||||
MidiInput* newInput = nullptr;
|
||||
|
||||
if (isPositiveAndBelow (index, (int) MIDIGetNumberOfSources()))
|
||||
if (isPositiveAndBelow (index, MIDIGetNumberOfSources()))
|
||||
{
|
||||
if (MIDIEndpointRef endPoint = MIDIGetSource ((ItemCount) index))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1704,7 +1704,7 @@ private:
|
|||
|
||||
for (MidiBuffer::Iterator i (midiEvents); i.getNextEvent (midiEventData, midiEventSize, midiEventPosition);)
|
||||
{
|
||||
jassert (isPositiveAndBelow (midiEventPosition, (int) nFrames));
|
||||
jassert (isPositiveAndBelow (midiEventPosition, nFrames));
|
||||
ignoreUnused (nFrames);
|
||||
|
||||
dataSize += (size_t) midiEventSize;
|
||||
|
|
|
|||
|
|
@ -943,7 +943,7 @@ struct VSTPluginInstance : public AudioPluginInstance,
|
|||
|
||||
float getParameter (int index) override
|
||||
{
|
||||
if (vstEffect != nullptr && isPositiveAndBelow (index, (int) vstEffect->numParameters))
|
||||
if (vstEffect != nullptr && isPositiveAndBelow (index, vstEffect->numParameters))
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
return vstEffect->getParameterValueFunction (vstEffect, index);
|
||||
|
|
@ -954,7 +954,7 @@ struct VSTPluginInstance : public AudioPluginInstance,
|
|||
|
||||
void setParameter (int index, float newValue) override
|
||||
{
|
||||
if (vstEffect != nullptr && isPositiveAndBelow (index, (int) vstEffect->numParameters))
|
||||
if (vstEffect != nullptr && isPositiveAndBelow (index, vstEffect->numParameters))
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
|
|
|
|||
|
|
@ -212,9 +212,9 @@ void findMinAndMax (const Type* values, int numValues, Type& lowest, Type& highe
|
|||
@see jmin, jmax, jmap
|
||||
*/
|
||||
template <typename Type>
|
||||
Type jlimit (const Type lowerLimit,
|
||||
const Type upperLimit,
|
||||
const Type valueToConstrain) noexcept
|
||||
Type jlimit (Type lowerLimit,
|
||||
Type upperLimit,
|
||||
Type valueToConstrain) noexcept
|
||||
{
|
||||
jassert (lowerLimit <= upperLimit); // if these are in the wrong order, results are unpredictable..
|
||||
|
||||
|
|
@ -228,15 +228,15 @@ Type jlimit (const Type lowerLimit,
|
|||
@code valueToTest >= 0 && valueToTest < upperLimit
|
||||
@endcode
|
||||
*/
|
||||
template <typename Type>
|
||||
bool isPositiveAndBelow (Type valueToTest, Type upperLimit) noexcept
|
||||
template <typename Type1, typename Type2>
|
||||
bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit) noexcept
|
||||
{
|
||||
jassert (Type() <= upperLimit); // makes no sense to call this if the upper limit is itself below zero..
|
||||
return Type() <= valueToTest && valueToTest < upperLimit;
|
||||
jassert (Type1() <= static_cast<Type1> (upperLimit)); // makes no sense to call this if the upper limit is itself below zero..
|
||||
return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noexcept
|
||||
template <typename Type>
|
||||
bool isPositiveAndBelow (int valueToTest, Type upperLimit) noexcept
|
||||
{
|
||||
jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero..
|
||||
return static_cast<unsigned int> (valueToTest) < static_cast<unsigned int> (upperLimit);
|
||||
|
|
@ -247,27 +247,23 @@ inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noe
|
|||
@code valueToTest >= 0 && valueToTest <= upperLimit
|
||||
@endcode
|
||||
*/
|
||||
template <typename Type>
|
||||
bool isPositiveAndNotGreaterThan (Type valueToTest, Type upperLimit) noexcept
|
||||
template <typename Type1, typename Type2>
|
||||
bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit) noexcept
|
||||
{
|
||||
jassert (Type() <= upperLimit); // makes no sense to call this if the upper limit is itself below zero..
|
||||
return Type() <= valueToTest && valueToTest <= upperLimit;
|
||||
jassert (Type1() <= static_cast<Type1> (upperLimit)); // makes no sense to call this if the upper limit is itself below zero..
|
||||
return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperLimit) noexcept
|
||||
template <typename Type>
|
||||
bool isPositiveAndNotGreaterThan (int valueToTest, Type upperLimit) noexcept
|
||||
{
|
||||
jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero..
|
||||
return static_cast<unsigned int> (valueToTest) <= static_cast<unsigned int> (upperLimit);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Handy function to swap two values. */
|
||||
template <typename Type>
|
||||
void swapVariables (Type& variable1, Type& variable2)
|
||||
{
|
||||
std::swap (variable1, variable2);
|
||||
}
|
||||
/** @deprecated Just use std::swap instead! */
|
||||
JUCE_DEPRECATED_WITH_BODY (template <typename Type> void swapVariables (Type& variable1, Type& variable2), { std::swap (variable1, variable2); })
|
||||
|
||||
/** Handy function for avoiding unused variables warning. */
|
||||
template <typename Type1>
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, con
|
|||
// Check that you're not trying to add the same character twice..
|
||||
jassert (findGlyph (character, false) == nullptr);
|
||||
|
||||
if (isPositiveAndBelow ((int) character, (int) numElementsInArray (lookupTable)))
|
||||
if (isPositiveAndBelow ((int) character, numElementsInArray (lookupTable)))
|
||||
lookupTable [character] = (short) glyphs.size();
|
||||
|
||||
glyphs.add (new GlyphInfo (character, path, width));
|
||||
|
|
@ -205,7 +205,7 @@ void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar ch
|
|||
|
||||
CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) noexcept
|
||||
{
|
||||
if (isPositiveAndBelow ((int) character, (int) numElementsInArray (lookupTable)) && lookupTable [character] > 0)
|
||||
if (isPositiveAndBelow ((int) character, numElementsInArray (lookupTable)) && lookupTable [character] > 0)
|
||||
return glyphs [(int) lookupTable [(int) character]];
|
||||
|
||||
for (int i = 0; i < glyphs.size(); ++i)
|
||||
|
|
|
|||
|
|
@ -572,7 +572,7 @@ void EdgeTable::intersectWithEdgeTableLine (const int y, const int* const otherL
|
|||
lastX = nextX;
|
||||
|
||||
const int nextLevel = (level1 * (level2 + 1)) >> 8;
|
||||
jassert (isPositiveAndBelow (nextLevel, (int) 256));
|
||||
jassert (isPositiveAndBelow (nextLevel, 256));
|
||||
|
||||
if (nextLevel != lastLevel)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public:
|
|||
while (--numPoints >= 0)
|
||||
{
|
||||
const int level = *++line;
|
||||
jassert (isPositiveAndBelow (level, (int) 256));
|
||||
jassert (isPositiveAndBelow (level, 256));
|
||||
const int endX = *++line;
|
||||
jassert (endX >= x);
|
||||
const int endOfRun = (endX >> 8);
|
||||
|
|
|
|||
|
|
@ -392,8 +392,8 @@ public:
|
|||
{
|
||||
NSRect viewFrame = [view frame];
|
||||
|
||||
if (! (isPositiveAndBelow (localPos.getX(), (int) viewFrame.size.width)
|
||||
&& isPositiveAndBelow (localPos.getY(), (int) viewFrame.size.height)))
|
||||
if (! (isPositiveAndBelow (localPos.getX(), viewFrame.size.width)
|
||||
&& isPositiveAndBelow (localPos.getY(), viewFrame.size.height)))
|
||||
return false;
|
||||
|
||||
if (! SystemStats::isRunningInAppExtensionSandbox())
|
||||
|
|
|
|||
|
|
@ -1179,8 +1179,8 @@ public:
|
|||
{
|
||||
auto r = getWindowRect (hwnd);
|
||||
|
||||
if (! (isPositiveAndBelow (localPos.x, (int) (r.right - r.left))
|
||||
&& isPositiveAndBelow (localPos.y, (int) (r.bottom - r.top))))
|
||||
if (! (isPositiveAndBelow (localPos.x, r.right - r.left)
|
||||
&& isPositiveAndBelow (localPos.y, r.bottom - r.top)))
|
||||
return false;
|
||||
|
||||
POINT p = { localPos.x + r.left + windowBorder.getLeft(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue