Skip to content

Commit

Permalink
Factor out common code
Browse files Browse the repository at this point in the history
  • Loading branch information
pljones committed Oct 4, 2024
1 parent 3144e75 commit b1eda2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
18 changes: 6 additions & 12 deletions src/audiomixerboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,22 +1335,16 @@ void CAudioMixerBoard::ApplyNewConClientList ( CVector<CChannelInfo>& vecChanInf

void CAudioMixerBoard::SetFaderLevel ( const int iChannelIdx, const int iValue )
{
// only apply new fader level if channel index is valid and the fader is visible
if ( ( iChannelIdx >= 0 ) && ( iChannelIdx < MAX_NUM_CHANNELS ) )
{
if ( vecpChanFader[static_cast<size_t> ( iChannelIdx )]->IsVisible() )
{
vecpChanFader[static_cast<size_t> ( iChannelIdx )]->SetFaderLevel ( iValue );
}
}
// Proposed change: if iChannelIdx is -1 and our own channel ID is a valid index
// then we adjust our own fader level:
if((iChannelIdx == -1) && iMyChannelID != INVALID_INDEX)
const int iTheChannelIdx = ( iChannelIdx == INVALID_INDEX ) ? iMyChannelID : iChannelIdx;

// only apply new fader level if channel index is valid and the fader is visible
if ( ( iTheChannelIdx >= 0 ) && ( iTheChannelIdx < MAX_NUM_CHANNELS ) )
{
if ( vecpChanFader[static_cast<size_t> ( iMyChannelID )]->IsVisible() )
if ( vecpChanFader[static_cast<size_t> ( iTheChannelIdx )]->IsVisible() )
{
//printf("debug: set our own fader(%d) level to %d\n", iMyChannelID, iValue);
vecpChanFader[static_cast<size_t> ( iMyChannelID )]->SetFaderLevel ( iValue );
vecpChanFader[static_cast<size_t> ( iTheChannelIdx )]->SetFaderLevel ( iValue );
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/sound/soundbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,16 @@ void CSoundBase::ParseMIDIMessage ( const CVector<uint8_t>& vMIDIPaketBytes )
switch ( cCtrl.eType )
{
case Fader:
case OurFader:
{
// we are assuming that the controller number is the same
// as the audio fader index and the range is 0-127
const int iFaderLevel = static_cast<int> ( static_cast<double> ( iValue ) / 127 * AUD_MIX_FADER_MAX );
const int iTheChannel = cCtrl.eType == OurFader ? INVALID_INDEX : cCtrl.iChannel;

// consider offset for the faders

emit ControllerInFaderLevel ( cCtrl.iChannel, iFaderLevel );
}
break;
case OurFader:
{
// special message about our own fader - emit a fader level whatever-it-is-called with channel id -1
const int iFaderLevel = static_cast<int> ( static_cast<double> ( iValue ) / 127*AUD_MIX_FADER_MAX );
emit ControllerInFaderLevel ( -1, iFaderLevel);
emit ControllerInFaderLevel ( iTheChannel, iFaderLevel );
}
break;
case Pan:
Expand Down

0 comments on commit b1eda2e

Please sign in to comment.