Core Refactor: Replace `QVector with std::vector` (#6477)

* Replace QVector with std::vector in AudioEngine

* Replace QVector with std::vector in AudioEngineWorkerThread

* Replace QVector with std::vector in AudioJack

* Replace QVector with std::vector in AutomatableModel

* Replace QVector with std::vector in AutomationClip

* Replace QVector with std::vector in AutomationEditor

* Replace QVector with std::vector in ConfigManager

* Replace QVector with std::vector in Controller

* Replace QVector with std::vector in ControllerConnection

* Replace QVector with std::vector in EffectChain

* Replace QVector with std::vector in EnvelopeAndLfoParameters

* Replace QVector with std::vector in InstrumentFunctions

* Replace QVector with std::vector in MidiClient

* Replace QVector with std::vector in Mixer

* Replace QVector with std::vector in Note

* Replace QVector with std::vector in PeakController

* Replace QVector with std::vector in PianoRoll

* Replace QVector with std::vector in PluginFactory

* Replace QVector with std::vector in RenderManager

* Replace QVector with std::vector in StepRecorder

* Replace QVector with std::vector in Track

* Replace QVector with std::vector in TrackContainer

* Replace QVector with std::vector in Song

* Adapt QVector to std::vector changes in ControllerConnectionDialog

* Phase 2: Use std::abs in panning.h
Without this, the QVector changes will make the code not compile.

* Phase 2: Replace QVector with std::vector in PeakControllerEffect

* Phase 2: Replace QVector with std::vector in AutomatableModel

* Phase 2: Replace QVector with std::vector in AutomationClip

* Phase 2: Replace QVector with std::vector in ControllerConnection

* Phase 2: Replace QVector with std::vector in EffectChain

* Phase 2: Replace QVector with std::vector in Mixer

* Phase 2: Replace QVector with std::vector in PeakController

* Phase 2: Replace QVector with std::vector in RenderManager

* Phase 2: Replace QVector with std::vector in Song

* Phase 2: Replace QVector with std::vector in StepRecorder

* Phase 2: Replace QVector with std::vector in Track

* Phase 2: Replace QVector with std::vector in TrackContainer

* Phase 2: Adapt QVector changes in EffectRackView

* Phase 2: Adapt QVector changes in AutomationClipView

* Phase 2: Adapt QVector changes in ClipView

* Phase 2: Adapt QVector changes in AutomationEditor

* Phase 2: Adapt QVector changes in PianoRoll

* Phase 2: Adapt QVector changes in TrackContainerView

* Phase 2: Adapt QVector changes in TrackContentWidget

* Phase 2: Adapt QVector changes in InstrumentTrack

* Phase 2: Adapt QVector changes in MidiClip

* Phase 2: Adapt QVector changes in SampleTrack

* Fix segmentation fault in ConfigManager::value

* Fix unintended faulty std::vector insert in AutomationClip::resolveAllIDs

* Resolve trailing whitespace in src/core/StepRecorder.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Use std::next and std::prev in EffectChain::moveUp/moveDown

* Introduce static "combineAllTracks" function in AutomationClip

* Adjust variable name in Song::automatedValuesAt

* Adjust removal of long step notes in StepRecorder::removeNotesReleasedForTooLong

* Iterate over m_chords by const reference in src/core/InstrumentFunctions.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Fix StepRecorder::removeNotesReleasedForTooLong again

* Combine the ConfigManager::value overloads using std::optional

* Revise StepRecorder::removeNotesReleasedForTooLong

* Remove redundant std::optional in ConfigManager::value

* Remove trailing whitespace in ConfigManager::value

* Fix: Prevent incorrect use of std::distance when element not found

* Chore: Remove trailing whitespace in edited files

* Only set the id attribute if the controller was found

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Remove extra indents from 84b8fe8a559855ed263b74cc582eab3655250c5f

* Fix compilation issues

* Add LMMS_ prefix for header guard in Track.h

* Undo changes made to MixerView::deleteUnusedChannels

* Simplify code to handle failure of finding tracks
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Split ternary operator into separate if statement
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Undo changes to indentation in MixerRoute

* Do general clean-up
Some of the changes made:
+ Use auto where benefical
+ Fix bug in AutomatableModel::globalAutomationValueAt (for loop should be looping over clips variable, not clipsInRange)
+ Undo out of focus whitespace changes

* Always assign to m_steps regardless if clip is found or not
Even when the clip is not found (i.e., currentClip is -1), m_steps still
gets assigned to.

* Insert at the end of tracks vector in src/core/Mixer.cpp

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Insert at the end of tracks vector in src/core/Mixer.cpp (2)

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Remove redundant template parameter

* Use std::array for zoomLevels

---------

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: Dominic Clark <mrdomclark@gmail.com>
This commit is contained in:
saker
2023-08-21 23:08:56 -04:00
committed by GitHub
parent 2ca05d025c
commit 9a0add49fb
49 changed files with 314 additions and 273 deletions

View File

@@ -32,10 +32,10 @@
#endif
#include <QThread>
#include <QVector>
#include <QWaitCondition>
#include <samplerate.h>
#include <vector>
#include "lmms_basics.h"
#include "LocklessList.h"
@@ -416,7 +416,7 @@ private:
bool m_renderOnly;
QVector<AudioPort *> m_audioPorts;
std::vector<AudioPort *> m_audioPorts;
fpp_t m_framesPerPeriod;
@@ -430,7 +430,7 @@ private:
surroundSampleFrame * m_outputBufferWrite;
// worker thread stuff
QVector<AudioEngineWorkerThread *> m_workers;
std::vector<AudioEngineWorkerThread *> m_workers;
int m_numWorkers;
// playhandle stuff

View File

@@ -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);
}
}

View File

@@ -35,7 +35,7 @@
#endif
#include <atomic>
#include <QVector>
#include <vector>
#include "AudioDevice.h"
#include "AudioDeviceSetupWidget.h"
@@ -117,7 +117,7 @@ private:
std::atomic<bool> m_stopped;
std::atomic<MidiJack *> m_midiClient;
QVector<jack_port_t *> m_outputPorts;
std::vector<jack_port_t *> m_outputPorts;
jack_default_audio_sample_t * * m_tempOutBufs;
surroundSampleFrame * m_outBuf;

View File

@@ -78,7 +78,7 @@ class LMMS_EXPORT AutomatableModel : public Model, public JournallingObject
Q_OBJECT
MM_OPERATORS
public:
using AutoModelVector = QVector<AutomatableModel*>;
using AutoModelVector = std::vector<AutomatableModel*>;
enum ScaleType
{

View File

@@ -62,7 +62,7 @@ public:
} ;
using timeMap = QMap<int, AutomationNode>;
using objectVector = QVector<QPointer<AutomatableModel>>;
using objectVector = std::vector<QPointer<AutomatableModel>>;
using TimemapIterator = timeMap::const_iterator;
@@ -167,7 +167,7 @@ public:
static bool isAutomated( const AutomatableModel * _m );
static QVector<AutomationClip *> clipsForModel( const AutomatableModel * _m );
static std::vector<AutomationClip*> 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<Track*>
*/
static std::vector<Track*> 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<jo_id_t> m_idsToResolve;
std::vector<jo_id_t> m_idsToResolve;
objectVector m_objects;
timeMap m_timeMap; // actual values
timeMap m_oldTimeMap; // old values for storing the values before setDragValue() is called.

View File

@@ -27,6 +27,7 @@
#define LMMS_GUI_AUTOMATION_EDITOR_H
#include <QWidget>
#include <array>
#include "Editor.h"
@@ -180,7 +181,7 @@ private:
ComboBoxModel m_zoomingYModel;
ComboBoxModel m_quantizeModel;
static const QVector<float> m_zoomXLevels;
static const std::array<float, 7> m_zoomXLevels;
FloatModel * m_tensionModel;

View File

@@ -30,9 +30,9 @@
#include <QMap>
#include <QPair>
#include <QStringList>
#include <QVector>
#include <QObject>
#include <vector>
#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<QPair<QString, QString>>;
using stringPairVector = std::vector<QPair<QString, QString>>;
using settingsMap = QMap<QString, stringPairVector>;
settingsMap m_settings;

View File

@@ -45,7 +45,7 @@ class ControllerDialog;
} // namespace gui
using ControllerVector = QVector<Controller*>;
using ControllerVector = std::vector<Controller*>;
class LMMS_EXPORT Controller : public Model, public JournallingObject
{

View File

@@ -30,12 +30,13 @@
#define LMMS_CONTROLLER_CONNECTION_H
#include <QObject>
#include <QVector>
#include "Controller.h"
#include "JournallingObject.h"
#include "ValueBuffer.h"
#include <vector>
namespace lmms
{
@@ -46,7 +47,7 @@ namespace gui
class ControllerConnectionDialog;
}
using ControllerConnectionVector = QVector<ControllerConnection*>;
using ControllerConnectionVector = std::vector<ControllerConnection*>;
class LMMS_EXPORT ControllerConnection : public QObject, public JournallingObject
{

View File

@@ -69,7 +69,7 @@ public:
private:
using EffectList = QVector<Effect*>;
using EffectList = std::vector<Effect*>;
EffectList m_effects;
BoolModel m_enabledModel;

View File

@@ -25,7 +25,7 @@
#ifndef LMMS_ENVELOPE_AND_LFO_PARAMETERS_H
#define LMMS_ENVELOPE_AND_LFO_PARAMETERS_H
#include <QVector>
#include <vector>
#include "JournallingObject.h"
#include "AutomatableModel.h"

View File

@@ -119,7 +119,7 @@ public:
};
struct ChordTable : public QVector<Chord>
struct ChordTable
{
private:
ChordTable();
@@ -131,6 +131,7 @@ public:
};
static std::array<Init, NUM_CHORD_TABLES> s_initTable;
std::vector<Chord> m_chords;
public:
static const ChordTable & getInstance()
@@ -150,6 +151,11 @@ public:
{
return getByName( name, false );
}
const std::vector<Chord>& chords() const
{
return m_chords;
}
};

View File

@@ -26,7 +26,7 @@
#define LMMS_MIDI_CLIENT_H
#include <QStringList>
#include <QVector>
#include <vector>
#include "MidiEvent.h"
@@ -111,7 +111,7 @@ public:
static MidiClient * openMidiClient();
protected:
QVector<MidiPort *> m_midiPorts;
std::vector<MidiPort *> m_midiPorts;
} ;

View File

@@ -39,7 +39,7 @@ namespace lmms
class MixerRoute;
using MixerRouteVector = QVector<MixerRoute*>;
using MixerRouteVector = std::vector<MixerRoute*>;
class MixerChannel : public ThreadableJob
{
@@ -219,7 +219,7 @@ public:
private:
// the mixer channels in the mixer. index 0 is always master.
QVector<MixerChannel *> m_mixerChannels;
std::vector<MixerChannel*> m_mixerChannels;
// make sure we have at least num channels
void allocateChannelsTo(int num);

View File

@@ -27,7 +27,7 @@
#define LMMS_NOTE_H
#include <optional>
#include <QVector>
#include <vector>
#include "volume.h"
#include "panning.h"
@@ -249,7 +249,7 @@ private:
DetuningHelper * m_detuning;
};
using NoteVector = QVector<Note*>;
using NoteVector = std::vector<Note*>;
struct NoteBounds
{

View File

@@ -36,7 +36,7 @@ namespace lmms
class PeakControllerEffect;
using PeakControllerEffectVector = QVector<PeakControllerEffect*>;
using PeakControllerEffectVector = std::vector<PeakControllerEffect*>;
class LMMS_EXPORT PeakController : public Controller
{

View File

@@ -27,9 +27,10 @@
#ifndef LMMS_GUI_PIANO_ROLL_H
#define LMMS_GUI_PIANO_ROLL_H
#include <QVector>
#include <QWidget>
#include <vector>
#include "Editor.h"
#include "ComboBoxModel.h"
#include "SerializingObject.h"
@@ -291,7 +292,7 @@ private:
PositionLine * m_positionLine;
QVector<QString> m_nemStr; // gui names of each edit mode
std::vector<QString> m_nemStr; // gui names of each edit mode
QMenu * m_noteEditMenu; // when you right click below the key area
QList<int> m_markedSemiTones;
@@ -358,8 +359,8 @@ private:
ComboBoxModel m_chordModel;
ComboBoxModel m_snapModel;
static const QVector<float> m_zoomLevels;
static const QVector<float> m_zoomYLevels;
static const std::vector<float> m_zoomLevels;
static const std::vector<float> m_zoomYLevels;
MidiClip* m_midiClip;
NoteVector m_ghostNotes;

View File

@@ -27,12 +27,12 @@
#include <memory>
#include <string>
#include <vector>
#include <QFileInfo>
#include <QHash>
#include <QList>
#include <QString>
#include <QVector>
#include "lmms_export.h"
#include "Plugin.h"
@@ -99,7 +99,7 @@ private:
PluginInfoList m_pluginInfos;
QMap<QString, PluginInfoAndKey> m_pluginByExt;
QVector<std::string> m_garbage; //!< cleaned up at destruction
std::vector<std::string> m_garbage; //!< cleaned up at destruction
QHash<QString, QString> m_errors;

View File

@@ -78,8 +78,8 @@ private:
std::unique_ptr<ProjectRenderer> m_activeRenderer;
QVector<Track*> m_tracksToRender;
QVector<Track*> m_unmuted;
std::vector<Track*> m_tracksToRender;
std::vector<Track*> m_unmuted;
} ;

View File

@@ -59,7 +59,7 @@ class StepRecorder : public QObject
void setCurrentMidiClip(MidiClip* newMidiClip);
void setStepsLength(const TimePos& newLength);
QVector<Note*> getCurStepNotes();
std::vector<Note*> getCurStepNotes();
bool isRecording() const
{
@@ -142,7 +142,7 @@ class StepRecorder : public QObject
QElapsedTimer releasedTimer;
} ;
QVector<StepNote*> 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<StepNote*> 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);

View File

@@ -25,7 +25,8 @@
#ifndef LMMS_TRACK_H
#define LMMS_TRACK_H
#include <QVector>
#include <vector>
#include <QColor>
#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<Clip*>;
using clipVector = std::vector<Clip*>;
enum TrackTypes
{

View File

@@ -49,7 +49,7 @@ class LMMS_EXPORT TrackContainer : public Model, public JournallingObject
{
Q_OBJECT
public:
using TrackList = QVector<Track*>;
using TrackList = std::vector<Track*>;
enum TrackContainerTypes
{
PatternContainer,

View File

@@ -31,6 +31,8 @@
#include "Midi.h"
#include "volume.h"
#include <cmath>
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<float>( pf );
v.vol[_p >= PanningCenter ? 0 : 1] *= 1.0f - std::abs(pf);
return v;
}

View File

@@ -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);
}
}

View File

@@ -419,7 +419,7 @@ const surroundSampleFrame * AudioEngine::renderNextBuffer()
}
// STAGE 2: process effects of all instrument- and sampletracks
AudioEngineWorkerThread::fillJobQueue<QVector<AudioPort *> >( m_audioPorts );
AudioEngineWorkerThread::fillJobQueue(m_audioPorts);
AudioEngineWorkerThread::startAndWaitForJobs();
@@ -663,7 +663,7 @@ void AudioEngine::removeAudioPort(AudioPort * port)
{
requestChangeInModel();
QVector<AudioPort *>::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);

View File

@@ -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<AutomationClip *> 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<AutomationClip *> clipsInRange;
std::vector<AutomationClip*> 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

View File

@@ -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<float>() ), 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<TimePos> nodesToRemove;
std::vector<TimePos> 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 *> AutomationClip::clipsForModel( const AutomatableModel * _m )
std::vector<AutomationClip *> AutomationClip::clipsForModel(const AutomatableModel* _m)
{
QVector<AutomationClip*> clips;
TrackContainer::TrackList tracks;
tracks += Engine::getSong()->tracks();
tracks += Engine::patternStore()->tracks();
tracks += Engine::getSong()->globalAutomationTrack();
std::vector<AutomationClip *> 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 *> 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<Track*> AutomationClip::combineAllTracks()
{
std::vector<Track*> 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

View File

@@ -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;
}

View File

@@ -25,8 +25,8 @@
*/
#include <QDomElement>
#include <QVector>
#include <vector>
#include "AudioEngine.h"
#include "ControllerConnection.h"
@@ -40,7 +40,7 @@ namespace lmms
long Controller::s_periods = 0;
QVector<Controller *> Controller::s_controllers;
std::vector<Controller*> 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();

View File

@@ -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);
}
}
}

View File

@@ -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<int>(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;
}

View File

@@ -177,12 +177,11 @@ bool InstrumentFunctionNoteStacking::Chord::hasSemiTone( int8_t semi_tone ) cons
InstrumentFunctionNoteStacking::ChordTable::ChordTable() :
QVector<Chord>()
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<PixmapLoader>( "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<int>(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 ||

View File

@@ -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)
{

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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<Note*> StepRecorder::getCurStepNotes()
std::vector<Note*> StepRecorder::getCurStepNotes()
{
QVector<Note*> notes;
std::vector<Note*> 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<int>::max();
bool notesRemoved = false;
QMutableVectorIterator<StepNote*> 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();

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -71,8 +71,7 @@ void MidiClient::removePort( MidiPort* port )
return;
}
QVector<MidiPort *>::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 );

View File

@@ -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)

View File

@@ -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 );

View File

@@ -72,7 +72,7 @@ QPixmap * AutomationEditor::s_toolMove = nullptr;
QPixmap * AutomationEditor::s_toolYFlip = nullptr;
QPixmap * AutomationEditor::s_toolXFlip = nullptr;
const QVector<float> AutomationEditor::m_zoomXLevels =
const std::array<float, 7> AutomationEditor::m_zoomXLevels =
{ 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f };

View File

@@ -148,15 +148,14 @@ std::array<PianoRoll::PianoRollKeyTypes, 12> PianoRoll::prKeyOrder
const int DEFAULT_PR_PPB = DEFAULT_CELL_WIDTH * DefaultStepsPerBar;
const QVector<float> PianoRoll::m_zoomLevels =
const std::vector<float> PianoRoll::m_zoomLevels =
{0.125f, 0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 4.0f, 8.0f};
const QVector<float> PianoRoll::m_zoomYLevels =
const std::vector<float> PianoRoll::m_zoomYLevels =
{0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 4.0f};
PianoRoll::PianoRoll() :
m_nemStr( QVector<QString>() ),
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 )

View File

@@ -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();

View File

@@ -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 );
}

View File

@@ -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();

View File

@@ -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

View File

@@ -115,11 +115,11 @@ void MidiClip::resizeToFirstTrack()
{
if (track != m_instrumentTrack)
{
unsigned int currentClip = m_instrumentTrack->
getClips().indexOf(this);
m_steps = static_cast<MidiClip *>
(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<MidiClip*>(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<Clip *> clips = m_instrumentTrack->getClips();
std::vector<Clip *> clips = m_instrumentTrack->getClips();
int clipNum = m_instrumentTrack->getClipNum(this);
return dynamic_cast<MidiClip*>(clips.value(clipNum + offset, nullptr));
if (clipNum < 0 || clipNum > clips.size() - 1) { return nullptr; }
return dynamic_cast<MidiClip*>(clips[clipNum + offset]);
}