Skip to content

Commit

Permalink
Set "song modified" flag in core
Browse files Browse the repository at this point in the history
Move setting the song to modified towards the core in the context of `SampleClip`. Previously the `SampleClipView` did this but it's none of it's business.

Introduce `SampleClip::changeLengthToSampleLength` which changes the length of the clip to the length of the sample. This was also previously done by the view which is again the wrong place to do the necessary calculations.
  • Loading branch information
michaelgregorius committed Apr 27, 2024
1 parent fe95000 commit 14ce3cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/SampleClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SampleClip : public Clip
SampleClip& operator=( const SampleClip& that ) = delete;

void changeLength( const TimePos & _length ) override;
void changeLengthToSampleLength();
const QString& sampleFile() const;

void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
Expand Down
9 changes: 9 additions & 0 deletions src/core/SampleClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ void SampleClip::changeLength( const TimePos & _length )
Clip::changeLength(std::max(static_cast<int>(_length), 1));
}

void SampleClip::changeLengthToSampleLength()
{
int length = static_cast<int>(m_sample.sampleSize() / Engine::framesPerTick());
changeLength(length);
}



Expand All @@ -129,6 +134,8 @@ void SampleClip::setSampleBuffer(std::shared_ptr<const SampleBuffer> sb)
updateLength();

emit sampleChanged();

Engine::getSong()->setModified();
}

void SampleClip::setSampleFile(const QString& sf)
Expand Down Expand Up @@ -210,6 +217,8 @@ void SampleClip::setIsPlaying(bool isPlaying)
void SampleClip::updateLength()
{
emit sampleChanged();

Engine::getSong()->setModified();
}


Expand Down
7 changes: 1 addition & 6 deletions src/gui/clips/SampleClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void SampleClipView::dropEvent( QDropEvent * _de )
m_clip->updateLength();
update();
_de->accept();
Engine::getSong()->setModified();
}
else
{
Expand Down Expand Up @@ -190,8 +189,7 @@ void SampleClipView::mouseDoubleClickEvent( QMouseEvent * )
if (af == m_clip->m_sample.sampleFile())
{
// Don't reload the same file again. Just reset the size.
int length = static_cast<int>(m_clip->m_sample.sampleSize() / Engine::framesPerTick());
m_clip->changeLength(length);
m_clip->changeLengthToSampleLength();
}
else
{
Expand All @@ -200,9 +198,6 @@ void SampleClipView::mouseDoubleClickEvent( QMouseEvent * )
if (sampleBuffer != SampleBuffer::emptyBuffer())
{
m_clip->setSampleBuffer(sampleBuffer);

// TODO Why do we have to do this here? This should happen in the core...
Engine::getSong()->setModified();
}
}
}
Expand Down

0 comments on commit 14ce3cc

Please sign in to comment.