diff --git a/include/BasicFilters.h b/include/BasicFilters.h index 684596c4d..c3a76d36e 100644 --- a/include/BasicFilters.h +++ b/include/BasicFilters.h @@ -39,7 +39,6 @@ #include #include "lmms_basics.h" -#include "templates.h" #include "lmms_constants.h" #include "interpolation.h" #include "MemoryManager.h" diff --git a/include/Controller.h b/include/Controller.h index d4fb94731..f1e71ad8f 100644 --- a/include/Controller.h +++ b/include/Controller.h @@ -31,7 +31,6 @@ #include "Engine.h" #include "Model.h" #include "JournallingObject.h" -#include "templates.h" #include "ValueBuffer.h" class ControllerDialog; @@ -112,7 +111,7 @@ public: inline static float fittedValue( float _val ) { - return tLimit( _val, 0.0f, 1.0f ); + return qBound( 0.0f, _val, 1.0f ); } static long runningPeriods() diff --git a/include/DspEffectLibrary.h b/include/DspEffectLibrary.h index 76296da0b..bf175df6d 100644 --- a/include/DspEffectLibrary.h +++ b/include/DspEffectLibrary.h @@ -27,7 +27,6 @@ #define DSP_EFFECT_LIBRARY_H #include "lmms_math.h" -#include "templates.h" #include "lmms_constants.h" #include "lmms_basics.h" diff --git a/include/Knob.h b/include/Knob.h index 245963ce2..b8d460f45 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -30,7 +30,6 @@ #include #include "AutomatableModelView.h" -#include "templates.h" class QPixmap; diff --git a/include/panning.h b/include/panning.h index 5f10433ce..8668ddf88 100644 --- a/include/panning.h +++ b/include/panning.h @@ -28,7 +28,6 @@ #include "lmms_basics.h" #include "volume.h" -#include "templates.h" #include "panning_constants.h" #include "Midi.h" diff --git a/include/templates.h b/include/templates.h deleted file mode 100644 index 50a14a6b8..000000000 --- a/include/templates.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * templates.h - miscellanous templates and algorithms - * - * Copyright (c) 2004-2008 Tobias Doerffel - * - * This file is part of LMMS - https://lmms.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program (see COPYING); if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - */ - - -#ifndef TEMPLATES_H -#define TEMPLATES_H - -#include - - -template -inline T tLimit( const T x, const T x1, const T x2 ) -{ - return qBound( x1, x, x2 ); -} - - -#endif diff --git a/plugins/bit_invader/bit_invader.cpp b/plugins/bit_invader/bit_invader.cpp index 9b0b63635..0d62bc2e6 100644 --- a/plugins/bit_invader/bit_invader.cpp +++ b/plugins/bit_invader/bit_invader.cpp @@ -36,7 +36,6 @@ #include "NotePlayHandle.h" #include "Oscillator.h" #include "PixmapButton.h" -#include "templates.h" #include "ToolTip.h" #include "Song.h" #include "interpolation.h" diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index e556e42bf..91e811276 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -41,7 +41,6 @@ #include "NotePlayHandle.h" #include "Oscillator.h" #include "PixmapButton.h" -#include "templates.h" #include "ToolTip.h" #include "BandLimitedWave.h" diff --git a/plugins/monstro/Monstro.cpp b/plugins/monstro/Monstro.cpp index fb089aa0c..4ea679347 100644 --- a/plugins/monstro/Monstro.cpp +++ b/plugins/monstro/Monstro.cpp @@ -28,7 +28,6 @@ #include "Monstro.h" #include "Engine.h" #include "InstrumentTrack.h" -#include "templates.h" #include "gui_templates.h" #include "ToolTip.h" #include "Song.h" diff --git a/plugins/nes/Nes.cpp b/plugins/nes/Nes.cpp index c44f01bad..b973f4356 100644 --- a/plugins/nes/Nes.cpp +++ b/plugins/nes/Nes.cpp @@ -27,7 +27,6 @@ #include "Nes.h" #include "Engine.h" #include "InstrumentTrack.h" -#include "templates.h" #include "ToolTip.h" #include "Song.h" #include "lmms_math.h" diff --git a/plugins/organic/organic.cpp b/plugins/organic/organic.cpp index 63aee0dc6..de5f08ff7 100644 --- a/plugins/organic/organic.cpp +++ b/plugins/organic/organic.cpp @@ -37,7 +37,6 @@ #include "NotePlayHandle.h" #include "Oscillator.h" #include "PixmapButton.h" -#include "templates.h" #include "ToolTip.h" #include "embed.h" diff --git a/plugins/sfxr/sfxr.cpp b/plugins/sfxr/sfxr.cpp index 2718d66d7..cdace1a30 100644 --- a/plugins/sfxr/sfxr.cpp +++ b/plugins/sfxr/sfxr.cpp @@ -45,7 +45,6 @@ float frnd(float range) #include "Knob.h" #include "NotePlayHandle.h" #include "PixmapButton.h" -#include "templates.h" #include "ToolTip.h" #include "Song.h" #include "MidiEvent.h" diff --git a/plugins/vibed/vibed.cpp b/plugins/vibed/vibed.cpp index bde5c8917..94f640ff3 100644 --- a/plugins/vibed/vibed.cpp +++ b/plugins/vibed/vibed.cpp @@ -35,7 +35,6 @@ #include "CaptionMenu.h" #include "Oscillator.h" #include "string_container.h" -#include "templates.h" #include "volume.h" #include "Song.h" diff --git a/plugins/vibed/vibrating_string.cpp b/plugins/vibed/vibrating_string.cpp index c32202717..14a666bbd 100644 --- a/plugins/vibed/vibrating_string.cpp +++ b/plugins/vibed/vibrating_string.cpp @@ -24,7 +24,6 @@ #include #include "vibrating_string.h" -#include "templates.h" #include "interpolation.h" #include "Mixer.h" #include "Engine.h" @@ -145,9 +144,9 @@ void vibratingString::resample( float *_src, f_cnt_t _src_frames, _dst_frames; const float frac_pos = src_frame_float - static_cast( src_frame_float ); - const f_cnt_t src_frame = tLimit( - static_cast( src_frame_float ), - 1, _src_frames - 3 ); + const f_cnt_t src_frame = qBound( + 1, static_cast( src_frame_float ), + _src_frames - 3 ); m_impulse[frame] = cubicInterpolate( _src[src_frame - 1], _src[src_frame + 0], diff --git a/plugins/vst_base/VstPlugin.cpp b/plugins/vst_base/VstPlugin.cpp index f224f092d..8d86f576f 100644 --- a/plugins/vst_base/VstPlugin.cpp +++ b/plugins/vst_base/VstPlugin.cpp @@ -60,7 +60,6 @@ #include "MainWindow.h" #include "Mixer.h" #include "Song.h" -#include "templates.h" #include "FileDialog.h" #ifdef LMMS_BUILD_LINUX diff --git a/plugins/watsyn/Watsyn.cpp b/plugins/watsyn/Watsyn.cpp index 2787e39b7..5c47b7a7a 100644 --- a/plugins/watsyn/Watsyn.cpp +++ b/plugins/watsyn/Watsyn.cpp @@ -28,7 +28,6 @@ #include "base64.h" #include "Engine.h" #include "InstrumentTrack.h" -#include "templates.h" #include "ToolTip.h" #include "Song.h" #include "lmms_math.h" diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 9b52ce8fe..6055598f7 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -439,7 +439,7 @@ void AutomatableModel::setStep( const float step ) float AutomatableModel::fittedValue( float value ) const { - value = tLimit( value, m_minValue, m_maxValue ); + value = qBound( m_minValue, value, m_maxValue ); if( m_step != 0 && m_hasStrictStepSize ) { diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index 47f432a8f..779592529 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -936,7 +936,7 @@ void SampleBuffer::visualize( QPainter & _p, const QRect & _dr, const float y_space = h*0.5f; const int nb_frames = focus_on_range ? _to_frame - _from_frame : m_frames; - const int fpp = tLimit( nb_frames / w, 1, 20 ); + const int fpp = qBound( 1, nb_frames / w, 20 ); QPointF * l = new QPointF[nb_frames / fpp + 1]; QPointF * r = new QPointF[nb_frames / fpp + 1]; int n = 0; diff --git a/src/core/audio/AudioAlsa.cpp b/src/core/audio/AudioAlsa.cpp index 45abe6776..b86675706 100644 --- a/src/core/audio/AudioAlsa.cpp +++ b/src/core/audio/AudioAlsa.cpp @@ -37,10 +37,10 @@ AudioAlsa::AudioAlsa( bool & _success_ful, Mixer* _mixer ) : - AudioDevice( tLimit( + AudioDevice( qBound( + DEFAULT_CHANNELS, ConfigManager::inst()->value( "audioalsa", "channels" ).toInt(), - DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ), + SURROUND_CHANNELS ), _mixer ), m_handle( NULL ), m_hwParams( NULL ), m_swParams( NULL ), diff --git a/src/core/audio/AudioJack.cpp b/src/core/audio/AudioJack.cpp index bca41356b..e149f5cbd 100644 --- a/src/core/audio/AudioJack.cpp +++ b/src/core/audio/AudioJack.cpp @@ -32,7 +32,6 @@ #include "Engine.h" #include "GuiApplication.h" -#include "templates.h" #include "gui_templates.h" #include "ConfigManager.h" #include "LcdSpinBox.h" @@ -44,10 +43,10 @@ AudioJack::AudioJack( bool & _success_ful, Mixer* _mixer ) : - AudioDevice( tLimit( ConfigManager::inst()->value( - "audiojack", "channels" ).toInt(), - DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ), + AudioDevice( qBound( + DEFAULT_CHANNELS, + ConfigManager::inst()->value( "audiojack", "channels" ).toInt(), + SURROUND_CHANNELS ), _mixer ), m_client( NULL ), m_active( false ), m_midiClient( NULL ), diff --git a/src/core/audio/AudioOss.cpp b/src/core/audio/AudioOss.cpp index 21f495dca..c9ad01801 100644 --- a/src/core/audio/AudioOss.cpp +++ b/src/core/audio/AudioOss.cpp @@ -69,10 +69,10 @@ AudioOss::AudioOss( bool & _success_ful, Mixer* _mixer ) : - AudioDevice( tLimit( + AudioDevice( qBound( + DEFAULT_CHANNELS, ConfigManager::inst()->value( "audiooss", "channels" ).toInt(), - DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ), + SURROUND_CHANNELS ), _mixer ), m_convertEndian( false ) { _success_ful = false; diff --git a/src/core/audio/AudioPortAudio.cpp b/src/core/audio/AudioPortAudio.cpp index 5566d7a36..61dca4a22 100644 --- a/src/core/audio/AudioPortAudio.cpp +++ b/src/core/audio/AudioPortAudio.cpp @@ -48,16 +48,15 @@ void AudioPortAudioSetupUtil::updateChannels() #include "Engine.h" #include "ConfigManager.h" #include "gui_templates.h" -#include "templates.h" #include "ComboBox.h" #include "Mixer.h" AudioPortAudio::AudioPortAudio( bool & _success_ful, Mixer * _mixer ) : - AudioDevice( tLimit( + AudioDevice( qBound( + DEFAULT_CHANNELS, ConfigManager::inst()->value( "audioportaudio", "channels" ).toInt(), - DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ), + SURROUND_CHANNELS ), _mixer ), m_paStream( NULL ), m_wasPAInitError( false ), m_outBuf( new surroundSampleFrame[mixer()->framesPerPeriod()] ), diff --git a/src/core/audio/AudioPulseAudio.cpp b/src/core/audio/AudioPulseAudio.cpp index 20a106ed1..050086c60 100644 --- a/src/core/audio/AudioPulseAudio.cpp +++ b/src/core/audio/AudioPulseAudio.cpp @@ -45,10 +45,10 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) AudioPulseAudio::AudioPulseAudio( bool & _success_ful, Mixer* _mixer ) : - AudioDevice( tLimit( + AudioDevice( qBound( + DEFAULT_CHANNELS, ConfigManager::inst()->value( "audiopa", "channels" ).toInt(), - DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ), + SURROUND_CHANNELS ), _mixer ), m_s( NULL ), m_quit( false ), m_convertEndian( false ) diff --git a/src/core/audio/AudioSndio.cpp b/src/core/audio/AudioSndio.cpp index 3145eb218..853d734d5 100644 --- a/src/core/audio/AudioSndio.cpp +++ b/src/core/audio/AudioSndio.cpp @@ -36,7 +36,6 @@ #include "Mixer.h" #include "Engine.h" #include "gui_templates.h" -#include "templates.h" #ifdef LMMS_HAVE_UNISTD_H #include @@ -50,10 +49,11 @@ AudioSndio::AudioSndio(bool & _success_ful, Mixer * _mixer) : - AudioDevice( tLimit( - ConfigManager::inst()->value( "audiosndio", "channels" ).toInt(), - DEFAULT_CHANNELS, SURROUND_CHANNELS ), _mixer ), - m_convertEndian ( false ) + AudioDevice( qBound( + DEFAULT_CHANNELS, + ConfigManager::inst()->value( "audiosndio", "channels" ).toInt(), + SURROUND_CHANNELS ), _mixer ), + m_convertEndian ( false ) { _success_ful = false; diff --git a/src/core/audio/AudioSoundIo.cpp b/src/core/audio/AudioSoundIo.cpp index f6c624127..cde14a1c5 100644 --- a/src/core/audio/AudioSoundIo.cpp +++ b/src/core/audio/AudioSoundIo.cpp @@ -33,14 +33,14 @@ #include "debug.h" #include "ConfigManager.h" #include "gui_templates.h" -#include "templates.h" #include "ComboBox.h" #include "Mixer.h" AudioSoundIo::AudioSoundIo( bool & outSuccessful, Mixer * _mixer ) : - AudioDevice( tLimit( - ConfigManager::inst()->value( "audiosoundio", "channels" ).toInt(), DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ) + AudioDevice( qBound( + DEFAULT_CHANNELS, + ConfigManager::inst()->value( "audiosoundio", "channels" ).toInt(), + SURROUND_CHANNELS ), _mixer ) { outSuccessful = false; m_soundio = NULL; diff --git a/src/gui/PianoView.cpp b/src/gui/PianoView.cpp index 6e8464dd4..c1be922c6 100644 --- a/src/gui/PianoView.cpp +++ b/src/gui/PianoView.cpp @@ -355,7 +355,7 @@ int PianoView::getKeyFromMouse( const QPoint & _p ) const } // some range-checking-stuff - return tLimit( key_num, 0, NumKeys - 1 ); + return qBound( 0, key_num, NumKeys - 1 ); } diff --git a/src/gui/PluginBrowser.cpp b/src/gui/PluginBrowser.cpp index 1e73b7cdc..671b58381 100644 --- a/src/gui/PluginBrowser.cpp +++ b/src/gui/PluginBrowser.cpp @@ -34,7 +34,6 @@ #include "embed.h" #include "Engine.h" -#include "templates.h" #include "gui_templates.h" #include "StringPairDrag.h" #include "PluginFactory.h" @@ -231,7 +230,7 @@ void PluginDescWidget::paintEvent( QPaintEvent * ) style()->drawPrimitive( QStyle::PE_Widget, &o, &p, this ); // Draw the rest - const int s = 16 + ( 32 * ( tLimit( height(), 24, 60 ) - 24 ) ) / + const int s = 16 + ( 32 * ( qBound( 24, height(), 60 ) - 24 ) ) / ( 60 - 24 ); const QSize logo_size( s, s ); QPixmap logo = m_logo.scaled( logo_size, Qt::KeepAspectRatio, diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 440da2595..5edc5d47c 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -709,7 +709,7 @@ void PianoRoll::setCurrentPattern( Pattern* newPattern ) { central_key = central_key / total_notes - ( KeysPerOctave * NumOctaves - m_totalKeysToScroll ) / 2; - m_startKey = tLimit( central_key, 0, NumOctaves * KeysPerOctave ); + m_startKey = qBound( 0, central_key, NumOctaves * KeysPerOctave ); } // resizeEvent() does the rest for us (scrolling, range-checking @@ -2215,9 +2215,9 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) else if( m_action == ActionResizeNoteEditArea ) { // change m_notesEditHeight and then repaint - m_notesEditHeight = tLimit( - m_oldNotesEditHeight - ( me->y() - m_moveStartY ), + m_notesEditHeight = qBound( NOTE_EDIT_MIN_HEIGHT, + m_oldNotesEditHeight - ( me->y() - m_moveStartY ), height() - PR_TOP_MARGIN - NOTE_EDIT_RESIZE_BAR - PR_BOTTOM_MARGIN - KEY_AREA_MIN_HEIGHT ); @@ -2299,16 +2299,18 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) if( me->buttons() & Qt::LeftButton ) { - vol = tLimit( MinVolume + + vol = qBound( MinVolume, + MinVolume + ( ( (float)noteEditBottom() ) - ( (float)me->y() ) ) / ( (float)( noteEditBottom() - noteEditTop() ) ) * ( MaxVolume - MinVolume ), - MinVolume, MaxVolume ); - pan = tLimit( PanningLeft + + MaxVolume ); + pan = qBound( PanningLeft, + PanningLeft + ( (float)( noteEditBottom() - me->y() ) ) / ( (float)( noteEditBottom() - noteEditTop() ) ) * ( (float)( PanningRight - PanningLeft ) ), - PanningLeft, PanningRight); + PanningRight); } if( m_noteEditMode == NoteEditVolume ) @@ -3513,7 +3515,7 @@ void PianoRoll::wheelEvent(QWheelEvent * we ) { for ( Note * n : nv ) { - volume_t vol = tLimit( n->getVolume() + step, MinVolume, MaxVolume ); + volume_t vol = qBound( MinVolume, n->getVolume() + step, MaxVolume ); n->setVolume( vol ); } bool allVolumesEqual = std::all_of( nv.begin(), nv.end(), @@ -3532,7 +3534,7 @@ void PianoRoll::wheelEvent(QWheelEvent * we ) { for ( Note * n : nv ) { - panning_t pan = tLimit( n->getPanning() + step, PanningLeft, PanningRight ); + panning_t pan = qBound( PanningLeft, n->getPanning() + step, PanningRight ); n->setPanning( pan ); } bool allPansEqual = std::all_of( nv.begin(), nv.end(), diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index a7809a077..093632831 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -592,7 +592,7 @@ int InstrumentTrack::masterKey( int _midi_key ) const { int key = baseNote(); - return tLimit( _midi_key - ( key - DefaultKey ), 0, NumKeys ); + return qBound( 0, _midi_key - ( key - DefaultKey ), NumKeys ); }