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 7, 2021
1 parent 7d0801a commit 68ccf44
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
41 changes: 30 additions & 11 deletions src/soundbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ CSoundBase::CSoundBase ( const QString& strNewSystemDriverTechniqueName,
bRun ( false ),
bCallbackEntered ( false ),
strSystemDriverTechniqueName ( strNewSystemDriverTechniqueName ),
iCtrlMIDIChannel ( INVALID_MIDI_CH ),
iMIDIOffsetFader ( 70 ) // Behringer X-TOUCH: offset of 0x46
iCtrlMIDIChannel ( INVALID_MIDI_CH )
{
// parse the MIDI setup command line argument string
ParseCommandLineArgument ( strMIDISetup );
Expand Down Expand Up @@ -234,6 +233,8 @@ QVector<QString> CSoundBase::LoadAndInitializeFirstValidDriver ( const bool bOpe
\******************************************************************************/
void CSoundBase::ParseCommandLineArgument ( const QString& strMIDISetup )
{
int iMIDIOffsetFader = 70; // Behringer X-TOUCH: offset of 0x46

// parse the server info string according to definition:
// [MIDI channel];[offset for level]
if ( !strMIDISetup.isEmpty() )
Expand All @@ -252,6 +253,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 +295,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
20 changes: 19 additions & 1 deletion src/soundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#ifndef HEADLESS
# include <QMessageBox>
#endif
#include <array>
#include "global.h"
#include "util.h"

Expand All @@ -43,6 +44,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 +156,7 @@ class CSoundBase : public QThread

QString strSystemDriverTechniqueName;
int iCtrlMIDIChannel;
int iMIDIOffsetFader;
std::array<CMidiCtlEntry, 128> aMidiCtls;

long lNumDevs;
QString strCurDevName;
Expand Down

0 comments on commit 68ccf44

Please sign in to comment.