Skip to content

Commit

Permalink
Core Refactor: Replace QVector with std::vector (LMMS#6477)
Browse files Browse the repository at this point in the history
* 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 84b8fe8

* 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>
  • Loading branch information
3 people authored Aug 22, 2023
1 parent 2ca05d0 commit 9a0add4
Show file tree
Hide file tree
Showing 49 changed files with 314 additions and 273 deletions.
6 changes: 3 additions & 3 deletions include/AudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#endif

#include <QThread>
#include <QVector>
#include <QWaitCondition>
#include <samplerate.h>

#include <vector>

#include "lmms_basics.h"
#include "LocklessList.h"
Expand Down Expand Up @@ -416,7 +416,7 @@ class LMMS_EXPORT AudioEngine : public QObject

bool m_renderOnly;

QVector<AudioPort *> m_audioPorts;
std::vector<AudioPort *> m_audioPorts;

fpp_t m_framesPerPeriod;

Expand All @@ -430,7 +430,7 @@ class LMMS_EXPORT AudioEngine : public QObject
surroundSampleFrame * m_outputBufferWrite;

// worker thread stuff
QVector<AudioEngineWorkerThread *> m_workers;
std::vector<AudioEngineWorkerThread *> m_workers;
int m_numWorkers;

// playhandle stuff
Expand Down
4 changes: 2 additions & 2 deletions include/AudioEngineWorkerThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class AudioEngineWorkerThread : public QThread
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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/AudioJack.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#endif

#include <atomic>
#include <QVector>
#include <vector>

#include "AudioDevice.h"
#include "AudioDeviceSetupWidget.h"
Expand Down Expand Up @@ -117,7 +117,7 @@ private slots:
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;

Expand Down
2 changes: 1 addition & 1 deletion include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
15 changes: 12 additions & 3 deletions include/AutomationClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LMMS_EXPORT AutomationClip : public Clip
} ;

using timeMap = QMap<int, AutomationNode>;
using objectVector = QVector<QPointer<AutomatableModel>>;
using objectVector = std::vector<QPointer<AutomatableModel>>;

using TimemapIterator = timeMap::const_iterator;

Expand Down Expand Up @@ -167,7 +167,7 @@ class LMMS_EXPORT AutomationClip : public Clip


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

Expand All @@ -190,6 +190,15 @@ public slots:
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))
Expand All @@ -199,7 +208,7 @@ public slots:
#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.
Expand Down
3 changes: 2 additions & 1 deletion include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define LMMS_GUI_AUTOMATION_EDITOR_H

#include <QWidget>
#include <array>

#include "Editor.h"

Expand Down Expand Up @@ -180,7 +181,7 @@ protected slots:
ComboBoxModel m_zoomingYModel;
ComboBoxModel m_quantizeModel;

static const QVector<float> m_zoomXLevels;
static const std::array<float, 7> m_zoomXLevels;

FloatModel * m_tensionModel;

Expand Down
11 changes: 4 additions & 7 deletions include/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include <QMap>
#include <QPair>
#include <QStringList>
#include <QVector>
#include <QObject>

#include <vector>
#include "lmms_export.h"


Expand Down Expand Up @@ -239,11 +239,8 @@ class LMMS_EXPORT ConfigManager : public QObject

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);
Expand Down Expand Up @@ -302,7 +299,7 @@ class LMMS_EXPORT ConfigManager : public QObject
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;

Expand Down
2 changes: 1 addition & 1 deletion include/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions include/ControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion include/EffectChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LMMS_EXPORT EffectChain : public Model, public SerializingObject


private:
using EffectList = QVector<Effect*>;
using EffectList = std::vector<Effect*>;
EffectList m_effects;

BoolModel m_enabledModel;
Expand Down
2 changes: 1 addition & 1 deletion include/EnvelopeAndLfoParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion include/InstrumentFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class InstrumentFunctionNoteStacking : public Model, public JournallingObject
};


struct ChordTable : public QVector<Chord>
struct ChordTable
{
private:
ChordTable();
Expand All @@ -131,6 +131,7 @@ class InstrumentFunctionNoteStacking : public Model, public JournallingObject
};

static std::array<Init, NUM_CHORD_TABLES> s_initTable;
std::vector<Chord> m_chords;

public:
static const ChordTable & getInstance()
Expand All @@ -150,6 +151,11 @@ class InstrumentFunctionNoteStacking : public Model, public JournallingObject
{
return getByName( name, false );
}

const std::vector<Chord>& chords() const
{
return m_chords;
}
};


Expand Down
4 changes: 2 additions & 2 deletions include/MidiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define LMMS_MIDI_CLIENT_H

#include <QStringList>
#include <QVector>
#include <vector>


#include "MidiEvent.h"
Expand Down Expand Up @@ -111,7 +111,7 @@ class MidiClient
static MidiClient * openMidiClient();

protected:
QVector<MidiPort *> m_midiPorts;
std::vector<MidiPort *> m_midiPorts;

} ;

Expand Down
4 changes: 2 additions & 2 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace lmms


class MixerRoute;
using MixerRouteVector = QVector<MixerRoute*>;
using MixerRouteVector = std::vector<MixerRoute*>;

class MixerChannel : public ThreadableJob
{
Expand Down Expand Up @@ -219,7 +219,7 @@ class LMMS_EXPORT Mixer : public Model, public JournallingObject

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);
Expand Down
4 changes: 2 additions & 2 deletions include/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define LMMS_NOTE_H

#include <optional>
#include <QVector>
#include <vector>

#include "volume.h"
#include "panning.h"
Expand Down Expand Up @@ -249,7 +249,7 @@ class LMMS_EXPORT Note : public SerializingObject
DetuningHelper * m_detuning;
};

using NoteVector = QVector<Note*>;
using NoteVector = std::vector<Note*>;

struct NoteBounds
{
Expand Down
2 changes: 1 addition & 1 deletion include/PeakController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace lmms

class PeakControllerEffect;

using PeakControllerEffectVector = QVector<PeakControllerEffect*>;
using PeakControllerEffectVector = std::vector<PeakControllerEffect*>;

class LMMS_EXPORT PeakController : public Controller
{
Expand Down
9 changes: 5 additions & 4 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -291,7 +292,7 @@ protected slots:

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;
Expand Down Expand Up @@ -358,8 +359,8 @@ protected slots:
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;
Expand Down
4 changes: 2 additions & 2 deletions include/PluginFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -99,7 +99,7 @@ public slots:
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;

Expand Down
4 changes: 2 additions & 2 deletions include/RenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private slots:

std::unique_ptr<ProjectRenderer> m_activeRenderer;

QVector<Track*> m_tracksToRender;
QVector<Track*> m_unmuted;
std::vector<Track*> m_tracksToRender;
std::vector<Track*> m_unmuted;
} ;


Expand Down
4 changes: 2 additions & 2 deletions include/StepRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 9a0add4

Please sign in to comment.