diff --git a/include/AutomationTrack.h b/include/AutomationTrack.h index 4e46204a0bc..f7918cfb038 100644 --- a/include/AutomationTrack.h +++ b/include/AutomationTrack.h @@ -36,7 +36,7 @@ class AutomationTrack : public Track { Q_OBJECT public: - AutomationTrack( TrackContainer* tc, bool _hidden = false ); + AutomationTrack(bool hidden = false); ~AutomationTrack() override = default; bool play( const TimePos & _start, const fpp_t _frames, diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index 9be6e8373b5..0c5d162eff5 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -64,7 +64,7 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor Q_OBJECT mapPropertyFromModel(int,getVolume,setVolume,m_volumeModel); public: - InstrumentTrack( TrackContainer* tc ); + InstrumentTrack(); ~InstrumentTrack() override; // used by instrument diff --git a/include/PatternTrack.h b/include/PatternTrack.h index b6ccda959e0..3cac3ae65a6 100644 --- a/include/PatternTrack.h +++ b/include/PatternTrack.h @@ -48,7 +48,7 @@ class LMMS_EXPORT PatternTrack : public Track { Q_OBJECT public: - PatternTrack(TrackContainer* tc); + PatternTrack(); ~PatternTrack() override; bool play( const TimePos & _start, const fpp_t _frames, diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 71105a8789f..55feb03e7c1 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -45,7 +45,7 @@ class SampleTrack : public Track { Q_OBJECT public: - SampleTrack( TrackContainer* tc ); + SampleTrack(); ~SampleTrack() override; bool play( const TimePos & _start, const fpp_t _frames, diff --git a/include/Track.h b/include/Track.h index e62dcbb101e..f772ab54e6e 100644 --- a/include/Track.h +++ b/include/Track.h @@ -84,7 +84,7 @@ class LMMS_EXPORT Track : public Model, public JournallingObject Count } ; - Track( Type type, TrackContainer * tc ); + Track(Type type); ~Track() override; static Track * create( Type tt, TrackContainer * tc ); @@ -159,6 +159,8 @@ class LMMS_EXPORT Track : public Model, public JournallingObject return m_trackContainer; } + void setTrackContainer(TrackContainer* trackContainer) { m_trackContainer = trackContainer; } + // name-stuff virtual const QString & name() const { diff --git a/include/TrackContainer.h b/include/TrackContainer.h index a6ea43ccde1..bc9c6444526 100644 --- a/include/TrackContainer.h +++ b/include/TrackContainer.h @@ -83,6 +83,7 @@ class LMMS_EXPORT TrackContainer : public Model, public JournallingObject m_tracksMutex.lockForWrite(); m_tracks.push_back(track); + track->setTrackContainer(this); updateAfterTrackAdd(track); m_tracksMutex.unlock(); diff --git a/plugins/HydrogenImport/HydrogenImport.cpp b/plugins/HydrogenImport/HydrogenImport.cpp index 42c31096578..65b9c0d6025 100644 --- a/plugins/HydrogenImport/HydrogenImport.cpp +++ b/plugins/HydrogenImport/HydrogenImport.cpp @@ -218,7 +218,7 @@ bool HydrogenImport::readSong() if ( nLayer == 0 ) { - drum_track[sId] = Engine::patternStore()->addTrack(Engine::patternStore()); + drum_track[sId] = Engine::patternStore()->addTrack(); drum_track[sId]->volumeModel()->setValue( fVolume * 100 ); drum_track[sId]->panningModel()->setValue( ( fPan_R - fPan_L ) * 100 ); ins = drum_track[sId]->loadInstrument( "audiofileprocessor" ); diff --git a/plugins/MidiImport/MidiImport.cpp b/plugins/MidiImport/MidiImport.cpp index 020c644a288..a1c57c1a500 100644 --- a/plugins/MidiImport/MidiImport.cpp +++ b/plugins/MidiImport/MidiImport.cpp @@ -165,7 +165,7 @@ class smfMidiCC // in the main thread. This should probably be // removed if that ever changes. qApp->processEvents(); - at = tc->addTrack(tc); + at = tc->addTrack(); } if( tn != "") { at->setName( tn ); @@ -227,7 +227,7 @@ class smfMidiChannel if( !it ) { // Keep LMMS responsive qApp->processEvents(); - it = tc->addTrack(tc); + it = tc->addTrack(); #ifdef LMMS_HAVE_FLUIDSYNTH it_inst = it->loadInstrument( "sf2player" ); @@ -331,10 +331,10 @@ bool MidiImport::readSMF( TrackContainer* tc ) // NOTE: unordered_map::operator[] creates a new element if none exists MeterModel & timeSigMM = Engine::getSong()->getTimeSigModel(); - auto nt = Engine::getSong()->addTrack(Engine::getSong()); + auto nt = Engine::getSong()->addTrack(); nt->setName(tr("MIDI Time Signature Numerator")); - auto dt = Engine::getSong()->addTrack(Engine::getSong()); + auto dt = Engine::getSong()->addTrack(); dt->setName(tr("MIDI Time Signature Denominator")); auto timeSigNumeratorPat = static_cast(nt->createClip()); @@ -363,7 +363,7 @@ bool MidiImport::readSMF( TrackContainer* tc ) pd.setValue( 2 ); // Tempo stuff - auto tt = Engine::getSong()->addTrack(Engine::getSong()); + auto tt = Engine::getSong()->addTrack(); tt->setName(tr("Tempo")); auto tap = static_cast(tt->createClip()); tap->setDisplayName(tr("Tempo")); diff --git a/src/core/PresetPreviewPlayHandle.cpp b/src/core/PresetPreviewPlayHandle.cpp index 2233c4bd23f..bb818d0f249 100644 --- a/src/core/PresetPreviewPlayHandle.cpp +++ b/src/core/PresetPreviewPlayHandle.cpp @@ -48,7 +48,7 @@ class PreviewTrackContainer : public TrackContainer m_dataMutex() { setJournalling( false ); - m_previewInstrumentTrack = addTrack(this); + m_previewInstrumentTrack = addTrack(); m_previewInstrumentTrack->setJournalling( false ); m_previewInstrumentTrack->setPreviewMode( true ); } diff --git a/src/core/Song.cpp b/src/core/Song.cpp index e4bd537437b..5ca9ab8871d 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -68,7 +68,7 @@ tick_t TimePos::s_ticksPerBar = DefaultTicksPerBar; Song::Song() : TrackContainer(), - m_globalAutomationTrack(new AutomationTrack(this, true)), + m_globalAutomationTrack(new AutomationTrack(true)), m_tempoModel( DefaultTempo, MinTempo, MaxTempo, this, tr( "Tempo" ) ), m_timeSigModel( this ), m_oldTicksPerBar( DefaultTicksPerBar ), @@ -98,6 +98,8 @@ Song::Song() : m_loopRenderRemaining(1), m_oldAutomatedValues() { + m_globalAutomationTrack->setTrackContainer(this); + for (double& millisecondsElapsed : m_elapsedMilliSeconds) { millisecondsElapsed = 0; } connect( &m_tempoModel, SIGNAL(dataChanged()), this, SLOT(setTempo()), Qt::DirectConnection ); @@ -806,7 +808,7 @@ void Song::removeBar() void Song::addPatternTrack() { - const auto patternTrack = addTrack(this); + const auto patternTrack = addTrack(); Engine::patternStore()->setCurrentPattern(static_cast(patternTrack)->patternIndex()); } @@ -815,7 +817,7 @@ void Song::addPatternTrack() void Song::addSampleTrack() { - addTrack(this); + addTrack(); } @@ -823,7 +825,7 @@ void Song::addSampleTrack() void Song::addAutomationTrack() { - addTrack(this); + addTrack(); } @@ -956,15 +958,15 @@ void Song::createNewProject() m_oldFileName = ""; setProjectFileName(""); - auto tripleOscTrack = addTrack(this); + auto tripleOscTrack = addTrack(); static_cast(tripleOscTrack)->loadInstrument("tripleoscillator"); - auto kickerTrack = Engine::patternStore()->addTrack(Engine::patternStore()); + auto kickerTrack = Engine::patternStore()->addTrack(); static_cast(kickerTrack)->loadInstrument("kicker"); - addTrack(this); - addTrack(this); - addTrack(this); + addTrack(); + addTrack(); + addTrack(); m_tempoModel.setInitValue( DefaultTempo ); m_timeSigModel.reset(); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index d80d3618338..03d54f31680 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -56,9 +56,9 @@ namespace lmms * * \todo check the definitions of all the properties - are they OK? */ -Track::Track( Type type, TrackContainer * tc ) : - Model( tc ), /*!< The track Model */ - m_trackContainer( tc ), /*!< The track container object */ +Track::Track(Type type) : + Model(nullptr), /*!< The track Model */ + m_trackContainer(), /*!< The track container object */ m_type( type ), /*!< The track type */ m_name(), /*!< The track's name */ m_mutedModel( false, this, tr( "Mute" ) ), /*!< For controlling track muting */ diff --git a/src/core/TrackContainer.cpp b/src/core/TrackContainer.cpp index 1557c736068..a7f227271f2 100644 --- a/src/core/TrackContainer.cpp +++ b/src/core/TrackContainer.cpp @@ -183,18 +183,18 @@ Track* TrackContainer::addTrack(const QDomElement& element) switch (trackType) { case Track::Type::Instrument: - track = addTrack(this); + track = addTrack(); break; case Track::Type::Pattern: - track = addTrack(this); + track = addTrack(); break; case Track::Type::Sample: - track = addTrack(this); + track = addTrack(); break; case Track::Type::HiddenAutomation: [[fallthrough]]; case Track::Type::Automation: - track = addTrack(this); + track = addTrack(); break; default: std::cerr << "TrackContainer::addTrack - unimplemented type\n"; diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index 667669afad1..cbefc7c5532 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -941,7 +941,7 @@ void FileBrowserTreeWidget::activateListItem(QTreeWidgetItem * item, } else if( f->handling() != FileItem::FileHandling::NotSupported ) { - auto it = Engine::patternStore()->addTrack(Engine::patternStore()); + auto it = Engine::patternStore()->addTrack(); handleFile( f, it ); } } @@ -953,7 +953,7 @@ void FileBrowserTreeWidget::openInNewInstrumentTrack(TrackContainer* tc, FileIte { if(item->isTrack()) { - auto it = tc->addTrack(tc); + auto it = tc->addTrack(); handleFile(item, it); } } @@ -978,7 +978,7 @@ bool FileBrowserTreeWidget::openInNewSampleTrack(FileItem* item) if (item->type() != FileItem::FileType::Sample) { return false; } // Create a new sample track for this sample - auto sampleTrack = Engine::getSong()->addTrack(Engine::getSong()); + auto sampleTrack = Engine::getSong()->addTrack(); // Add the sample clip to the track Engine::audioEngine()->requestChangeInModel(); diff --git a/src/gui/PluginBrowser.cpp b/src/gui/PluginBrowser.cpp index 0bb9439c53e..967f739bddf 100644 --- a/src/gui/PluginBrowser.cpp +++ b/src/gui/PluginBrowser.cpp @@ -306,7 +306,7 @@ void PluginDescWidget::contextMenuEvent(QContextMenuEvent* e) void PluginDescWidget::openInNewInstrumentTrack(QString value) { TrackContainer* tc = Engine::getSong(); - auto it = tc->addTrack(tc); + auto it = tc->addTrack(); auto ilt = new InstrumentLoaderThread(this, it, value); ilt->start(); } diff --git a/src/gui/editors/PatternEditor.cpp b/src/gui/editors/PatternEditor.cpp index 32e2a036219..ddeac422aca 100644 --- a/src/gui/editors/PatternEditor.cpp +++ b/src/gui/editors/PatternEditor.cpp @@ -87,7 +87,7 @@ void PatternEditor::removeSteps() void PatternEditor::addSampleTrack() { - model()->addTrack(model()); + model()->addTrack(); } @@ -95,7 +95,7 @@ void PatternEditor::addSampleTrack() void PatternEditor::addAutomationTrack() { - model()->addTrack(model()); + model()->addTrack(); } diff --git a/src/gui/editors/TrackContainerView.cpp b/src/gui/editors/TrackContainerView.cpp index d5ae6e101c9..e5821ba841e 100644 --- a/src/gui/editors/TrackContainerView.cpp +++ b/src/gui/editors/TrackContainerView.cpp @@ -395,7 +395,7 @@ void TrackContainerView::dropEvent( QDropEvent * _de ) QString value = StringPairDrag::decodeValue( _de ); if( type == "instrument" ) { - auto it = m_tc->addTrack(m_tc); + auto it = m_tc->addTrack(); auto ilt = new InstrumentLoaderThread(this, it, value); ilt->start(); //it->toggledInstrumentTrackButton( true ); @@ -405,7 +405,7 @@ void TrackContainerView::dropEvent( QDropEvent * _de ) || type == "soundfontfile" || type == "vstpluginfile" || type == "patchfile" ) { - auto it = m_tc->addTrack(m_tc); + auto it = m_tc->addTrack(); PluginFactory::PluginInfoAndKey piakn = getPluginFactory()->pluginSupportingExtension(FileItem::extension(value)); Instrument * i = it->loadInstrument(piakn.info.name(), &piakn.key); @@ -416,7 +416,7 @@ void TrackContainerView::dropEvent( QDropEvent * _de ) else if( type == "presetfile" ) { DataFile dataFile( value ); - auto it = m_tc->addTrack(m_tc); + auto it = m_tc->addTrack(); it->loadPreset(dataFile.content().toElement()); //it->toggledInstrumentTrackButton( true ); diff --git a/src/tracks/AutomationTrack.cpp b/src/tracks/AutomationTrack.cpp index 333f6fc5ad2..8d5e6c31ec0 100644 --- a/src/tracks/AutomationTrack.cpp +++ b/src/tracks/AutomationTrack.cpp @@ -32,9 +32,8 @@ namespace lmms { - -AutomationTrack::AutomationTrack( TrackContainer* tc, bool _hidden ) : - Track( _hidden ? Type::HiddenAutomation : Type::Automation, tc ) +AutomationTrack::AutomationTrack(bool hidden) + : Track(hidden ? Type::HiddenAutomation : Type::Automation) { setName( tr( "Automation track" ) ); } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 6355665fc73..ba3305eb21d 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -46,8 +46,8 @@ namespace lmms { -InstrumentTrack::InstrumentTrack( TrackContainer* tc ) : - Track( Track::Type::Instrument, tc ), +InstrumentTrack::InstrumentTrack() : + Track(Track::Type::Instrument), MidiEventProcessor(), m_midiPort( tr( "unnamed_track" ), Engine::audioEngine()->midiClient(), this, this ), diff --git a/src/tracks/PatternTrack.cpp b/src/tracks/PatternTrack.cpp index 6708399cac1..007e873d175 100644 --- a/src/tracks/PatternTrack.cpp +++ b/src/tracks/PatternTrack.cpp @@ -40,8 +40,8 @@ namespace lmms PatternTrack::infoMap PatternTrack::s_infoMap; -PatternTrack::PatternTrack(TrackContainer* tc) : - Track(Track::Type::Pattern, tc) +PatternTrack::PatternTrack() : + Track(Track::Type::Pattern) { int patternNum = s_infoMap.size(); s_infoMap[this] = patternNum; diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index ad50f6b349c..ef4410159b8 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -44,8 +44,8 @@ namespace lmms { -SampleTrack::SampleTrack(TrackContainer* tc) : - Track(Track::Type::Sample, tc), +SampleTrack::SampleTrack() : + Track(Track::Type::Sample), m_volumeModel(DefaultVolume, MinVolume, MaxVolume, 0.1f, this, tr("Volume")), m_panningModel(DefaultPanning, PanningLeft, PanningRight, 0.1f, this, tr("Panning")), m_mixerChannelModel(0, 0, 0, this, tr("Mixer channel")), diff --git a/tests/src/tracks/AutomationTrackTest.cpp b/tests/src/tracks/AutomationTrackTest.cpp index aafbea1bbf8..e686f11cc0b 100644 --- a/tests/src/tracks/AutomationTrackTest.cpp +++ b/tests/src/tracks/AutomationTrackTest.cpp @@ -94,7 +94,7 @@ private slots: FloatModel model; auto song = Engine::getSong(); - auto track = song->addTrack(song); + auto track = song->addTrack(); auto c1 = static_cast(track->createClip()); c1->setProgressionType(AutomationClip::ProgressionType::Linear); @@ -130,7 +130,7 @@ private slots: FloatModel model; auto song = Engine::getSong(); - auto track = song->addTrack(song); + auto track = song->addTrack(); auto c = static_cast(track->createClip()); c->setProgressionType(AutomationClip::ProgressionType::Linear); @@ -155,7 +155,7 @@ private slots: using namespace lmms; auto song = Engine::getSong(); - auto instrumentTrack = song->addTrack(song); + auto instrumentTrack = song->addTrack(); auto midiClip = static_cast(instrumentTrack->createClip()); midiClip->changeLength(TimePos(4, 0)); @@ -180,8 +180,8 @@ private slots: auto song = Engine::getSong(); auto patternStore = Engine::patternStore(); - auto patternTrack = song->addTrack(song); - auto automationTrack = patternStore->addTrack(patternStore); + auto patternTrack = song->addTrack(); + auto automationTrack = patternStore->addTrack(); automationTrack->createClipsForPattern(patternStore->numOfPatterns() - 1); QVERIFY(automationTrack->numOfClips()); @@ -200,7 +200,7 @@ private slots: QCOMPARE(patternStore->automatedValuesAt(10, patternTrack->patternIndex())[&model], 1.0f); QCOMPARE(patternStore->automatedValuesAt(50, patternTrack->patternIndex())[&model], 1.0f); - auto patternTrack2 = song->addTrack(song); + auto patternTrack2 = song->addTrack(); QCOMPARE(patternStore->automatedValuesAt(5, patternTrack->patternIndex())[&model], 0.5f); QVERIFY(! patternStore->automatedValuesAt(5, patternTrack2->patternIndex()).size()); @@ -225,7 +225,7 @@ private slots: auto globalTrack = song->globalAutomationTrack(); auto globalClip = static_cast(globalTrack->createClip()); - auto localTrack = song->addTrack(song); + auto localTrack = song->addTrack(); auto localClip = static_cast(localTrack->createClip()); FloatModel model;