Skip to content

Commit

Permalink
Encapsulate mixer channel index
Browse files Browse the repository at this point in the history
Make the mixer channel index `m_channelIndex` private and add getters and
setters. Also add a method to determine if the channel is the master
channel.

Move `m_channelIndex` to the end of the initialization list of the
`MixerChannel` constructor because it is now the last member in the
header.

Adjust all clients to make use of the new methods.
  • Loading branch information
michaelgregorius committed Oct 7, 2024
1 parent 8e460a0 commit a2600bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
12 changes: 9 additions & 3 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class MixerChannel : public ThreadableJob
FloatModel m_volumeModel;
QString m_name;
QMutex m_lock;
int m_channelIndex; // what channel index are we
bool m_queued; // are we queued up for rendering yet?
bool m_muted; // are we muted? updated per period so we don't have to call m_muteModel.value() twice

Expand All @@ -73,6 +72,11 @@ class MixerChannel : public ThreadableJob
// pointers to other channels that send to this one
MixerRouteVector m_receives;

const int & getIndex() { return m_channelIndex; }
void setIndex(int index) { m_channelIndex = index; }

bool isMaster() { return m_channelIndex == 0; }

bool requiresProcessing() const override { return true; }
void unmuteForSolo();
void unmuteSenderForSolo();
Expand All @@ -88,6 +92,8 @@ class MixerChannel : public ThreadableJob
private:
void doProcessing() override;

private:
int m_channelIndex;
std::optional<QColor> m_color;
};

Expand All @@ -100,12 +106,12 @@ class MixerRoute : public QObject

mix_ch_t senderIndex() const
{
return m_from->m_channelIndex;
return m_from->getIndex();
}

mix_ch_t receiverIndex() const
{
return m_to->m_channelIndex;
return m_to->getIndex();
}

FloatModel * amount()
Expand Down
20 changes: 10 additions & 10 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ MixerRoute::MixerRoute( MixerChannel * from, MixerChannel * to, float amount ) :
m_from( from ),
m_to( to ),
m_amount(amount, 0, 1, 0.001f, nullptr,
tr("Amount to send from channel %1 to channel %2").arg(m_from->m_channelIndex).arg(m_to->m_channelIndex))
tr("Amount to send from channel %1 to channel %2").arg(m_from->getIndex()).arg(m_to->getIndex()))
{
//qDebug( "created: %d to %d", m_from->m_channelIndex, m_to->m_channelIndex );
// create send amount model
Expand All @@ -54,7 +54,7 @@ MixerRoute::MixerRoute( MixerChannel * from, MixerChannel * to, float amount ) :
void MixerRoute::updateName()
{
m_amount.setDisplayName(
tr( "Amount to send from channel %1 to channel %2" ).arg( m_from->m_channelIndex ).arg( m_to->m_channelIndex ) );
tr("Amount to send from channel %1 to channel %2").arg(m_from->getIndex()).arg(m_to->getIndex()));
}


Expand All @@ -70,9 +70,9 @@ MixerChannel::MixerChannel( int idx, Model * _parent ) :
m_volumeModel(1.f, 0.f, 2.f, 0.001f, _parent),
m_name(),
m_lock(),
m_channelIndex( idx ),
m_queued( false ),
m_dependenciesMet(0)
m_dependenciesMet(0),
m_channelIndex(idx)
{
zeroSampleFrames(m_buffer, Engine::audioEngine()->framesPerPeriod());
}
Expand Down Expand Up @@ -112,7 +112,7 @@ void MixerChannel::unmuteForSolo()
m_muteModel.setValue(false);

// if channel is not master, unmute also every channel it sends to/receives from
if (m_channelIndex != 0)
if (!isMaster())
{
for (const MixerRoute* sendsRoute : m_sends)
{
Expand All @@ -130,7 +130,7 @@ void MixerChannel::unmuteSenderForSolo()
m_muteModel.setValue(false);

// if channel is not master, unmute every channel it sends to
if (m_channelIndex != 0)
if (!isMaster())
{
for (const MixerRoute* sendsRoute : m_sends)
{
Expand All @@ -145,7 +145,7 @@ void MixerChannel::unmuteReceiverForSolo()
m_muteModel.setValue(false);

// if channel is not master, unmute every channel it receives from, and of those, unmute the channels they send to
if (m_channelIndex != 0)
if (!isMaster())
{
for (const MixerRoute* receiverRoute : m_receives)
{
Expand Down Expand Up @@ -405,7 +405,7 @@ void Mixer::deleteChannel( int index )
validateChannelName( i, i + 1 );

// set correct channel index
m_mixerChannels[i]->m_channelIndex = i;
m_mixerChannels[i]->setIndex(i);

// now check all routes and update names of the send models
for( MixerRoute * r : m_mixerChannels[i]->m_sends )
Expand Down Expand Up @@ -478,8 +478,8 @@ void Mixer::moveChannelLeft( int index )
qSwap(m_mixerChannels[index], m_mixerChannels[index - 1]);

// Update m_channelIndex of both channels
m_mixerChannels[index]->m_channelIndex = index;
m_mixerChannels[index - 1]->m_channelIndex = index -1;
m_mixerChannels[index]->setIndex(index);
m_mixerChannels[index - 1]->setIndex(index - 1);
}


Expand Down
4 changes: 2 additions & 2 deletions src/gui/tracks/InstrumentTrackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ QMenu * InstrumentTrackView::createMixerMenu(QString title, QString newMixerLabe

if ( currentChannel != mixerChannel )
{
auto index = currentChannel->m_channelIndex;
QString label = tr( "%1: %2" ).arg( currentChannel->m_channelIndex ).arg( currentChannel->m_name );
auto index = currentChannel->getIndex();
QString label = tr( "%1: %2" ).arg(index).arg(currentChannel->m_name);
mixerMenu->addAction(label, [this, index](){
assignMixerLine(index);
});
Expand Down
4 changes: 2 additions & 2 deletions src/gui/tracks/SampleTrackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ QMenu * SampleTrackView::createMixerMenu(QString title, QString newMixerLabel)

if (currentChannel != mixerChannel)
{
const auto index = currentChannel->m_channelIndex;
QString label = tr("%1: %2").arg(currentChannel->m_channelIndex).arg(currentChannel->m_name);
const auto index = currentChannel->getIndex();
QString label = tr("%1: %2").arg(index).arg(currentChannel->m_name);
mixerMenu->addAction(label, [this, index](){
assignMixerLine(index);
});
Expand Down

0 comments on commit a2600bf

Please sign in to comment.