From 25e8b640d84a0d6cbe7dcd6153cbf0fcdda42d40 Mon Sep 17 00:00:00 2001 From: regulus79 <117475203+regulus79@users.noreply.github.com> Date: Mon, 2 Jun 2025 00:42:02 -0400 Subject: [PATCH] Update Sample Length when Loading New Sample via Double-Click (#7898) This PR makes it so that when you double-click on a sample clip and select a new sample, it will automatically update the length of the clip, as long as the clip has auto-resize enabled. --- include/SampleClip.h | 1 - src/core/SampleClip.cpp | 14 ++++++++------ src/gui/clips/SampleClipView.cpp | 7 ++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/SampleClip.h b/include/SampleClip.h index cbd3ac5d5..ea7853386 100644 --- a/include/SampleClip.h +++ b/include/SampleClip.h @@ -54,7 +54,6 @@ public: SampleClip& operator=( const SampleClip& that ) = delete; void changeLength( const TimePos & _length ) override; - void changeLengthToSampleLength(); const QString& sampleFile() const; bool hasSampleFileLoaded(const QString & filename) const; diff --git a/src/core/SampleClip.cpp b/src/core/SampleClip.cpp index 5c04287c4..11aabc2ff 100644 --- a/src/core/SampleClip.cpp +++ b/src/core/SampleClip.cpp @@ -152,12 +152,6 @@ void SampleClip::changeLength( const TimePos & _length ) Clip::changeLength(std::max(static_cast(_length), 1)); } -void SampleClip::changeLengthToSampleLength() -{ - int length = m_sample.sampleSize() / Engine::framesPerTick(); - changeLength(length); -} - const QString& SampleClip::sampleFile() const @@ -261,6 +255,14 @@ void SampleClip::setIsPlaying(bool isPlaying) void SampleClip::updateLength() { + // If the clip has already been manually resized, don't automatically resize it. + // Unless we are in a pattern, where you can't resize stuff manually + if (getAutoResize() || !getResizable()) + { + changeLength(sampleLength()); + setStartTimeOffset(0); + } + emit sampleChanged(); Engine::getSong()->setModified(); diff --git a/src/gui/clips/SampleClipView.cpp b/src/gui/clips/SampleClipView.cpp index b281e5304..df3726cbf 100644 --- a/src/gui/clips/SampleClipView.cpp +++ b/src/gui/clips/SampleClipView.cpp @@ -192,11 +192,7 @@ void SampleClipView::mouseDoubleClickEvent( QMouseEvent * ) if (selectedAudioFile.isEmpty()) { return; } - if (m_clip->hasSampleFileLoaded(selectedAudioFile)) - { - m_clip->changeLengthToSampleLength(); - } - else + if (!m_clip->hasSampleFileLoaded(selectedAudioFile)) { auto sampleBuffer = SampleLoader::createBufferFromFile(selectedAudioFile); if (sampleBuffer != SampleBuffer::emptyBuffer()) @@ -204,6 +200,7 @@ void SampleClipView::mouseDoubleClickEvent( QMouseEvent * ) m_clip->setSampleBuffer(sampleBuffer); } } + m_clip->updateLength(); }