Skip to content

Commit

Permalink
Add canAddClip function to avoid coding errors (adding a clip to a ty…
Browse files Browse the repository at this point in the history
…pe of track where it should not be possible)
  • Loading branch information
sakertooth committed Dec 8, 2024
1 parent a0fa59f commit 46ba381
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/AutomationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/PatternTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -118,7 +119,10 @@ class LMMS_EXPORT Track : public Model, public JournallingObject
T* addClip(Args&&... args)
{
static_assert(std::is_base_of_v<Clip, T>, "T must be a kind of Clip");

auto clip = new T(std::forward<Args>(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);
Expand Down
4 changes: 4 additions & 0 deletions src/tracks/AutomationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Clip* AutomationTrack::createClip()



bool AutomationTrack::canAddClip(Clip* clip)
{
return dynamic_cast<AutomationClip*>(clip) != nullptr;
}

void AutomationTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this, bool presetMode)
{
Expand Down
4 changes: 4 additions & 0 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ Clip* InstrumentTrack::createClip()
}


bool InstrumentTrack::canAddClip(Clip* clip)
{
return dynamic_cast<MidiClip*>(clip) != nullptr;
}


gui::TrackView* InstrumentTrack::createView( gui::TrackContainerView* tcv )
Expand Down
4 changes: 4 additions & 0 deletions src/tracks/PatternTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ Clip* PatternTrack::createClip()
}


bool PatternTrack::canAddClip(Clip* clip)
{
return dynamic_cast<PatternClip*>(clip) != nullptr;
}


void PatternTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this, bool presetMode)
Expand Down
4 changes: 4 additions & 0 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ Clip * SampleTrack::createClip()



bool SampleTrack::canAddClip(Clip* clip)
{
return dynamic_cast<SampleClip*>(clip) != nullptr;
}

void SampleTrack::saveTrackSpecificSettings(QDomDocument& _doc, QDomElement& _this, bool presetMode)
{
Expand Down

0 comments on commit 46ba381

Please sign in to comment.