From 609c008a710b1f4eee0433c5dc90c43589496b5b Mon Sep 17 00:00:00 2001 From: Bernhard <93736385+spechtstatt@users.noreply.github.com> Date: Mon, 13 Nov 2023 12:37:28 +0100 Subject: [PATCH] Keep master bus color on FX Mixer when switching project Fixes #6398 --- include/Mixer.h | 9 ++------- include/Track.h | 8 ++++---- src/core/Mixer.cpp | 7 +++---- src/core/Track.cpp | 14 ++++++-------- src/gui/MixerLine.cpp | 8 ++++---- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/include/Mixer.h b/include/Mixer.h index 35787a414..6e5a12786 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -31,7 +31,7 @@ #include "ThreadableJob.h" #include - +#include #include namespace lmms @@ -76,18 +76,13 @@ class MixerChannel : public ThreadableJob bool requiresProcessing() const override { return true; } void unmuteForSolo(); - void setColor (QColor newColor) { m_color = newColor; - m_hasColor = true; } - // TODO C++17 and above: use std::optional instead - QColor m_color; - bool m_hasColor; + std::optional m_color; - std::atomic_int m_dependenciesMet; void incrementDeps(); void processed(); diff --git a/include/Track.h b/include/Track.h index 33d1ad233..71c6b0457 100644 --- a/include/Track.h +++ b/include/Track.h @@ -32,6 +32,7 @@ #include "AutomatableModel.h" #include "JournallingObject.h" #include "lmms_basics.h" +#include namespace lmms @@ -191,11 +192,11 @@ public: QColor color() { - return m_color; + return m_color.value(); } bool useColor() { - return m_hasColor; + return m_color.has_value(); } bool isMutedBeforeSolo() const @@ -241,8 +242,7 @@ private: QMutex m_processingLock; - QColor m_color; - bool m_hasColor; + std::optional m_color; friend class gui::TrackView; diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 59c2dd72e..31212313d 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -72,7 +72,6 @@ MixerChannel::MixerChannel( int idx, Model * _parent ) : m_lock(), m_channelIndex( idx ), m_queued( false ), - m_hasColor( false ), m_dependenciesMet(0) { BufferManager::clear( m_buffer, Engine::audioEngine()->framesPerPeriod() ); @@ -722,6 +721,7 @@ void Mixer::clearChannel(mix_ch_t index) ch->m_volumeModel.setDisplayName( ch->m_name + ">" + tr( "Volume" ) ); ch->m_muteModel.setDisplayName( ch->m_name + ">" + tr( "Mute" ) ); ch->m_soloModel.setDisplayName( ch->m_name + ">" + tr( "Solo" ) ); + ch->m_color = std::nullopt; // send only to master if( index > 0) @@ -759,7 +759,7 @@ void Mixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) ch->m_soloModel.saveSettings( _doc, mixch, "soloed" ); mixch.setAttribute( "num", i ); mixch.setAttribute( "name", ch->m_name ); - if( ch->m_hasColor ) mixch.setAttribute( "color", ch->m_color.name() ); + if (ch->m_color.has_value()) { mixch.setAttribute("color", ch->m_color->name()); } // add the channel sends for (const auto& send : ch->m_sends) @@ -807,8 +807,7 @@ void Mixer::loadSettings( const QDomElement & _this ) m_mixerChannels[num]->m_name = mixch.attribute( "name" ); if( mixch.hasAttribute( "color" ) ) { - m_mixerChannels[num]->m_hasColor = true; - m_mixerChannels[num]->m_color.setNamedColor( mixch.attribute( "color" ) ); + m_mixerChannels[num]->m_color = QColor(mixch.attribute("color")); } m_mixerChannels[num]->m_fxChain.restoreState( mixch.firstChildElement( diff --git a/src/core/Track.cpp b/src/core/Track.cpp index b034b95fb..2d4a2d840 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -65,9 +65,8 @@ Track::Track( Type type, TrackContainer * tc ) : m_soloModel( false, this, tr( "Solo" ) ), /*!< For controlling track soloing */ m_simpleSerializingMode( false ), m_clips(), /*!< The clips (segments) */ - m_color( 0, 0, 0 ), - m_hasColor( false ) -{ + m_color(std::nullopt) +{ m_trackContainer->addTrack( this ); m_height = -1; } @@ -209,9 +208,9 @@ void Track::saveSettings( QDomDocument & doc, QDomElement & element ) element.setAttribute( "trackheight", m_height ); } - if( m_hasColor ) + if (m_color.has_value()) { - element.setAttribute( "color", m_color.name() ); + element.setAttribute("color", m_color->name()); } QDomElement tsDe = doc.createElement( nodeName() ); @@ -636,14 +635,13 @@ void Track::toggleSolo() void Track::setColor(const QColor& c) { - m_hasColor = true; m_color = c; emit colorChanged(); } void Track::resetColor() { - m_hasColor = false; + m_color = std::nullopt; emit colorChanged(); } @@ -653,4 +651,4 @@ BoolModel *Track::getMutedModel() return &m_mutedModel; } -} // namespace lmms \ No newline at end of file +} // namespace lmms diff --git a/src/gui/MixerLine.cpp b/src/gui/MixerLine.cpp index a90f13f83..d3435787e 100644 --- a/src/gui/MixerLine.cpp +++ b/src/gui/MixerLine.cpp @@ -174,9 +174,9 @@ void MixerLine::drawMixerLine( QPainter* p, const MixerLine *mixerLine, bool isA int width = mixerLine->rect().width(); int height = mixerLine->rect().height(); - if( channel->m_hasColor && !muted ) + if (channel->m_color.has_value() && !muted) { - p->fillRect( mixerLine->rect(), channel->m_color.darker( isActive ? 120 : 150 ) ); + p->fillRect(mixerLine->rect(), channel->m_color->darker(isActive ? 120 : 150)); } else { @@ -435,7 +435,7 @@ void MixerLine::setStrokeInnerInactive( const QColor & c ) void MixerLine::selectColor() { auto channel = Engine::mixer()->mixerChannel( m_channelIndex ); - auto new_color = ColorChooser(this).withPalette(ColorChooser::Palette::Mixer)->getColor(channel->m_color); + auto new_color = ColorChooser(this).withPalette(ColorChooser::Palette::Mixer)->getColor(channel->m_color.value_or(backgroundActive().color())); if(!new_color.isValid()) { return; } channel->setColor (new_color); Engine::getSong()->setModified(); @@ -446,7 +446,7 @@ void MixerLine::selectColor() // Disable the usage of color on this mixer line void MixerLine::resetColor() { - Engine::mixer()->mixerChannel( m_channelIndex )->m_hasColor = false; + Engine::mixer()->mixerChannel(m_channelIndex)->m_color = std::nullopt; Engine::getSong()->setModified(); update(); }