Skip to content

Commit

Permalink
Keep master bus color on FX Mixer when switching project
Browse files Browse the repository at this point in the history
Fixes #6398
  • Loading branch information
spechtstatt authored Nov 13, 2023
1 parent ecc5ff8 commit 609c008
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
9 changes: 2 additions & 7 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "ThreadableJob.h"

#include <atomic>

#include <optional>
#include <QColor>

namespace lmms
Expand Down Expand Up @@ -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<QColor> m_color;


std::atomic_int m_dependenciesMet;
void incrementDeps();
void processed();
Expand Down
8 changes: 4 additions & 4 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "AutomatableModel.h"
#include "JournallingObject.h"
#include "lmms_basics.h"
#include <optional>


namespace lmms
Expand Down Expand Up @@ -191,11 +192,11 @@ class LMMS_EXPORT Track : public Model, public JournallingObject

QColor color()
{
return m_color;
return m_color.value();
}
bool useColor()
{
return m_hasColor;
return m_color.has_value();
}

bool isMutedBeforeSolo() const
Expand Down Expand Up @@ -241,8 +242,7 @@ public slots:

QMutex m_processingLock;

QColor m_color;
bool m_hasColor;
std::optional<QColor> m_color;

friend class gui::TrackView;

Expand Down
7 changes: 3 additions & 4 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 6 additions & 8 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
}

Expand All @@ -653,4 +651,4 @@ BoolModel *Track::getMutedModel()
return &m_mutedModel;
}

} // namespace lmms
} // namespace lmms
8 changes: 4 additions & 4 deletions src/gui/MixerLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down

0 comments on commit 609c008

Please sign in to comment.