Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set sample clips for valid files #7224

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 14 additions & 9 deletions src/gui/clips/SampleClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ void SampleClipView::dropEvent( QDropEvent * _de )
m_clip->updateLength();
update();
_de->accept();
Engine::getSong()->setModified();
}
else
{
Expand Down Expand Up @@ -183,16 +182,22 @@ void SampleClipView::mouseDoubleClickEvent( QMouseEvent * )
{
QString af = SampleLoader::openAudioFile();

if ( af.isEmpty() ) {} //Don't do anything if no file is loaded
else if (af == m_clip->m_sample.sampleFile())
{ //Instead of reloading the existing file, just reset the size
int length = static_cast<int>(m_clip->m_sample.sampleSize() / Engine::framesPerTick());
m_clip->changeLength(length);
// Don't do anything if no file is loaded
if (af.isEmpty()) { return; }

if (af == m_clip->m_sample.sampleFile())
{
// Don't reload the same file again. Just reset the size.
m_clip->changeLengthToSampleLength();
}
else
{ //Otherwise load the new file as ususal
m_clip->setSampleFile( af );
Engine::getSong()->setModified();
{
// Load the new file and set it for the clip
auto sampleBuffer = SampleLoader::createBufferFromFile(af);
if (sampleBuffer != SampleBuffer::emptyBuffer())
{
m_clip->setSampleBuffer(sampleBuffer);
}
}
}

Expand Down
Loading