diff --git a/include/AudioEngine.h b/include/AudioEngine.h index d0f269d87..dec8f2592 100644 --- a/include/AudioEngine.h +++ b/include/AudioEngine.h @@ -32,10 +32,10 @@ #endif #include -#include #include #include +#include #include "lmms_basics.h" #include "LocklessList.h" @@ -416,7 +416,7 @@ private: bool m_renderOnly; - QVector m_audioPorts; + std::vector m_audioPorts; fpp_t m_framesPerPeriod; @@ -430,7 +430,7 @@ private: surroundSampleFrame * m_outputBufferWrite; // worker thread stuff - QVector m_workers; + std::vector m_workers; int m_numWorkers; // playhandle stuff diff --git a/include/AudioEngineWorkerThread.h b/include/AudioEngineWorkerThread.h index 112930808..16de6ff6f 100644 --- a/include/AudioEngineWorkerThread.h +++ b/include/AudioEngineWorkerThread.h @@ -100,9 +100,9 @@ public: JobQueue::OperationMode _opMode = JobQueue::Static ) { resetJobQueue( _opMode ); - for( typename T::ConstIterator it = _vec.begin(); it != _vec.end(); ++it ) + for (const auto& job : _vec) { - addJob( *it ); + addJob(job); } } diff --git a/include/AudioJack.h b/include/AudioJack.h index 2ef0f665c..164258e5f 100644 --- a/include/AudioJack.h +++ b/include/AudioJack.h @@ -35,7 +35,7 @@ #endif #include -#include +#include #include "AudioDevice.h" #include "AudioDeviceSetupWidget.h" @@ -117,7 +117,7 @@ private: std::atomic m_stopped; std::atomic m_midiClient; - QVector m_outputPorts; + std::vector m_outputPorts; jack_default_audio_sample_t * * m_tempOutBufs; surroundSampleFrame * m_outBuf; diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index 1e6d5eda3..2b93a514c 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -78,7 +78,7 @@ class LMMS_EXPORT AutomatableModel : public Model, public JournallingObject Q_OBJECT MM_OPERATORS public: - using AutoModelVector = QVector; + using AutoModelVector = std::vector; enum ScaleType { diff --git a/include/AutomationClip.h b/include/AutomationClip.h index 10c714c3d..fc6a26d0e 100644 --- a/include/AutomationClip.h +++ b/include/AutomationClip.h @@ -62,7 +62,7 @@ public: } ; using timeMap = QMap; - using objectVector = QVector>; + using objectVector = std::vector>; using TimemapIterator = timeMap::const_iterator; @@ -167,7 +167,7 @@ public: static bool isAutomated( const AutomatableModel * _m ); - static QVector clipsForModel( const AutomatableModel * _m ); + static std::vector clipsForModel(const AutomatableModel* _m); static AutomationClip * globalAutomationClip( AutomatableModel * _m ); static void resolveAllIDs(); @@ -190,6 +190,15 @@ private: void generateTangents(timeMap::iterator it, int numToGenerate); float valueAt( timeMap::const_iterator v, int offset ) const; + /** + * @brief + * This function combines the song tracks, pattern store tracks, + * and the global automation track all in one vector. + * + * @return std::vector + */ + static std::vector combineAllTracks(); + // Mutex to make methods involving automation clips thread safe // Mutable so we can lock it from const objects #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) @@ -199,7 +208,7 @@ private: #endif AutomationTrack * m_autoTrack; - QVector m_idsToResolve; + std::vector m_idsToResolve; objectVector m_objects; timeMap m_timeMap; // actual values timeMap m_oldTimeMap; // old values for storing the values before setDragValue() is called. diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index c2ab98092..a1c4d694f 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -27,6 +27,7 @@ #define LMMS_GUI_AUTOMATION_EDITOR_H #include +#include #include "Editor.h" @@ -180,7 +181,7 @@ private: ComboBoxModel m_zoomingYModel; ComboBoxModel m_quantizeModel; - static const QVector m_zoomXLevels; + static const std::array m_zoomXLevels; FloatModel * m_tensionModel; diff --git a/include/ConfigManager.h b/include/ConfigManager.h index eee069681..f6239c297 100644 --- a/include/ConfigManager.h +++ b/include/ConfigManager.h @@ -30,9 +30,9 @@ #include #include #include -#include #include +#include #include "lmms_export.h" @@ -239,11 +239,8 @@ public: void addRecentlyOpenedProject(const QString & _file); - const QString & value(const QString & cls, - const QString & attribute) const; - const QString & value(const QString & cls, - const QString & attribute, - const QString & defaultVal) const; + QString value(const QString& cls, const QString& attribute, const QString& defaultVal = "") const; + void setValue(const QString & cls, const QString & attribute, const QString & value); void deleteValue(const QString & cls, const QString & attribute); @@ -302,7 +299,7 @@ private: unsigned int m_configVersion; QStringList m_recentlyOpenedProjects; - using stringPairVector = QVector>; + using stringPairVector = std::vector>; using settingsMap = QMap; settingsMap m_settings; diff --git a/include/Controller.h b/include/Controller.h index 0a5eb0f36..b176b1f74 100644 --- a/include/Controller.h +++ b/include/Controller.h @@ -45,7 +45,7 @@ class ControllerDialog; } // namespace gui -using ControllerVector = QVector; +using ControllerVector = std::vector; class LMMS_EXPORT Controller : public Model, public JournallingObject { diff --git a/include/ControllerConnection.h b/include/ControllerConnection.h index 4473b68e0..b60687123 100644 --- a/include/ControllerConnection.h +++ b/include/ControllerConnection.h @@ -30,12 +30,13 @@ #define LMMS_CONTROLLER_CONNECTION_H #include -#include #include "Controller.h" #include "JournallingObject.h" #include "ValueBuffer.h" +#include + namespace lmms { @@ -46,7 +47,7 @@ namespace gui class ControllerConnectionDialog; } -using ControllerConnectionVector = QVector; +using ControllerConnectionVector = std::vector; class LMMS_EXPORT ControllerConnection : public QObject, public JournallingObject { diff --git a/include/EffectChain.h b/include/EffectChain.h index 57cf8d547..f9482174e 100644 --- a/include/EffectChain.h +++ b/include/EffectChain.h @@ -69,7 +69,7 @@ public: private: - using EffectList = QVector; + using EffectList = std::vector; EffectList m_effects; BoolModel m_enabledModel; diff --git a/include/EnvelopeAndLfoParameters.h b/include/EnvelopeAndLfoParameters.h index a713a90f3..02abd07e3 100644 --- a/include/EnvelopeAndLfoParameters.h +++ b/include/EnvelopeAndLfoParameters.h @@ -25,7 +25,7 @@ #ifndef LMMS_ENVELOPE_AND_LFO_PARAMETERS_H #define LMMS_ENVELOPE_AND_LFO_PARAMETERS_H -#include +#include #include "JournallingObject.h" #include "AutomatableModel.h" diff --git a/include/InstrumentFunctions.h b/include/InstrumentFunctions.h index f62b74e9a..61d625d83 100644 --- a/include/InstrumentFunctions.h +++ b/include/InstrumentFunctions.h @@ -119,7 +119,7 @@ public: }; - struct ChordTable : public QVector + struct ChordTable { private: ChordTable(); @@ -131,6 +131,7 @@ public: }; static std::array s_initTable; + std::vector m_chords; public: static const ChordTable & getInstance() @@ -150,6 +151,11 @@ public: { return getByName( name, false ); } + + const std::vector& chords() const + { + return m_chords; + } }; diff --git a/include/MidiClient.h b/include/MidiClient.h index 3a64f709c..1eb04402b 100644 --- a/include/MidiClient.h +++ b/include/MidiClient.h @@ -26,7 +26,7 @@ #define LMMS_MIDI_CLIENT_H #include -#include +#include #include "MidiEvent.h" @@ -111,7 +111,7 @@ public: static MidiClient * openMidiClient(); protected: - QVector m_midiPorts; + std::vector m_midiPorts; } ; diff --git a/include/Mixer.h b/include/Mixer.h index 6589836c4..35787a414 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -39,7 +39,7 @@ namespace lmms class MixerRoute; -using MixerRouteVector = QVector; +using MixerRouteVector = std::vector; class MixerChannel : public ThreadableJob { @@ -219,7 +219,7 @@ public: private: // the mixer channels in the mixer. index 0 is always master. - QVector m_mixerChannels; + std::vector m_mixerChannels; // make sure we have at least num channels void allocateChannelsTo(int num); diff --git a/include/Note.h b/include/Note.h index 15aeaa2ce..dd261b3af 100644 --- a/include/Note.h +++ b/include/Note.h @@ -27,7 +27,7 @@ #define LMMS_NOTE_H #include -#include +#include #include "volume.h" #include "panning.h" @@ -249,7 +249,7 @@ private: DetuningHelper * m_detuning; }; -using NoteVector = QVector; +using NoteVector = std::vector; struct NoteBounds { diff --git a/include/PeakController.h b/include/PeakController.h index 357e2a95d..de9da3b1c 100644 --- a/include/PeakController.h +++ b/include/PeakController.h @@ -36,7 +36,7 @@ namespace lmms class PeakControllerEffect; -using PeakControllerEffectVector = QVector; +using PeakControllerEffectVector = std::vector; class LMMS_EXPORT PeakController : public Controller { diff --git a/include/PianoRoll.h b/include/PianoRoll.h index 6100792d5..03b93d816 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -27,9 +27,10 @@ #ifndef LMMS_GUI_PIANO_ROLL_H #define LMMS_GUI_PIANO_ROLL_H -#include #include +#include + #include "Editor.h" #include "ComboBoxModel.h" #include "SerializingObject.h" @@ -291,7 +292,7 @@ private: PositionLine * m_positionLine; - QVector m_nemStr; // gui names of each edit mode + std::vector m_nemStr; // gui names of each edit mode QMenu * m_noteEditMenu; // when you right click below the key area QList m_markedSemiTones; @@ -358,8 +359,8 @@ private: ComboBoxModel m_chordModel; ComboBoxModel m_snapModel; - static const QVector m_zoomLevels; - static const QVector m_zoomYLevels; + static const std::vector m_zoomLevels; + static const std::vector m_zoomYLevels; MidiClip* m_midiClip; NoteVector m_ghostNotes; diff --git a/include/PluginFactory.h b/include/PluginFactory.h index 001ea190a..10c76e4ee 100644 --- a/include/PluginFactory.h +++ b/include/PluginFactory.h @@ -27,12 +27,12 @@ #include #include +#include #include #include #include #include -#include #include "lmms_export.h" #include "Plugin.h" @@ -99,7 +99,7 @@ private: PluginInfoList m_pluginInfos; QMap m_pluginByExt; - QVector m_garbage; //!< cleaned up at destruction + std::vector m_garbage; //!< cleaned up at destruction QHash m_errors; diff --git a/include/RenderManager.h b/include/RenderManager.h index 5240e96a8..43f696f14 100644 --- a/include/RenderManager.h +++ b/include/RenderManager.h @@ -78,8 +78,8 @@ private: std::unique_ptr m_activeRenderer; - QVector m_tracksToRender; - QVector m_unmuted; + std::vector m_tracksToRender; + std::vector m_unmuted; } ; diff --git a/include/StepRecorder.h b/include/StepRecorder.h index 456e69a69..55435617c 100644 --- a/include/StepRecorder.h +++ b/include/StepRecorder.h @@ -59,7 +59,7 @@ class StepRecorder : public QObject void setCurrentMidiClip(MidiClip* newMidiClip); void setStepsLength(const TimePos& newLength); - QVector getCurStepNotes(); + std::vector getCurStepNotes(); bool isRecording() const { @@ -142,7 +142,7 @@ class StepRecorder : public QObject QElapsedTimer releasedTimer; } ; - QVector m_curStepNotes; // contains the current recorded step notes (i.e. while user still press the notes; before they are applied to the clip) + std::vector m_curStepNotes; // contains the current recorded step notes (i.e. while user still press the notes; before they are applied to the clip) StepNote* findCurStepNote(const int key); diff --git a/include/Track.h b/include/Track.h index ff3c1ae00..000d564f7 100644 --- a/include/Track.h +++ b/include/Track.h @@ -25,7 +25,8 @@ #ifndef LMMS_TRACK_H #define LMMS_TRACK_H -#include +#include + #include #include "AutomatableModel.h" @@ -69,7 +70,7 @@ class LMMS_EXPORT Track : public Model, public JournallingObject mapPropertyFromModel(bool,isMuted,setMuted,m_mutedModel); mapPropertyFromModel(bool,isSolo,setSolo,m_soloModel); public: - using clipVector = QVector; + using clipVector = std::vector; enum TrackTypes { diff --git a/include/TrackContainer.h b/include/TrackContainer.h index f99273ba2..8739a9e9f 100644 --- a/include/TrackContainer.h +++ b/include/TrackContainer.h @@ -49,7 +49,7 @@ class LMMS_EXPORT TrackContainer : public Model, public JournallingObject { Q_OBJECT public: - using TrackList = QVector; + using TrackList = std::vector; enum TrackContainerTypes { PatternContainer, diff --git a/include/panning.h b/include/panning.h index 56ca04eee..0fd74d1cc 100644 --- a/include/panning.h +++ b/include/panning.h @@ -31,6 +31,8 @@ #include "Midi.h" #include "volume.h" +#include + namespace lmms { @@ -40,7 +42,7 @@ inline StereoVolumeVector panningToVolumeVector( panning_t _p, { StereoVolumeVector v = { { _scale, _scale } }; const float pf = _p / 100.0f; - v.vol[_p >= PanningCenter ? 0 : 1] *= 1.0f - qAbs( pf ); + v.vol[_p >= PanningCenter ? 0 : 1] *= 1.0f - std::abs(pf); return v; } diff --git a/plugins/PeakControllerEffect/PeakControllerEffect.cpp b/plugins/PeakControllerEffect/PeakControllerEffect.cpp index d32a22320..bd99631b7 100644 --- a/plugins/PeakControllerEffect/PeakControllerEffect.cpp +++ b/plugins/PeakControllerEffect/PeakControllerEffect.cpp @@ -76,7 +76,7 @@ PeakControllerEffect::PeakControllerEffect( { Engine::getSong()->addController( m_autoController ); } - PeakController::s_effects.append( this ); + PeakController::s_effects.push_back(this); } @@ -84,11 +84,11 @@ PeakControllerEffect::PeakControllerEffect( PeakControllerEffect::~PeakControllerEffect() { - int idx = PeakController::s_effects.indexOf( this ); - if( idx >= 0 ) + auto it = std::find(PeakController::s_effects.begin(), PeakController::s_effects.end(), this); + if (it != PeakController::s_effects.end()) { - PeakController::s_effects.remove( idx ); - Engine::getSong()->removeController( m_autoController ); + PeakController::s_effects.erase(it); + Engine::getSong()->removeController(m_autoController); } } diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index a91e88f38..91a16ed12 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -419,7 +419,7 @@ const surroundSampleFrame * AudioEngine::renderNextBuffer() } // STAGE 2: process effects of all instrument- and sampletracks - AudioEngineWorkerThread::fillJobQueue >( m_audioPorts ); + AudioEngineWorkerThread::fillJobQueue(m_audioPorts); AudioEngineWorkerThread::startAndWaitForJobs(); @@ -663,7 +663,7 @@ void AudioEngine::removeAudioPort(AudioPort * port) { requestChangeInModel(); - QVector::Iterator it = std::find(m_audioPorts.begin(), m_audioPorts.end(), port); + auto it = std::find(m_audioPorts.begin(), m_audioPorts.end(), port); if (it != m_audioPorts.end()) { m_audioPorts.erase(it); diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 378ccd91e..fa4697c69 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -71,7 +71,7 @@ AutomatableModel::~AutomatableModel() { while( m_linkedModels.empty() == false ) { - m_linkedModels.last()->unlinkModel( this ); + m_linkedModels.back()->unlinkModel(this); m_linkedModels.erase( m_linkedModels.end() - 1 ); } @@ -473,7 +473,8 @@ float AutomatableModel::fittedValue( float value ) const void AutomatableModel::linkModel( AutomatableModel* model ) { - if( !m_linkedModels.contains( model ) && model != this ) + auto containsModel = std::find(m_linkedModels.begin(), m_linkedModels.end(), model) != m_linkedModels.end(); + if (!containsModel && model != this) { m_linkedModels.push_back( model ); @@ -490,7 +491,7 @@ void AutomatableModel::linkModel( AutomatableModel* model ) void AutomatableModel::unlinkModel( AutomatableModel* model ) { - AutoModelVector::Iterator it = std::find( m_linkedModels.begin(), m_linkedModels.end(), model ); + auto it = std::find(m_linkedModels.begin(), m_linkedModels.end(), model); if( it != m_linkedModels.end() ) { m_linkedModels.erase( it ); @@ -504,7 +505,8 @@ void AutomatableModel::unlinkModel( AutomatableModel* model ) void AutomatableModel::linkModels( AutomatableModel* model1, AutomatableModel* model2 ) { - if (!model1->m_linkedModels.contains( model2 ) && model1 != model2) + auto model1ContainsModel2 = std::find(model1->m_linkedModels.begin(), model1->m_linkedModels.end(), model2) != model1->m_linkedModels.end(); + if (!model1ContainsModel2 && model1 != model2) { // copy data model1->m_value = model2->m_value; @@ -588,7 +590,7 @@ float AutomatableModel::controllerValue( int frameOffset ) const return v; } - AutomatableModel* lm = m_linkedModels.first(); + AutomatableModel* lm = m_linkedModels.front(); if (lm->controllerConnection() && lm->useControllerValue()) { return fittedValue( lm->controllerValue( frameOffset ) ); @@ -649,7 +651,7 @@ ValueBuffer * AutomatableModel::valueBuffer() AutomatableModel* lm = nullptr; if (hasLinkedModels()) { - lm = m_linkedModels.first(); + lm = m_linkedModels.front(); } if (lm && lm->controllerConnection() && lm->useControllerValue() && lm->controllerConnection()->getController()->isSampleExact()) @@ -721,8 +723,8 @@ void AutomatableModel::reset() float AutomatableModel::globalAutomationValueAt( const TimePos& time ) { // get clips that connect to this model - QVector clips = AutomationClip::clipsForModel( this ); - if( clips.isEmpty() ) + auto clips = AutomationClip::clipsForModel(this); + if (clips.empty()) { // if no such clips exist, return current value return m_value; @@ -731,17 +733,17 @@ float AutomatableModel::globalAutomationValueAt( const TimePos& time ) { // of those clips: // find the clips which overlap with the time position - QVector clipsInRange; + std::vector clipsInRange; for (const auto& clip : clips) { int s = clip->startPosition(); int e = clip->endPosition(); - if (s <= time && e >= time) { clipsInRange += clip; } + if (s <= time && e >= time) { clipsInRange.push_back(clip); } } AutomationClip * latestClip = nullptr; - if( ! clipsInRange.isEmpty() ) + if (!clipsInRange.empty()) { // if there are more than one overlapping clips, just use the first one because // multiple clip behaviour is undefined anyway diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index c031c5a41..7a161c355 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -120,19 +120,19 @@ bool AutomationClip::addObject( AutomatableModel * _obj, bool _search_dup ) { QMutexLocker m(&m_clipMutex); - if( _search_dup && m_objects.contains(_obj) ) + if (_search_dup && std::find(m_objects.begin(), m_objects.end(), _obj) != m_objects.end()) { return false; } // the automation track is unconnected and there is nothing in the track - if( m_objects.isEmpty() && hasAutomation() == false ) + if (m_objects.empty() && hasAutomation() == false) { // then initialize first value putValue( TimePos(0), _obj->inverseScaledValue( _obj->value() ), false ); } - m_objects += _obj; + m_objects.push_back(_obj); connect( _obj, SIGNAL(destroyed(lmms::jo_id_t)), this, SLOT(objectDestroyed(lmms::jo_id_t)), @@ -184,7 +184,7 @@ const AutomatableModel * AutomationClip::firstObject() const QMutexLocker m(&m_clipMutex); AutomatableModel* model; - if (!m_objects.isEmpty() && (model = m_objects.first()) != nullptr) + if (!m_objects.empty() && (model = m_objects.front()) != nullptr) { return model; } @@ -380,11 +380,11 @@ void AutomationClip::removeNodes(const int tick0, const int tick1) // Make a list of TimePos with nodes to be removed // because we can't simply remove the nodes from // the timeMap while we are iterating it. - QVector nodesToRemove; + std::vector nodesToRemove; for (auto it = m_timeMap.lowerBound(start), endIt = m_timeMap.upperBound(end); it != endIt; ++it) { - nodesToRemove.append(POS(it)); + nodesToRemove.push_back(POS(it)); } for (auto node: nodesToRemove) @@ -831,7 +831,7 @@ void AutomationClip::loadSettings( const QDomElement & _this ) } else if( element.tagName() == "object" ) { - m_idsToResolve << element.attribute( "id" ).toInt(); + m_idsToResolve.push_back(element.attribute("id").toInt()); } } @@ -865,9 +865,9 @@ QString AutomationClip::name() const { return Clip::name(); } - if( !m_objects.isEmpty() && m_objects.first() != nullptr ) + if (!m_objects.empty() && m_objects.front() != nullptr) { - return m_objects.first()->fullDisplayName(); + return m_objects.front()->fullDisplayName(); } return tr( "Drag a control while pressing <%1>" ).arg(UI_CTRL_KEY); } @@ -888,12 +888,8 @@ gui::ClipView * AutomationClip::createView( gui::TrackView * _tv ) bool AutomationClip::isAutomated( const AutomatableModel * _m ) { - TrackContainer::TrackList l; - l += Engine::getSong()->tracks(); - l += Engine::patternStore()->tracks(); - l += Engine::getSong()->globalAutomationTrack(); - - for (const auto& track : l) + auto l = combineAllTracks(); + for (const auto track : l) { if (track->type() == Track::AutomationTrack || track->type() == Track::HiddenAutomationTrack) { @@ -921,16 +917,13 @@ bool AutomationClip::isAutomated( const AutomatableModel * _m ) * @brief returns a list of all the automation clips that are connected to a specific model * @param _m the model we want to look for */ -QVector AutomationClip::clipsForModel( const AutomatableModel * _m ) +std::vector AutomationClip::clipsForModel(const AutomatableModel* _m) { - QVector clips; - TrackContainer::TrackList tracks; - tracks += Engine::getSong()->tracks(); - tracks += Engine::patternStore()->tracks(); - tracks += Engine::getSong()->globalAutomationTrack(); + std::vector clips; + auto l = combineAllTracks(); // go through all tracks... - for (const auto& track : tracks) + for (const auto track : l) { // we want only automation tracks... if (track->type() == Track::AutomationTrack || track->type() == Track::HiddenAutomationTrack ) @@ -953,7 +946,7 @@ QVector AutomationClip::clipsForModel( const AutomatableModel } } // if the clips is connected to the model, add it to the list - if( has_object ) { clips += a; } + if (has_object) { clips.push_back(a); } } } } @@ -989,9 +982,7 @@ AutomationClip * AutomationClip::globalAutomationClip( void AutomationClip::resolveAllIDs() { - TrackContainer::TrackList l = Engine::getSong()->tracks() + - Engine::patternStore()->tracks(); - l += Engine::getSong()->globalAutomationTrack(); + auto l = combineAllTracks(); for (const auto& track : l) { if (track->type() == Track::AutomationTrack || track->type() == Track::HiddenAutomationTrack) @@ -1060,10 +1051,9 @@ void AutomationClip::objectDestroyed( jo_id_t _id ) // when switching samplerate) and real deletions because in the latter // case we had to remove ourselves if we're the global automation // clip of the destroyed object - m_idsToResolve += _id; + m_idsToResolve.push_back(_id); - for( objectVector::Iterator objIt = m_objects.begin(); - objIt != m_objects.end(); objIt++ ) + for (auto objIt = m_objects.begin(); objIt != m_objects.end(); objIt++) { Q_ASSERT( !(*objIt).isNull() ); if( (*objIt)->id() == _id ) @@ -1173,4 +1163,18 @@ void AutomationClip::generateTangents(timeMap::iterator it, int numToGenerate) } } +std::vector AutomationClip::combineAllTracks() +{ + std::vector combinedTrackList; + + auto& songTracks = Engine::getSong()->tracks(); + auto& patternStoreTracks = Engine::patternStore()->tracks(); + + combinedTrackList.insert(combinedTrackList.end(), songTracks.begin(), songTracks.end()); + combinedTrackList.insert(combinedTrackList.end(), patternStoreTracks.begin(), patternStoreTracks.end()); + combinedTrackList.push_back(Engine::getSong()->globalAutomationTrack()); + + return combinedTrackList; +} + } // namespace lmms diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index bfe9e31f1..c647a27e6 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -334,10 +334,9 @@ void ConfigManager::addRecentlyOpenedProject(const QString & file) -const QString & ConfigManager::value(const QString & cls, - const QString & attribute) const +QString ConfigManager::value(const QString& cls, const QString& attribute, const QString& defaultVal) const { - if(m_settings.contains(cls)) + if (m_settings.find(cls) != m_settings.end()) { for (const auto& setting : m_settings[cls]) { @@ -347,18 +346,7 @@ const QString & ConfigManager::value(const QString & cls, } } } - static QString empty; - return empty; -} - - - -const QString & ConfigManager::value(const QString & cls, - const QString & attribute, - const QString & defaultVal) const -{ - const QString & val = value(cls, attribute); - return val.isEmpty() ? defaultVal : val; + return defaultVal; } diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index aee6481cc..e7031f20c 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -25,8 +25,8 @@ */ #include -#include +#include #include "AudioEngine.h" #include "ControllerConnection.h" @@ -40,7 +40,7 @@ namespace lmms long Controller::s_periods = 0; -QVector Controller::s_controllers; +std::vector Controller::s_controllers; @@ -55,7 +55,7 @@ Controller::Controller( ControllerTypes _type, Model * _parent, { if( _type != DummyController && _type != MidiController ) { - s_controllers.append( this ); + s_controllers.push_back(this); // Determine which name to use for ( uint i=s_controllers.size(); ; i++ ) { @@ -86,10 +86,10 @@ Controller::Controller( ControllerTypes _type, Model * _parent, Controller::~Controller() { - int idx = s_controllers.indexOf( this ); - if( idx >= 0 ) + auto it = std::find(s_controllers.begin(), s_controllers.end(), this); + if (it != s_controllers.end()) { - s_controllers.remove( idx ); + s_controllers.erase(it); } m_valueBuffer.clear(); diff --git a/src/core/ControllerConnection.cpp b/src/core/ControllerConnection.cpp index c65cd8ae9..a4477c563 100644 --- a/src/core/ControllerConnection.cpp +++ b/src/core/ControllerConnection.cpp @@ -53,7 +53,7 @@ ControllerConnection::ControllerConnection(Controller * _controller) : m_controller = Controller::create( Controller::DummyController, nullptr ); } - s_connections.append( this ); + s_connections.push_back(this); } @@ -64,7 +64,7 @@ ControllerConnection::ControllerConnection( int _controllerId ) : m_controllerId( _controllerId ), m_ownsController( false ) { - s_connections.append( this ); + s_connections.push_back(this); } @@ -76,7 +76,10 @@ ControllerConnection::~ControllerConnection() { m_controller->removeConnection( this ); } - s_connections.remove( s_connections.indexOf( this ) ); + + auto it = std::find(s_connections.begin(), s_connections.end(), this); + if (it != s_connections.end()) { s_connections.erase(it); }; + if( m_ownsController ) { delete m_controller; @@ -186,10 +189,12 @@ void ControllerConnection::saveSettings( QDomDocument & _doc, QDomElement & _thi } else { - int id = Engine::getSong()->controllers().indexOf( m_controller ); - if( id >= 0 ) + const auto& controllers = Engine::getSong()->controllers(); + const auto it = std::find(controllers.begin(), controllers.end(), m_controller); + if (it != controllers.end()) { - _this.setAttribute( "id", id ); + const int id = std::distance(controllers.begin(), it); + _this.setAttribute("id", id); } } } diff --git a/src/core/EffectChain.cpp b/src/core/EffectChain.cpp index 024ddab64..b07a7227b 100644 --- a/src/core/EffectChain.cpp +++ b/src/core/EffectChain.cpp @@ -56,7 +56,7 @@ EffectChain::~EffectChain() void EffectChain::saveSettings( QDomDocument & _doc, QDomElement & _this ) { m_enabledModel.saveSettings( _doc, _this, "enabled" ); - _this.setAttribute( "numofeffects", m_effects.count() ); + _this.setAttribute("numofeffects", static_cast(m_effects.size())); for( Effect* effect : m_effects) { @@ -121,7 +121,7 @@ void EffectChain::loadSettings( const QDomElement & _this ) void EffectChain::appendEffect( Effect * _effect ) { Engine::audioEngine()->requestChangeInModel(); - m_effects.append( _effect ); + m_effects.push_back(_effect); Engine::audioEngine()->doneChangeInModel(); m_enabledModel.setValue( true ); @@ -136,7 +136,7 @@ void EffectChain::removeEffect( Effect * _effect ) { Engine::audioEngine()->requestChangeInModel(); - Effect ** found = std::find( m_effects.begin(), m_effects.end(), _effect ); + auto found = std::find(m_effects.begin(), m_effects.end(), _effect); if( found == m_effects.end() ) { Engine::audioEngine()->doneChangeInModel(); @@ -146,7 +146,7 @@ void EffectChain::removeEffect( Effect * _effect ) Engine::audioEngine()->doneChangeInModel(); - if( m_effects.isEmpty() ) + if (m_effects.empty()) { m_enabledModel.setValue( false ); } @@ -159,10 +159,10 @@ void EffectChain::removeEffect( Effect * _effect ) void EffectChain::moveDown( Effect * _effect ) { - if( _effect != m_effects.last() ) + if (_effect != m_effects.back()) { - int i = m_effects.indexOf(_effect); - std::swap(m_effects[i + 1], m_effects[i]); + auto it = std::find(m_effects.begin(), m_effects.end(), _effect); + std::swap(*std::next(it), *it); } } @@ -171,10 +171,10 @@ void EffectChain::moveDown( Effect * _effect ) void EffectChain::moveUp( Effect * _effect ) { - if( _effect != m_effects.first() ) + if (_effect != m_effects.front()) { - int i = m_effects.indexOf(_effect); - std::swap(m_effects[i - 1], m_effects[i]); + auto it = std::find(m_effects.begin(), m_effects.end(), _effect); + std::swap(*std::prev(it), *it); } } @@ -228,9 +228,9 @@ void EffectChain::clear() Engine::audioEngine()->requestChangeInModel(); - while( m_effects.count() ) + while (m_effects.size()) { - Effect * e = m_effects[m_effects.count() - 1]; + auto e = m_effects[m_effects.size() - 1]; m_effects.pop_back(); delete e; } diff --git a/src/core/InstrumentFunctions.cpp b/src/core/InstrumentFunctions.cpp index 06e56666c..d2fea9dbd 100644 --- a/src/core/InstrumentFunctions.cpp +++ b/src/core/InstrumentFunctions.cpp @@ -177,12 +177,11 @@ bool InstrumentFunctionNoteStacking::Chord::hasSemiTone( int8_t semi_tone ) cons -InstrumentFunctionNoteStacking::ChordTable::ChordTable() : - QVector() +InstrumentFunctionNoteStacking::ChordTable::ChordTable() { for (const auto& chord : s_initTable) { - push_back(Chord(chord.m_name, chord.m_semiTones)); + m_chords.emplace_back(chord.m_name, chord.m_semiTones); } } @@ -191,10 +190,12 @@ InstrumentFunctionNoteStacking::ChordTable::ChordTable() : const InstrumentFunctionNoteStacking::Chord & InstrumentFunctionNoteStacking::ChordTable::getByName( const QString & name, bool is_scale ) const { - for( int i = 0; i < size(); i++ ) + for (const auto& chord : m_chords) { - if( at( i ).getName() == name && is_scale == at( i ).isScale() ) - return at( i ); + if (chord.getName() == name && is_scale == chord.isScale()) + { + return chord; + } } static Chord empty; @@ -211,9 +212,10 @@ InstrumentFunctionNoteStacking::InstrumentFunctionNoteStacking( Model * _parent m_chordRangeModel( 1.0f, 1.0f, 9.0f, 1.0f, this, tr( "Chord range" ) ) { const ChordTable & chord_table = ChordTable::getInstance(); - for( int i = 0; i < chord_table.size(); ++i ) + + for (const auto& chord : chord_table.chords()) { - m_chordsModel.addItem( chord_table[i].getName() ); + m_chordsModel.addItem(chord.getName()); } } @@ -244,10 +246,10 @@ void InstrumentFunctionNoteStacking::processNote( NotePlayHandle * _n ) const int sub_note_key_base = base_note_key + octave_cnt * KeysPerOctave; // process all notes in the chord - for( int i = 0; i < chord_table[selected_chord].size(); ++i ) + for( int i = 0; i < chord_table.chords()[selected_chord].size(); ++i ) { // add interval to sub-note-key - const int sub_note_key = sub_note_key_base + (int) chord_table[selected_chord][i]; + const int sub_note_key = sub_note_key_base + (int) chord_table.chords()[selected_chord][i]; // maybe we're out of range -> let's get outta // here! if( sub_note_key > NumKeys ) @@ -309,9 +311,9 @@ InstrumentFunctionArpeggio::InstrumentFunctionArpeggio( Model * _parent ) : m_arpModeModel( this, tr( "Arpeggio mode" ) ) { const InstrumentFunctionNoteStacking::ChordTable & chord_table = InstrumentFunctionNoteStacking::ChordTable::getInstance(); - for( int i = 0; i < chord_table.size(); ++i ) + for (auto& chord : chord_table.chords()) { - m_arpModel.addItem( chord_table[i].getName() ); + m_arpModel.addItem(chord.getName()); } m_arpDirectionModel.addItem( tr( "Up" ), std::make_unique( "arp_up" ) ); @@ -362,7 +364,7 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) } const InstrumentFunctionNoteStacking::ChordTable & chord_table = InstrumentFunctionNoteStacking::ChordTable::getInstance(); - const int cur_chord_size = chord_table[selected_arp].size(); + const int cur_chord_size = chord_table.chords()[selected_arp].size(); const int range = static_cast(cur_chord_size * m_arpRangeModel.value() * m_arpRepeatsModel.value()); const int total_range = range * cnphv.size(); @@ -485,7 +487,7 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) // now calculate final key for our arp-note const int sub_note_key = base_note_key + (cur_arp_idx / cur_chord_size ) * - KeysPerOctave + chord_table[selected_arp][cur_arp_idx % cur_chord_size]; + KeysPerOctave + chord_table.chords()[selected_arp][cur_arp_idx % cur_chord_size]; // range-checking if( sub_note_key >= NumKeys || diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index b2a9f9e3f..dba5c334e 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -201,9 +201,9 @@ Mixer::Mixer() : Mixer::~Mixer() { - while( ! m_mixerRoutes.isEmpty() ) + while (!m_mixerRoutes.empty()) { - deleteChannelSend( m_mixerRoutes.first() ); + deleteChannelSend(m_mixerRoutes.front()); } while( m_mixerChannels.size() ) { @@ -293,8 +293,11 @@ void Mixer::deleteChannel( int index ) // go through every instrument and adjust for the channel index change TrackContainer::TrackList tracks; - tracks += Engine::getSong()->tracks(); - tracks += Engine::patternStore()->tracks(); + + auto& songTracks = Engine::getSong()->tracks(); + auto& patternStoreTracks = Engine::patternStore()->tracks(); + tracks.insert(tracks.end(), songTracks.begin(), songTracks.end()); + tracks.insert(tracks.end(), patternStoreTracks.begin(), patternStoreTracks.end()); for( Track* t : tracks ) { @@ -335,13 +338,13 @@ void Mixer::deleteChannel( int index ) MixerChannel * ch = m_mixerChannels[index]; // delete all of this channel's sends and receives - while( ! ch->m_sends.isEmpty() ) + while (!ch->m_sends.empty()) { - deleteChannelSend( ch->m_sends.first() ); + deleteChannelSend(ch->m_sends.front()); } - while( ! ch->m_receives.isEmpty() ) + while (!ch->m_receives.empty()) { - deleteChannelSend( ch->m_receives.first() ); + deleteChannelSend(ch->m_receives.front()); } // if m_lastSoloed was our index, reset it @@ -350,7 +353,7 @@ void Mixer::deleteChannel( int index ) else if (m_lastSoloed > index) { --m_lastSoloed; } // actually delete the channel - m_mixerChannels.remove(index); + m_mixerChannels.erase(m_mixerChannels.begin() + index); delete ch; for( int i = index; i < m_mixerChannels.size(); ++i ) @@ -477,13 +480,13 @@ MixerRoute * Mixer::createRoute( MixerChannel * from, MixerChannel * to, float a auto route = new MixerRoute(from, to, amount); // add us to from's sends - from->m_sends.append( route ); + from->m_sends.push_back(route); // add us to to's receives - to->m_receives.append( route ); + to->m_receives.push_back(route); // add us to mixer's list - Engine::mixer()->m_mixerRoutes.append( route ); + Engine::mixer()->m_mixerRoutes.push_back(route); Engine::audioEngine()->doneChangeInModel(); return route; @@ -512,12 +515,22 @@ void Mixer::deleteChannelSend( mix_ch_t fromChannel, mix_ch_t toChannel ) void Mixer::deleteChannelSend( MixerRoute * route ) { Engine::audioEngine()->requestChangeInModel(); + + auto removeFromMixerRoute = [route](MixerRouteVector& routeVec) + { + auto it = std::find(routeVec.begin(), routeVec.end(), route); + if (it != routeVec.end()) { routeVec.erase(it); } + }; + // remove us from from's sends - route->sender()->m_sends.remove( route->sender()->m_sends.indexOf( route ) ); + removeFromMixerRoute(route->sender()->m_sends); + // remove us from to's receives - route->receiver()->m_receives.remove( route->receiver()->m_receives.indexOf( route ) ); + removeFromMixerRoute(route->receiver()->m_receives); + // remove us from mixer's list - Engine::mixer()->m_mixerRoutes.remove( Engine::mixer()->m_mixerRoutes.indexOf( route ) ); + removeFromMixerRoute(Engine::mixer()->m_mixerRoutes); + delete route; Engine::audioEngine()->doneChangeInModel(); } @@ -714,9 +727,9 @@ void Mixer::clearChannel(mix_ch_t index) if( index > 0) { // delete existing sends - while( ! ch->m_sends.isEmpty() ) + while (!ch->m_sends.empty()) { - deleteChannelSend( ch->m_sends.first() ); + deleteChannelSend(ch->m_sends.front()); } // add send to master @@ -724,9 +737,9 @@ void Mixer::clearChannel(mix_ch_t index) } // delete receives - while( ! ch->m_receives.isEmpty() ) + while (!ch->m_receives.empty()) { - deleteChannelSend( ch->m_receives.first() ); + deleteChannelSend(ch->m_receives.front()); } } @@ -835,15 +848,18 @@ void Mixer::validateChannelName( int index, int oldIndex ) bool Mixer::isChannelInUse(int index) { // check if the index mixer channel receives audio from any other channel - if (!m_mixerChannels[index]->m_receives.isEmpty()) + if (!m_mixerChannels[index]->m_receives.empty()) { return true; } // check if the destination mixer channel on any instrument or sample track is the index mixer channel TrackContainer::TrackList tracks; - tracks += Engine::getSong()->tracks(); - tracks += Engine::patternStore()->tracks(); + + auto& songTracks = Engine::getSong()->tracks(); + auto& patternStoreTracks = Engine::patternStore()->tracks(); + tracks.insert(tracks.end(), songTracks.begin(), songTracks.end()); + tracks.insert(tracks.end(), patternStoreTracks.begin(), patternStoreTracks.end()); for (const auto t : tracks) { diff --git a/src/core/PeakController.cpp b/src/core/PeakController.cpp index a9215325e..af0e7e69d 100644 --- a/src/core/PeakController.cpp +++ b/src/core/PeakController.cpp @@ -161,12 +161,11 @@ void PeakController::loadSettings( const QDomElement & _this ) effectId = m_loadCount++; } - PeakControllerEffectVector::Iterator i; - for( i = s_effects.begin(); i != s_effects.end(); ++i ) + for (const auto& effect : s_effects) { - if( (*i)->m_effectId == effectId ) + if (effect->m_effectId == effectId) { - m_peakEffect = *i; + m_peakEffect = effect; return; } } @@ -190,16 +189,14 @@ PeakController * PeakController::getControllerBySetting(const QDomElement & _thi { int effectId = _this.attribute( "effectId" ).toInt(); - PeakControllerEffectVector::Iterator i; - //Backward compatibility for bug in <= 0.4.15 . For >= 1.0.0 , //foundCount should always be 1 because m_effectId is initialized with rand() int foundCount = 0; if( m_buggedFile == false ) { - for( i = s_effects.begin(); i != s_effects.end(); ++i ) + for (const auto& effect : s_effects) { - if( (*i)->m_effectId == effectId ) + if (effect->m_effectId == effectId) { foundCount++; } @@ -208,9 +205,9 @@ PeakController * PeakController::getControllerBySetting(const QDomElement & _thi { m_buggedFile = true; int newEffectId = 0; - for( i = s_effects.begin(); i != s_effects.end(); ++i ) + for (const auto& effect : s_effects) { - (*i)->m_effectId = newEffectId++; + effect->m_effectId = newEffectId++; } QMessageBox msgBox; msgBox.setIcon( QMessageBox::Information ); @@ -231,11 +228,11 @@ PeakController * PeakController::getControllerBySetting(const QDomElement & _thi } m_getCount++; //NB: m_getCount should be increased even m_buggedFile is false - for( i = s_effects.begin(); i != s_effects.end(); ++i ) + for (const auto& effect : s_effects) { - if( (*i)->m_effectId == effectId ) + if (effect->m_effectId == effectId) { - return (*i)->controller(); + return effect->controller(); } } diff --git a/src/core/RenderManager.cpp b/src/core/RenderManager.cpp index 56b4ce9d7..8c031b970 100644 --- a/src/core/RenderManager.cpp +++ b/src/core/RenderManager.cpp @@ -69,7 +69,7 @@ void RenderManager::renderNextTrack() { m_activeRenderer.reset(); - if( m_tracksToRender.isEmpty() ) + if (m_tracksToRender.empty()) { // nothing left to render restoreMutedState(); @@ -169,7 +169,7 @@ void RenderManager::render(QString outputPath) // Unmute all tracks that were muted while rendering tracks void RenderManager::restoreMutedState() { - while( !m_unmuted.isEmpty() ) + while (!m_unmuted.empty()) { Track* restoreTrack = m_unmuted.back(); m_unmuted.pop_back(); diff --git a/src/core/Song.cpp b/src/core/Song.cpp index fef66f193..6f4c5212e 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -840,7 +840,9 @@ bpm_t Song::getTempo() AutomatedValueMap Song::automatedValuesAt(TimePos time, int clipNum) const { - return TrackContainer::automatedValuesFromTracks(TrackList{m_globalAutomationTrack} << tracks(), time, clipNum); + auto trackList = TrackList{m_globalAutomationTrack}; + trackList.insert(trackList.end(), tracks().begin(), tracks().end()); + return TrackContainer::automatedValuesFromTracks(trackList, time, clipNum); } @@ -1326,8 +1328,7 @@ void Song::restoreControllerStates( const QDomElement & element ) else { // Fix indices to ensure correct connections - m_controllers.append(Controller::create( - Controller::DummyController, this)); + m_controllers.push_back(Controller::create(Controller::DummyController, this)); } node = node.nextSibling(); @@ -1445,9 +1446,10 @@ void Song::setProjectFileName(QString const & projectFileName) void Song::addController( Controller * controller ) { - if( controller && !m_controllers.contains( controller ) ) + bool containsController = std::find(m_controllers.begin(), m_controllers.end(), controller) != m_controllers.end(); + if (controller && !containsController) { - m_controllers.append( controller ); + m_controllers.push_back(controller); emit controllerAdded( controller ); this->setModified(); @@ -1459,10 +1461,10 @@ void Song::addController( Controller * controller ) void Song::removeController( Controller * controller ) { - int index = m_controllers.indexOf( controller ); - if( index != -1 ) + auto it = std::find(m_controllers.begin(), m_controllers.end(), controller); + if (it != m_controllers.end()) { - m_controllers.remove( index ); + m_controllers.erase(it); emit controllerRemoved( controller ); delete controller; diff --git a/src/core/StepRecorder.cpp b/src/core/StepRecorder.cpp index e8f31f644..9c2a216ae 100644 --- a/src/core/StepRecorder.cpp +++ b/src/core/StepRecorder.cpp @@ -91,7 +91,7 @@ void StepRecorder::notePressed(const Note & n) StepNote* stepNote = findCurStepNote(n.key()); if(stepNote == nullptr) { - m_curStepNotes.append(new StepNote(Note(m_curStepLength, m_curStepStartPos, n.key(), n.getVolume(), n.getPanning()))); + m_curStepNotes.push_back(new StepNote(Note(m_curStepLength, m_curStepStartPos, n.key(), n.getVolume(), n.getPanning()))); m_pianoRoll.update(); } else if (stepNote->isReleased()) @@ -175,15 +175,15 @@ void StepRecorder::setStepsLength(const TimePos& newLength) updateWidget(); } -QVector StepRecorder::getCurStepNotes() +std::vector StepRecorder::getCurStepNotes() { - QVector notes; + std::vector notes; if(m_isStepInProgress) { - for(StepNote* stepNote: m_curStepNotes) + for (StepNote* stepNote: m_curStepNotes) { - notes.append(&stepNote->m_note); + notes.push_back(&stepNote->m_note); } } @@ -288,18 +288,13 @@ void StepRecorder::removeNotesReleasedForTooLong() int nextTimout = std::numeric_limits::max(); bool notesRemoved = false; - QMutableVectorIterator itr(m_curStepNotes); - while (itr.hasNext()) + for (const auto& stepNote : m_curStepNotes) { - StepNote* stepNote = itr.next(); - - if(stepNote->isReleased()) + if (stepNote->isReleased()) { const int timeSinceReleased = stepNote->timeSinceReleased(); // capture value to avoid wraparound when calculting nextTimout if (timeSinceReleased >= REMOVE_RELEASED_NOTE_TIME_THRESHOLD_MS) { - delete stepNote; - itr.remove(); notesRemoved = true; } else @@ -309,6 +304,17 @@ void StepRecorder::removeNotesReleasedForTooLong() } } + m_curStepNotes.erase(std::remove_if(m_curStepNotes.begin(), m_curStepNotes.end(), [](auto stepNote) + { + bool shouldRemove = stepNote->isReleased() && stepNote->timeSinceReleased() >= REMOVE_RELEASED_NOTE_TIME_THRESHOLD_MS; + if (shouldRemove) + { + delete stepNote; + } + + return shouldRemove; + }), m_curStepNotes.end()); + if(notesRemoved) { m_pianoRoll.update(); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 084f302f8..33b9c8ef3 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -84,9 +84,9 @@ Track::~Track() lock(); emit destroyedTrack(); - while( !m_clips.isEmpty() ) + while (!m_clips.empty()) { - delete m_clips.last(); + delete m_clips.back(); } m_trackContainer->removeTrack( this ); @@ -365,9 +365,9 @@ void Track::removeClip( Clip * clip ) /*! \brief Remove all Clips from this track */ void Track::deleteClips() { - while( ! m_clips.isEmpty() ) + while (!m_clips.empty()) { - delete m_clips.first(); + delete m_clips.front(); } } diff --git a/src/core/TrackContainer.cpp b/src/core/TrackContainer.cpp index 0347773ed..33c695f48 100644 --- a/src/core/TrackContainer.cpp +++ b/src/core/TrackContainer.cpp @@ -196,14 +196,14 @@ void TrackContainer::removeTrack( Track * _track ) // After checking that index != -1, we need to upgrade the lock to a write locker before changing m_tracks. // But since Qt offers no function to promote a read lock to a write lock, we must start with the write locker. QWriteLocker lockTracksAccess(&m_tracksMutex); - int index = m_tracks.indexOf( _track ); - if( index != -1 ) + auto it = std::find(m_tracks.begin(), m_tracks.end(), _track); + if (it != m_tracks.end()) { // If the track is solo, all other tracks are muted. Change this before removing the solo track: if (_track->isSolo()) { _track->setSolo(false); } - m_tracks.remove( index ); + m_tracks.erase(it); lockTracksAccess.unlock(); if( Engine::getSong() ) @@ -226,9 +226,9 @@ void TrackContainer::updateAfterTrackAdd() void TrackContainer::clearAllTracks() { //m_tracksMutex.lockForWrite(); - while( !m_tracks.isEmpty() ) + while (!m_tracks.empty()) { - delete m_tracks.first(); + delete m_tracks.front(); } //m_tracksMutex.unlock(); } @@ -240,7 +240,7 @@ bool TrackContainer::isEmpty() const { for (const auto& track : m_tracks) { - if (!track->getClips().isEmpty()) + if (!track->getClips().empty()) { return false; } @@ -275,7 +275,7 @@ AutomatedValueMap TrackContainer::automatedValuesFromTracks(const TrackList &tra track->getClipsInRange(clips, 0, time); } else { Q_ASSERT(track->numOfClips() > clipNum); - clips << track->getClip(clipNum); + clips.push_back(track->getClip(clipNum)); } default: break; diff --git a/src/core/midi/MidiClient.cpp b/src/core/midi/MidiClient.cpp index 78691de6f..030384c5e 100644 --- a/src/core/midi/MidiClient.cpp +++ b/src/core/midi/MidiClient.cpp @@ -71,8 +71,7 @@ void MidiClient::removePort( MidiPort* port ) return; } - QVector::Iterator it = - std::find( m_midiPorts.begin(), m_midiPorts.end(), port ); + auto it = std::find(m_midiPorts.begin(), m_midiPorts.end(), port); if( it != m_midiPorts.end() ) { m_midiPorts.erase( it ); diff --git a/src/gui/clips/AutomationClipView.cpp b/src/gui/clips/AutomationClipView.cpp index 6fa91efdb..a5d415a2e 100644 --- a/src/gui/clips/AutomationClipView.cpp +++ b/src/gui/clips/AutomationClipView.cpp @@ -191,10 +191,10 @@ void AutomationClipView::constructContextMenu( QMenu * _cm ) _cm->addAction( embed::getIconPixmap( "flip_x" ), tr( "Flip Horizontally (Visible)" ), this, SLOT(flipX())); - if( !m_clip->m_objects.isEmpty() ) + if (!m_clip->m_objects.empty()) { _cm->addSeparator(); - auto m = new QMenu(tr("%1 Connections").arg(m_clip->m_objects.count()), _cm); + auto m = new QMenu(tr("%1 Connections").arg(m_clip->m_objects.size()), _cm); for (const auto& object : m_clip->m_objects) { if (object) diff --git a/src/gui/clips/ClipView.cpp b/src/gui/clips/ClipView.cpp index 8c4f704bc..871466a55 100644 --- a/src/gui/clips/ClipView.cpp +++ b/src/gui/clips/ClipView.cpp @@ -545,7 +545,7 @@ DataFile ClipView::createClipDataFiles( { // Insert into the dom under the "clips" element Track* clipTrack = clipView->m_trackView->getTrack(); - int trackIndex = tc->tracks().indexOf( clipTrack ); + int trackIndex = std::distance(tc->tracks().begin(), std::find(tc->tracks().begin(), tc->tracks().end(), clipTrack)); QDomElement clipElement = dataFile.createElement("clip"); clipElement.setAttribute( "trackIndex", trackIndex ); clipElement.setAttribute( "trackType", clipTrack->type() ); @@ -557,12 +557,15 @@ DataFile ClipView::createClipDataFiles( dataFile.content().appendChild( clipParent ); // Add extra metadata needed for calculations later - int initialTrackIndex = tc->tracks().indexOf( t ); - if( initialTrackIndex < 0 ) + + const auto initialTrackIt = std::find(tc->tracks().begin(), tc->tracks().end(), t); + if (initialTrackIt != tc->tracks().end()) { printf("Failed to find selected track in the TrackContainer.\n"); return dataFile; } + + const int initialTrackIndex = std::distance(tc->tracks().begin(), initialTrackIt); QDomElement metadata = dataFile.createElement( "copyMetadata" ); // initialTrackIndex is the index of the track that was touched metadata.setAttribute( "initialTrackIndex", initialTrackIndex ); diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index db56557a4..1289c5626 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -72,7 +72,7 @@ QPixmap * AutomationEditor::s_toolMove = nullptr; QPixmap * AutomationEditor::s_toolYFlip = nullptr; QPixmap * AutomationEditor::s_toolXFlip = nullptr; -const QVector AutomationEditor::m_zoomXLevels = +const std::array AutomationEditor::m_zoomXLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f }; diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 337b36b36..753dfe77f 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -148,15 +148,14 @@ std::array PianoRoll::prKeyOrder const int DEFAULT_PR_PPB = DEFAULT_CELL_WIDTH * DefaultStepsPerBar; -const QVector PianoRoll::m_zoomLevels = +const std::vector PianoRoll::m_zoomLevels = {0.125f, 0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 4.0f, 8.0f}; -const QVector PianoRoll::m_zoomYLevels = +const std::vector PianoRoll::m_zoomYLevels = {0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 4.0f}; PianoRoll::PianoRoll() : - m_nemStr( QVector() ), m_noteEditMenu( nullptr ), m_semiToneMarkerMenu( nullptr ), m_zoomingModel(), @@ -406,7 +405,7 @@ PianoRoll::PianoRoll() : InstrumentFunctionNoteStacking::ChordTable::getInstance(); m_scaleModel.addItem( tr("No scale") ); - for( const InstrumentFunctionNoteStacking::Chord& chord : chord_table ) + for (const InstrumentFunctionNoteStacking::Chord& chord : chord_table.chords()) { if( chord.isScale() ) { @@ -423,7 +422,7 @@ PianoRoll::PianoRoll() : // Set up chord model m_chordModel.addItem( tr("No chord") ); - for( const InstrumentFunctionNoteStacking::Chord& chord : chord_table ) + for (const InstrumentFunctionNoteStacking::Chord& chord : chord_table.chords()) { if( ! chord.isScale() ) { @@ -775,7 +774,7 @@ void PianoRoll::fitNoteLengths(bool fill) { if (!fill) { break; } // Last notes stretch to end of last bar - length = notes.last()->endPos().nextFullBar() * TimePos::ticksPerBar() - note->pos(); + length = notes.back()->endPos().nextFullBar() * TimePos::ticksPerBar() - note->pos(); } else { @@ -1241,11 +1240,11 @@ void PianoRoll::shiftPos(NoteVector notes, int amount) { m_midiClip->addJournalCheckPoint(); - if (notes.isEmpty()) { + if (notes.empty()) { return; } - auto leftMostPos = notes.first()->pos(); + auto leftMostPos = notes.front()->pos(); //Limit leftwards shifts to prevent moving left of clip start auto shiftAmount = (leftMostPos > -amount) ? amount : -leftMostPos; if (shiftAmount == 0) { return; } @@ -1645,7 +1644,7 @@ void PianoRoll::mousePressEvent(QMouseEvent * me ) if (note) { - n.append(note); + n.push_back(note); updateKnifePos(me); @@ -1723,7 +1722,7 @@ void PianoRoll::mousePressEvent(QMouseEvent * me ) const NoteVector & notes = m_midiClip->notes(); // will be our iterator in the following loop - NoteVector::ConstIterator it = notes.begin()+notes.size()-1; + auto it = notes.begin() + notes.size() - 1; // loop through whole note-vector... for( int i = 0; i < notes.size(); ++i ) @@ -1846,9 +1845,9 @@ void PianoRoll::mousePressEvent(QMouseEvent * me ) auto selectedNotes = getSelectedNotes(); - m_moveBoundaryLeft = selectedNotes.first()->pos().getTicks(); - m_moveBoundaryRight = selectedNotes.first()->endPos(); - m_moveBoundaryBottom = selectedNotes.first()->key(); + m_moveBoundaryLeft = selectedNotes.front()->pos().getTicks(); + m_moveBoundaryRight = selectedNotes.front()->endPos(); + m_moveBoundaryBottom = selectedNotes.front()->key(); m_moveBoundaryTop = m_moveBoundaryBottom; //Figure out the bounding box of all the selected notes @@ -2036,7 +2035,7 @@ void PianoRoll::mouseDoubleClickEvent(QMouseEvent * me ) { if( i->withinRange( ticks_start, ticks_end ) || ( i->selected() && !altPressed ) ) { - nv += i; + nv.push_back(i); } } // make sure we're on a note @@ -2054,8 +2053,8 @@ void PianoRoll::mouseDoubleClickEvent(QMouseEvent * me ) if( dist < closest_dist ) { closest = i; closest_dist = dist; } } // ... then remove all notes from the vector that aren't on the same exact time - NoteVector::Iterator it = nv.begin(); - while( it != nv.end() ) + auto it = nv.begin(); + while (it != nv.end()) { const Note *note = *it; if( note->pos().getTicks() != closest->pos().getTicks() ) @@ -2517,7 +2516,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) bool altPressed = me->modifiers() & Qt::AltModifier; // We iterate from last note in MIDI clip to the first, // chronologically - NoteVector::ConstIterator it = notes.begin()+notes.size()-1; + auto it = notes.begin() + notes.size() - 1; for( int i = 0; i < notes.size(); ++i ) { Note* n = *it; @@ -2579,7 +2578,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) const NoteVector & notes = m_midiClip->notes(); // will be our iterator in the following loop - NoteVector::ConstIterator it = notes.begin()+notes.size()-1; + auto it = notes.begin() + notes.size() - 1; // loop through whole note-vector... for( int i = 0; i < notes.size(); ++i ) @@ -2656,7 +2655,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) const NoteVector & notes = m_midiClip->notes(); // will be our iterator in the following loop - NoteVector::ConstIterator it = notes.begin(); + auto it = notes.begin(); // loop through whole note-vector... while( it != notes.end() ) @@ -3789,7 +3788,7 @@ void PianoRoll::wheelEvent(QWheelEvent * we ) { if( i->withinRange( ticks_start, ticks_end ) || ( i->selected() && !altPressed ) ) { - nv += i; + nv.push_back(i); } } if( nv.size() > 0 ) diff --git a/src/gui/editors/TrackContainerView.cpp b/src/gui/editors/TrackContainerView.cpp index 38a6a36d5..83017fb1a 100644 --- a/src/gui/editors/TrackContainerView.cpp +++ b/src/gui/editors/TrackContainerView.cpp @@ -199,8 +199,8 @@ void TrackContainerView::moveTrackView( TrackView * trackView, int indexTo ) Track * track = m_tc->m_tracks[indexFrom]; - m_tc->m_tracks.remove( indexFrom ); - m_tc->m_tracks.insert( indexTo, track ); + m_tc->m_tracks.erase(m_tc->m_tracks.begin() + indexFrom); + m_tc->m_tracks.insert(m_tc->m_tracks.begin() + indexTo, track); m_trackViews.move( indexFrom, indexTo ); realignTracks(); diff --git a/src/gui/modals/ControllerConnectionDialog.cpp b/src/gui/modals/ControllerConnectionDialog.cpp index 6396c7ccb..55c0b476f 100644 --- a/src/gui/modals/ControllerConnectionDialog.cpp +++ b/src/gui/modals/ControllerConnectionDialog.cpp @@ -258,10 +258,12 @@ ControllerConnectionDialog::ControllerConnectionDialog( QWidget * _parent, } else { - int idx = Engine::getSong()->controllers().indexOf( cc->getController() ); + auto& controllers = Engine::getSong()->controllers(); + auto it = std::find(controllers.begin(), controllers.end(), cc->getController()); - if( idx >= 0 ) + if (it != controllers.end()) { + int idx = std::distance(it, controllers.begin()); m_userGroupBox->model()->setValue( true ); m_userController->model()->setValue( idx ); } diff --git a/src/gui/tracks/TrackContentWidget.cpp b/src/gui/tracks/TrackContentWidget.cpp index 26107c1ae..ca7123bda 100644 --- a/src/gui/tracks/TrackContentWidget.cpp +++ b/src/gui/tracks/TrackContentWidget.cpp @@ -345,7 +345,8 @@ bool TrackContentWidget::canPasteSelection( TimePos clipPos, const QMimeData* md // Get the current track's index const TrackContainer::TrackList tracks = t->trackContainer()->tracks(); - const int currentTrackIndex = tracks.indexOf( t ); + const auto currentTrackIt = std::find(tracks.begin(), tracks.end(), t); + const int currentTrackIndex = currentTrackIt != tracks.end() ? std::distance(tracks.begin(), currentTrackIt) : -1; // Don't paste if we're on the same bar and allowSameBar is false auto sourceTrackContainerId = metadata.attributeNode( "trackContainerId" ).value().toUInt(); @@ -443,7 +444,8 @@ bool TrackContentWidget::pasteSelection( TimePos clipPos, const QMimeData * md, // Snap the mouse position to the beginning of the dropped bar, in ticks const TrackContainer::TrackList tracks = getTrack()->trackContainer()->tracks(); - const int currentTrackIndex = tracks.indexOf( getTrack() ); + const auto currentTrackIt = std::find(tracks.begin(), tracks.end(), getTrack()); + const int currentTrackIndex = currentTrackIt != tracks.end() ? std::distance(tracks.begin(), currentTrackIt) : -1; bool wasSelection = m_trackView->trackContainerView()->rubberBand()->selectedObjects().count(); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 7eb6bba11..1d2546288 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -739,7 +739,7 @@ bool InstrumentTrack::play( const TimePos & _start, const fpp_t _frames, // get all notes from the given clip... const NoteVector & notes = c->notes(); // ...and set our index to zero - NoteVector::ConstIterator nit = notes.begin(); + auto nit = notes.begin(); // very effective algorithm for playing notes that are // posated within the current sample-frame diff --git a/src/tracks/MidiClip.cpp b/src/tracks/MidiClip.cpp index 08e76ae59..52a532028 100644 --- a/src/tracks/MidiClip.cpp +++ b/src/tracks/MidiClip.cpp @@ -115,11 +115,11 @@ void MidiClip::resizeToFirstTrack() { if (track != m_instrumentTrack) { - unsigned int currentClip = m_instrumentTrack-> - getClips().indexOf(this); - m_steps = static_cast - (track->getClip(currentClip)) - ->m_steps; + const auto& instrumentTrackClips = m_instrumentTrack->getClips(); + const auto currentClipIt = std::find(instrumentTrackClips.begin(), instrumentTrackClips.end(), this); + unsigned int currentClip = currentClipIt != instrumentTrackClips.end() ? + std::distance(instrumentTrackClips.begin(), currentClipIt) : -1; + m_steps = static_cast(track->getClip(currentClip))->m_steps; } break; } @@ -218,17 +218,14 @@ Note * MidiClip::addNote( const Note & _new_note, const bool _quant_pos ) void MidiClip::removeNote( Note * _note_to_del ) { instrumentTrack()->lock(); - NoteVector::Iterator it = m_notes.begin(); - while( it != m_notes.end() ) + + m_notes.erase(std::remove_if(m_notes.begin(), m_notes.end(), [&](Note* note) { - if( *it == _note_to_del ) - { - delete *it; - m_notes.erase( it ); - break; - } - ++it; - } + auto shouldRemove = note == _note_to_del; + if (shouldRemove) { delete note; } + return shouldRemove; + }), m_notes.end()); + instrumentTrack()->unlock(); checkType(); @@ -354,15 +351,13 @@ void MidiClip::setType( MidiClipTypes _new_clip_type ) void MidiClip::checkType() { - NoteVector::Iterator it = m_notes.begin(); - while( it != m_notes.end() ) + for (auto& note : m_notes) { - if( ( *it )->length() > 0 ) + if (note->length() > 0) { - setType( MelodyClip ); + setType(MelodyClip); return; } - ++it; } setType( BeatClip ); } @@ -395,9 +390,9 @@ void MidiClip::saveSettings( QDomDocument & _doc, QDomElement & _this ) _this.setAttribute( "steps", m_steps ); // now save settings of all notes - for (const auto& note : m_notes) + for (auto& note : m_notes) { - note->saveState( _doc, _this ); + note->saveState(_doc, _this); } } @@ -477,9 +472,10 @@ MidiClip * MidiClip::nextMidiClip() const MidiClip * MidiClip::adjacentMidiClipByOffset(int offset) const { - QVector clips = m_instrumentTrack->getClips(); + std::vector clips = m_instrumentTrack->getClips(); int clipNum = m_instrumentTrack->getClipNum(this); - return dynamic_cast(clips.value(clipNum + offset, nullptr)); + if (clipNum < 0 || clipNum > clips.size() - 1) { return nullptr; } + return dynamic_cast(clips[clipNum + offset]); }