From 441fd905bee745a56de6f838812584306daa6add Mon Sep 17 00:00:00 2001 From: Sotonye Atemie Date: Mon, 9 Feb 2026 11:57:28 -0500 Subject: [PATCH] Improve performance when moving channels in the Mixer (#8235) Improves performance when moving mixer channels to the left or right using simple Qt layout operations and swapping of values. This commit also addresses a deadlock in Mixer::mixToChannel by ensuring we lock and unlock the same channel regardless of any move operations occurring simultaneously on another thread. --- include/MixerChannelView.h | 1 + include/MixerView.h | 1 - src/core/Mixer.cpp | 11 +++++----- src/gui/MixerChannelView.cpp | 6 ------ src/gui/MixerView.cpp | 39 ++++++++++++++---------------------- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/include/MixerChannelView.h b/include/MixerChannelView.h index 1b2fa3953..6f2217012 100644 --- a/include/MixerChannelView.h +++ b/include/MixerChannelView.h @@ -64,6 +64,7 @@ public: void keyPressEvent(QKeyEvent* ke) override; void reset(); + int channelIndex() const { return m_channelIndex; } void setChannelIndex(int index); diff --git a/include/MixerView.h b/include/MixerView.h index f5f98b62a..6d9fded64 100644 --- a/include/MixerView.h +++ b/include/MixerView.h @@ -83,7 +83,6 @@ public: // move the channel to the left or right void moveChannelLeft(int index); - void moveChannelLeft(int index, int focusIndex); void moveChannelRight(int index); void renameChannel(int index); diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 6007be466..156987336 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -644,12 +644,13 @@ FloatModel * Mixer::channelSendModel( mix_ch_t fromChannel, mix_ch_t toChannel ) void Mixer::mixToChannel( const SampleFrame* _buf, mix_ch_t _ch ) { - if( m_mixerChannels[_ch]->m_muteModel.value() == false ) + const auto channel = m_mixerChannels[_ch]; + if (!channel->m_muteModel.value()) { - m_mixerChannels[_ch]->m_lock.lock(); - MixHelpers::add( m_mixerChannels[_ch]->m_buffer, _buf, Engine::audioEngine()->framesPerPeriod() ); - m_mixerChannels[_ch]->m_hasInput = true; - m_mixerChannels[_ch]->m_lock.unlock(); + channel->m_lock.lock(); + MixHelpers::add(channel->m_buffer, _buf, Engine::audioEngine()->framesPerPeriod()); + channel->m_hasInput = true; + channel->m_lock.unlock(); } } diff --git a/src/gui/MixerChannelView.cpp b/src/gui/MixerChannelView.cpp index d3de94bef..26b2aa94c 100644 --- a/src/gui/MixerChannelView.cpp +++ b/src/gui/MixerChannelView.cpp @@ -249,13 +249,7 @@ void MixerChannelView::keyPressEvent(QKeyEvent* ke) void MixerChannelView::setChannelIndex(int index) { - MixerChannel* mixerChannel = Engine::mixer()->mixerChannel(index); - m_fader->setModel(&mixerChannel->m_volumeModel); - m_muteButton->setModel(&mixerChannel->m_muteModel); - m_soloButton->setModel(&mixerChannel->m_soloModel); - m_effectRackView->setModel(&mixerChannel->m_fxChain); m_channelNumberLcd->setValue(index); - m_renameLineEdit->setText(elideName(mixerChannel->m_name)); m_channelIndex = index; } diff --git a/src/gui/MixerView.cpp b/src/gui/MixerView.cpp index 299f1bff5..ef1f35a20 100644 --- a/src/gui/MixerView.cpp +++ b/src/gui/MixerView.cpp @@ -433,38 +433,29 @@ void MixerView::deleteUnusedChannels() } } - - -void MixerView::moveChannelLeft(int index, int focusIndex) -{ - // can't move master or first channel left or last channel right - if (index <= 1 || index >= m_mixerChannelViews.size()) return; - - Mixer *m = getMixer(); - - // Move instruments channels - m->moveChannelLeft(index); - - // Update widgets models - m_mixerChannelViews[index]->setChannelIndex(index); - m_mixerChannelViews[index - 1]->setChannelIndex(index - 1); - - // Focus on new position - setCurrentMixerChannel(focusIndex); -} - - - void MixerView::moveChannelLeft(int index) { - moveChannelLeft(index, index - 1); + // can't move master or first channel left or last channel right + if (index <= 1 || index >= m_mixerChannelViews.size()) { return; } + + m_mixer->moveChannelLeft(index); + + const auto layoutIndex = chLayout->indexOf(m_mixerChannelViews[index]); + assert(layoutIndex >= 1); + + chLayout->removeWidget(m_mixerChannelViews[index]); + chLayout->insertWidget(layoutIndex - 1, m_mixerChannelViews[index]); + + m_mixerChannelViews[index]->setChannelIndex(index - 1); + m_mixerChannelViews[index - 1]->setChannelIndex(index); + std::swap(m_mixerChannelViews[index - 1], m_mixerChannelViews[index]); } void MixerView::moveChannelRight(int index) { - moveChannelLeft(index + 1, index + 1); + moveChannelLeft(index + 1); }