Skip to content

Commit

Permalink
Add SampleClip::hasSampleFileLoaded
Browse files Browse the repository at this point in the history
Add the method `SampleClip::hasSampleFileLoaded` and remove some comments.
  • Loading branch information
michaelgregorius committed Apr 29, 2024
1 parent ef681e1 commit 4d5bf7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/SampleClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SampleClip : public Clip
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
5 changes: 5 additions & 0 deletions src/core/SampleClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,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 Down
11 changes: 4 additions & 7 deletions src/gui/clips/SampleClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,17 @@ void SampleClipView::mouseReleaseEvent(QMouseEvent *_me)

void SampleClipView::mouseDoubleClickEvent( QMouseEvent * )
{
QString af = SampleLoader::openAudioFile();
const QString selectedAudioFile = SampleLoader::openAudioFile();

// Don't do anything if no file is loaded
if (af.isEmpty()) { return; }
if (selectedAudioFile.isEmpty()) { return; }

if (af == m_clip->m_sample.sampleFile())
if (m_clip->hasSampleFileLoaded(selectedAudioFile))
{
// Don't reload the same file again. Just reset the size.
m_clip->changeLengthToSampleLength();
}
else
{
// Load the new file and set it for the clip
auto sampleBuffer = SampleLoader::createBufferFromFile(af);
auto sampleBuffer = SampleLoader::createBufferFromFile(selectedAudioFile);
if (sampleBuffer != SampleBuffer::emptyBuffer())
{
m_clip->setSampleBuffer(sampleBuffer);
Expand Down

0 comments on commit 4d5bf7c

Please sign in to comment.