diff --git a/include/AutomationTrack.h b/include/AutomationTrack.h index f7918cfb038..d010d0231c3 100644 --- a/include/AutomationTrack.h +++ b/include/AutomationTrack.h @@ -49,6 +49,7 @@ class AutomationTrack : public Track gui::TrackView * createView( gui::TrackContainerView* ) override; Clip* createClip() override; + bool canAddClip(Clip* clip) override; void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override; void loadTrackSpecificSettings( const QDomElement & _this ) override; diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index 0c5d162eff5..5caad67bdee 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -131,6 +131,7 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor // create new track-content-object = clip Clip* createClip() override; + bool canAddClip(Clip* clip) override; // called by track void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override; diff --git a/include/PatternTrack.h b/include/PatternTrack.h index 3cac3ae65a6..a05c25764a7 100644 --- a/include/PatternTrack.h +++ b/include/PatternTrack.h @@ -56,6 +56,7 @@ class LMMS_EXPORT PatternTrack : public Track const f_cnt_t _frame_base, int _clip_num = -1 ) override; gui::TrackView * createView( gui::TrackContainerView* tcv ) override; Clip* createClip() override; + bool canAddClip(Clip* clip) override; void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override; void loadTrackSpecificSettings( const QDomElement & _this ) override; diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 55feb03e7c1..63cd0ae8023 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -52,6 +52,7 @@ class SampleTrack : public Track const f_cnt_t _frame_base, int _clip_num = -1 ) override; gui::TrackView * createView( gui::TrackContainerView* tcv ) override; Clip* createClip() override; + bool canAddClip(Clip* clip) override; void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override; void loadTrackSpecificSettings( const QDomElement & _this ) override; diff --git a/include/Track.h b/include/Track.h index 7db19f1a8d2..a07f7324782 100644 --- a/include/Track.h +++ b/include/Track.h @@ -102,6 +102,7 @@ class LMMS_EXPORT Track : public Model, public JournallingObject virtual gui::TrackView * createView( gui::TrackContainerView * view ) = 0; virtual Clip* createClip() = 0; + virtual bool canAddClip(Clip* clip) = 0; virtual void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) = 0; virtual void loadTrackSpecificSettings( const QDomElement & element ) = 0; @@ -118,7 +119,10 @@ class LMMS_EXPORT Track : public Model, public JournallingObject T* addClip(Args&&... args) { static_assert(std::is_base_of_v, "T must be a kind of Clip"); + auto clip = new T(std::forward(args)...); + assert(canAddClip(clip) && "This clip cannot be added to this track (incompatible types?)"); + m_clips.push_back(clip); clip->setTrack(this); clip->onAddedToTrack(this); diff --git a/src/tracks/AutomationTrack.cpp b/src/tracks/AutomationTrack.cpp index 8d5e6c31ec0..36bc32afddd 100644 --- a/src/tracks/AutomationTrack.cpp +++ b/src/tracks/AutomationTrack.cpp @@ -62,6 +62,10 @@ Clip* AutomationTrack::createClip() +bool AutomationTrack::canAddClip(Clip* clip) +{ + return dynamic_cast(clip) != nullptr; +} void AutomationTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this, bool presetMode) { diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index ba3305eb21d..f4e5606f2c3 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -809,6 +809,10 @@ Clip* InstrumentTrack::createClip() } +bool InstrumentTrack::canAddClip(Clip* clip) +{ + return dynamic_cast(clip) != nullptr; +} gui::TrackView* InstrumentTrack::createView( gui::TrackContainerView* tcv ) diff --git a/src/tracks/PatternTrack.cpp b/src/tracks/PatternTrack.cpp index 007e873d175..f4f87d4a59c 100644 --- a/src/tracks/PatternTrack.cpp +++ b/src/tracks/PatternTrack.cpp @@ -150,6 +150,10 @@ Clip* PatternTrack::createClip() } +bool PatternTrack::canAddClip(Clip* clip) +{ + return dynamic_cast(clip) != nullptr; +} void PatternTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this, bool presetMode) diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index ef4410159b8..6b50cbb54c3 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -185,6 +185,10 @@ Clip * SampleTrack::createClip() +bool SampleTrack::canAddClip(Clip* clip) +{ + return dynamic_cast(clip) != nullptr; +} void SampleTrack::saveTrackSpecificSettings(QDomDocument& _doc, QDomElement& _this, bool presetMode) {