Skip to content

Commit

Permalink
More generic structure for responding to MIDI controller messages
Browse files Browse the repository at this point in the history
This is preparation for continuing work on issue jamulussoftware#95.  While it does
not yet introduce functional differences, MIDI controller information
is organised in a manner where reacting to more than just fader
control messages becomes easy.

The preparation right now is for controllers of type fader, pan, solo,
mute but can be easily extended for other messages arriving on a
single channel.
  • Loading branch information
dakhubgit committed Feb 10, 2021
1 parent 35f677b commit f440a8b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
45 changes: 34 additions & 11 deletions src/soundbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CSoundBase::CSoundBase ( const QString& strNewSystemDriverTechniqueName,
bCallbackEntered ( false ),
strSystemDriverTechniqueName ( strNewSystemDriverTechniqueName ),
iCtrlMIDIChannel ( INVALID_MIDI_CH ),
iMIDIOffsetFader ( 70 ) // Behringer X-TOUCH: offset of 0x46
aMidiCtls ( 128 )
{
// parse the MIDI setup command line argument string
ParseCommandLineArgument ( strMIDISetup );
Expand Down Expand Up @@ -234,7 +234,12 @@ QVector<QString> CSoundBase::LoadAndInitializeFirstValidDriver ( const bool bOpe
\******************************************************************************/
void CSoundBase::ParseCommandLineArgument ( const QString& strMIDISetup )
{
// parse the server info string according to definition:
int iMIDIOffsetFader = 70; // Behringer X-TOUCH: offset of 0x46

// parse the server info string according to definition: there is
// the legacy definition with just one or two numbers that only
// provides a definition for the controller offset of the level
// controllers (default 70 for the sake of Behringer X-Touch)
// [MIDI channel];[offset for level]
if ( !strMIDISetup.isEmpty() )
{
Expand All @@ -252,6 +257,13 @@ void CSoundBase::ParseCommandLineArgument ( const QString& strMIDISetup )
{
iMIDIOffsetFader = slMIDIParams[1].toUInt();
}

for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
if ( i + iMIDIOffsetFader > 127 )
break;
aMidiCtls[i + iMIDIOffsetFader] = { EMidiCtlType::Fader, i };
}
}
}

Expand Down Expand Up @@ -287,15 +299,26 @@ printf ( "\n" );
// make sure packet is long enough
if ( vMIDIPaketBytes.Size() > 2 )
{
// 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> (
qMin ( vMIDIPaketBytes[2], uint8_t ( 127 ) ) ) / 127 * AUD_MIX_FADER_MAX );

// consider offset for the faders
const int iChID = vMIDIPaketBytes[1] - iMIDIOffsetFader;

emit ControllerInFaderLevel ( iChID, iFaderLevel );
const auto &cCtrl = aMidiCtls[qMin ( vMIDIPaketBytes[1], uint8_t ( 127 ) )];
const int iValue = qMin ( vMIDIPaketBytes[2], uint8_t ( 127 ) );
switch ( cCtrl.eType )
{
case Fader:
{
// 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 );

// consider offset for the faders

emit ControllerInFaderLevel ( cCtrl.iChannel, iFaderLevel );
}
break;

default:
break;
}
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/soundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ enum ESndCrdResetType
RS_RELOAD_RESTART_AND_INIT
};

enum EMidiCtlType
{
Fader = 0,
Pan,
Solo,
Mute,
None
};

class CMidiCtlEntry {
public:
CMidiCtlEntry ( EMidiCtlType eT = EMidiCtlType::None, int iC = 0 )
: eType ( eT ), iChannel ( iC )
{ }
EMidiCtlType eType;
int iChannel;
};

/* Classes ********************************************************************/
class CSoundBase : public QThread
Expand Down Expand Up @@ -138,7 +155,7 @@ class CSoundBase : public QThread

QString strSystemDriverTechniqueName;
int iCtrlMIDIChannel;
int iMIDIOffsetFader;
QVector<CMidiCtlEntry> aMidiCtls;

long lNumDevs;
QString strCurDevName;
Expand Down

0 comments on commit f440a8b

Please sign in to comment.