diff --git a/examples/DSP module plugin demo/Source/PluginProcessor.cpp b/examples/DSP module plugin demo/Source/PluginProcessor.cpp index 389776a3c8..b05febfd4c 100644 --- a/examples/DSP module plugin demo/Source/PluginProcessor.cpp +++ b/examples/DSP module plugin demo/Source/PluginProcessor.cpp @@ -137,7 +137,7 @@ void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacinggetIndex(); - if (isPositiveAndBelow (waveshaperIndex, (int) numWaveShapers) ) + if (isPositiveAndBelow (waveshaperIndex, numWaveShapers) ) { waveShapers[waveshaperIndex].process (waveshaperContext); diff --git a/examples/audio plugin host/Source/FilterIOConfiguration.cpp b/examples/audio plugin host/Source/FilterIOConfiguration.cpp index eb77a538ed..cd465f7eb9 100644 --- a/examples/audio plugin host/Source/FilterIOConfiguration.cpp +++ b/examples/audio plugin host/Source/FilterIOConfiguration.cpp @@ -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)) diff --git a/modules/juce_audio_basics/midi/juce_MidiKeyboardState.cpp b/modules/juce_audio_basics/midi/juce_MidiKeyboardState.cpp index ad52ceb8fd..68b8db06be 100644 --- a/modules/juce_audio_basics/midi/juce_MidiKeyboardState.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiKeyboardState.cpp @@ -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)); diff --git a/modules/juce_audio_basics/midi/juce_MidiMessage.cpp b/modules/juce_audio_basics/midi/juce_MidiMessage.cpp index bf2eb56cd3..054981cae7 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessage.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiMessage.cpp @@ -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]); diff --git a/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp b/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp index cd98d478e6..9637792a76 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp @@ -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)) { diff --git a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm index 19b4ed209c..ce62442b92 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -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; diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp index 716b274016..172e348844 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp @@ -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); diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h index 7e6b348f8e..759b5c020d 100644 --- a/modules/juce_core/maths/juce_MathsFunctions.h +++ b/modules/juce_core/maths/juce_MathsFunctions.h @@ -212,9 +212,9 @@ void findMinAndMax (const Type* values, int numValues, Type& lowest, Type& highe @see jmin, jmax, jmap */ template -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 -bool isPositiveAndBelow (Type valueToTest, Type upperLimit) noexcept +template +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 (upperLimit)); // makes no sense to call this if the upper limit is itself below zero.. + return Type1() <= valueToTest && valueToTest < static_cast (upperLimit); } -template <> -inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noexcept +template +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 (valueToTest) < static_cast (upperLimit); @@ -247,27 +247,23 @@ inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noe @code valueToTest >= 0 && valueToTest <= upperLimit @endcode */ -template -bool isPositiveAndNotGreaterThan (Type valueToTest, Type upperLimit) noexcept +template +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 (upperLimit)); // makes no sense to call this if the upper limit is itself below zero.. + return Type1() <= valueToTest && valueToTest <= static_cast (upperLimit); } -template <> -inline bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperLimit) noexcept +template +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 (valueToTest) <= static_cast (upperLimit); } //============================================================================== -/** Handy function to swap two values. */ -template -void swapVariables (Type& variable1, Type& variable2) -{ - std::swap (variable1, variable2); -} +/** @deprecated Just use std::swap instead! */ +JUCE_DEPRECATED_WITH_BODY (template void swapVariables (Type& variable1, Type& variable2), { std::swap (variable1, variable2); }) /** Handy function for avoiding unused variables warning. */ template diff --git a/modules/juce_graphics/fonts/juce_CustomTypeface.cpp b/modules/juce_graphics/fonts/juce_CustomTypeface.cpp index acc1456aa6..5897a3753c 100644 --- a/modules/juce_graphics/fonts/juce_CustomTypeface.cpp +++ b/modules/juce_graphics/fonts/juce_CustomTypeface.cpp @@ -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) diff --git a/modules/juce_graphics/geometry/juce_EdgeTable.cpp b/modules/juce_graphics/geometry/juce_EdgeTable.cpp index 141613c844..bfcb7c7d96 100644 --- a/modules/juce_graphics/geometry/juce_EdgeTable.cpp +++ b/modules/juce_graphics/geometry/juce_EdgeTable.cpp @@ -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) { diff --git a/modules/juce_graphics/geometry/juce_EdgeTable.h b/modules/juce_graphics/geometry/juce_EdgeTable.h index 76c318ed1d..5311a894e2 100644 --- a/modules/juce_graphics/geometry/juce_EdgeTable.h +++ b/modules/juce_graphics/geometry/juce_EdgeTable.h @@ -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); diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 1102b0c6dc..d1b39752ff 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -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()) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index cb769925fd..45c81f45d6 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -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(),