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 all 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
2 changes: 2 additions & 0 deletions include/SampleClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class SampleClip : public Clip
SampleClip& operator=( const SampleClip& that ) = delete;

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

void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
void loadSettings( const QDomElement & _this ) override;
Expand Down
14 changes: 14 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 = m_sample.sampleSize() / Engine::framesPerTick();
changeLength(length);
}



Expand All @@ -120,6 +125,11 @@ const QString& SampleClip::sampleFile() const
return m_sample.sampleFile();
}

bool SampleClip::hasSampleFileLoaded(const QString & filename) const
{
return m_sample.sampleFile() == filename;
}

void SampleClip::setSampleBuffer(std::shared_ptr<const SampleBuffer> sb)
{
{
Expand All @@ -129,6 +139,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 +222,8 @@ void SampleClip::setIsPlaying(bool isPlaying)
void SampleClip::updateLength()
{
emit sampleChanged();

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


Expand Down
22 changes: 12 additions & 10 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 @@ -181,18 +180,21 @@ void SampleClipView::mouseReleaseEvent(QMouseEvent *_me)

void SampleClipView::mouseDoubleClickEvent( QMouseEvent * )
{
QString af = SampleLoader::openAudioFile();
const QString selectedAudioFile = 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);
if (selectedAudioFile.isEmpty()) { return; }

if (m_clip->hasSampleFileLoaded(selectedAudioFile))
{
m_clip->changeLengthToSampleLength();
}
else
{ //Otherwise load the new file as ususal
m_clip->setSampleFile( af );
Engine::getSong()->setModified();
{
auto sampleBuffer = SampleLoader::createBufferFromFile(selectedAudioFile);
if (sampleBuffer != SampleBuffer::emptyBuffer())
{
m_clip->setSampleBuffer(sampleBuffer);
}
}
}

Expand Down
Loading