From ea24503fdc4acf5268fd4413166b427689e1776e Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 12 Jan 2019 12:45:08 +0000 Subject: [PATCH] preparation for MIDI controller audio fader level support --- android/sound.cpp | 6 ++++-- android/sound.h | 4 +++- linux/sound.h | 20 ++++++++++++-------- mac/sound.cpp | 6 ++++-- mac/sound.h | 5 ++++- src/audiomixerboard.cpp | 13 +++++++++++++ src/audiomixerboard.h | 6 +++++- src/client.cpp | 9 +++++++-- src/client.h | 4 +++- src/clientdlg.cpp | 4 ++++ src/clientdlg.h | 4 ++++ src/main.cpp | 22 +++++++++++++++++++++- src/soundbase.cpp | 16 +++++++++++++--- src/soundbase.h | 13 ++++++++++--- src/util.h | 1 + windows/sound.cpp | 6 ++++-- windows/sound.h | 4 +++- 17 files changed, 115 insertions(+), 28 deletions(-) diff --git a/android/sound.cpp b/android/sound.cpp index c207a6d1..24d1378e 100644 --- a/android/sound.cpp +++ b/android/sound.cpp @@ -26,8 +26,10 @@ /* Implementation *************************************************************/ -CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ) : - CSoundBase ( "OpenSL", true, fpNewProcessCallback, arg ) +CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), + void* arg, + const int iCtrlMIDIChannel ) : + CSoundBase ( "OpenSL", true, fpNewProcessCallback, arg, iCtrlMIDIChannel ) { } diff --git a/android/sound.h b/android/sound.h index e915efdd..fb1b1e6d 100644 --- a/android/sound.h +++ b/android/sound.h @@ -36,7 +36,9 @@ class CSound : public CSoundBase { public: - CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ); + CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), + void* arg, + const int iCtrlMIDIChannel ); virtual ~CSound() {} virtual int Init ( const int iNewPrefMonoBufferSize ); diff --git a/linux/sound.h b/linux/sound.h index 4b23b040..398093b0 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -60,8 +60,10 @@ class CSound : public CSoundBase { public: - CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ) : - CSoundBase ( "Jack", true, fpNewProcessCallback, arg ), iJACKBufferSizeMono ( 0 ), + CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), + void* arg, + const int iCtrlMIDIChannel ) : + CSoundBase ( "Jack", true, fpNewProcessCallback, arg, iCtrlMIDIChannel ), iJACKBufferSizeMono ( 0 ), iJACKBufferSizeStero ( 0 ) { OpenJack(); } virtual ~CSound() { CloseJack(); } @@ -85,18 +87,20 @@ protected: void CloseJack(); // callbacks - static int process ( jack_nframes_t nframes, void* arg ); - static int bufferSizeCallback ( jack_nframes_t, void *arg ); - static void shutdownCallback ( void* ); - jack_client_t* pJackClient; + static int process ( jack_nframes_t nframes, void* arg ); + static int bufferSizeCallback ( jack_nframes_t, void *arg ); + static void shutdownCallback ( void* ); + jack_client_t* pJackClient; }; #else // no sound -> dummy class definition class CSound : public CSoundBase { public: - CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), void* pParg ) : - CSoundBase ( "nosound", false, fpNewProcessCallback, pParg ) {} + CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), + void* pParg, + const int iCtrlMIDIChannel ) : + CSoundBase ( "nosound", false, fpNewProcessCallback, pParg, iCtrlMIDIChannel ) {} virtual ~CSound() {} }; #endif // WITH_SOUND diff --git a/mac/sound.cpp b/mac/sound.cpp index 8c5c4d1e..2698fc36 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -26,8 +26,10 @@ /* Implementation *************************************************************/ -CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ) : - CSoundBase ( "CoreAudio", true, fpNewProcessCallback, arg ) +CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), + void* arg, + const int iCtrlMIDIChannel ) : + CSoundBase ( "CoreAudio", true, fpNewProcessCallback, arg, iCtrlMIDIChannel ) { // Apple Mailing Lists: Subject: GUI Apps should set kAudioHardwarePropertyRunLoop // in the HAL, From: Jeff Moore, Date: Fri, 6 Dec 2002 diff --git a/mac/sound.h b/mac/sound.h index 0377b1ff..8c73eada 100755 --- a/mac/sound.h +++ b/mac/sound.h @@ -26,6 +26,7 @@ #define _SOUND_H__9518A621345F78_363456876UZGSDF82CF549__INCLUDED_ #include +#include #include #include "soundbase.h" #include "global.h" @@ -35,7 +36,9 @@ class CSound : public CSoundBase { public: - CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ); + CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), + void* arg, + const int iCtrlMIDIChannel ); virtual int Init ( const int iNewPrefMonoBufferSize ); virtual void Start(); diff --git a/src/audiomixerboard.cpp b/src/audiomixerboard.cpp index 8edb819c..a18f45e9 100755 --- a/src/audiomixerboard.cpp +++ b/src/audiomixerboard.cpp @@ -669,6 +669,19 @@ void CAudioMixerBoard::ApplyNewConClientList ( CVector& vecChanInf emit NumClientsChanged ( iNumConnectedClients ); } +void CAudioMixerBoard::SetFaderLevel ( const int iChannelIdx, + const double dValue ) +{ + // only apply new fader level if channel index is valid and the fader is visible + if ( ( iChannelIdx >= 0 ) && ( iChannelIdx < MAX_NUM_CHANNELS ) ) + { + if ( vecpChanFader[iChannelIdx]->IsVisible() ) + { + vecpChanFader[iChannelIdx]->SetFaderLevel ( dValue ); + } + } +} + void CAudioMixerBoard::UpdateSoloStates() { // first check if any channel has a solo state active diff --git a/src/audiomixerboard.h b/src/audiomixerboard.h index c5ac42c0..dbad3da2 100755 --- a/src/audiomixerboard.h +++ b/src/audiomixerboard.h @@ -102,6 +102,9 @@ public: void SetServerName ( const QString& strNewServerName ); void SetGUIDesign ( const EGUIDesign eNewDesign ); + void SetFaderLevel ( const int iChannelIdx, + const double dValue ); + // settings CVector vecStoredFaderTags; CVector vecStoredFaderLevels; @@ -115,7 +118,8 @@ protected: void StoreFaderSettings ( CChannelFader* pChanFader ); void UpdateSoloStates(); - void OnGainValueChanged ( const int iChannelIdx, const double dValue ); + void OnGainValueChanged ( const int iChannelIdx, + const double dValue ); CVector vecpChanFader; QHBoxLayout* pMainLayout; diff --git a/src/client.cpp b/src/client.cpp index 1595551e..50b76a91 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -27,7 +27,8 @@ /* Implementation *************************************************************/ CClient::CClient ( const quint16 iPortNumber, - const QString& strConnOnStartupAddress ) : + const QString& strConnOnStartupAddress, + const int iCtrlMIDIChannel ) : vstrIPAddress ( MAX_NUM_SERVER_ADDR_ITEMS, "" ), ChannelInfo (), vecStoredFaderTags ( MAX_NUM_STORED_FADER_SETTINGS, "" ), @@ -50,7 +51,7 @@ CClient::CClient ( const quint16 iPortNumber, eAudioChannelConf ( CC_MONO ), bIsInitializationPhase ( true ), Socket ( &Channel, iPortNumber ), - Sound ( AudioCallback, this ), + Sound ( AudioCallback, this, iCtrlMIDIChannel ), iAudioInFader ( AUD_FADER_IN_MIDDLE ), bReverbOnLeftChan ( false ), iReverbLevel ( 0 ), @@ -196,6 +197,10 @@ CClient::CClient ( const quint16 iPortNumber, QObject::connect ( &Sound, SIGNAL ( ReinitRequest ( int ) ), this, SLOT ( OnSndCrdReinitRequest ( int ) ) ); + QObject::connect ( &Sound, + SIGNAL ( ControllerInFaderLevel ( int, double ) ), + SIGNAL ( ControllerInFaderLevel ( int, double ) ) ); + QObject::connect ( &Socket, SIGNAL ( InvalidPacketReceived ( CHostAddress ) ), this, SLOT ( OnInvalidPacketReceived ( CHostAddress ) ) ); diff --git a/src/client.h b/src/client.h index 83806d4e..51883bd9 100755 --- a/src/client.h +++ b/src/client.h @@ -100,7 +100,8 @@ class CClient : public QObject public: CClient ( const quint16 iPortNumber, - const QString& strConnOnStartupAddress ); + const QString& strConnOnStartupAddress, + const int iCtrlMIDIChannel ); void Start(); void Stop(); @@ -410,6 +411,7 @@ signals: #endif void Disconnected(); + void ControllerInFaderLevel ( int iChannelIdx, double dValue ); }; #endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */ diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 72d0c78c..1a1cfadc 100755 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -482,6 +482,10 @@ CClientDlg::CClientDlg ( CClient* pNCliP, SIGNAL ( CLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ) ); + QObject::connect ( pClient, + SIGNAL ( ControllerInFaderLevel ( int, double ) ), + this, SLOT ( OnControllerInFaderLevel ( int, double ) ) ); + #ifdef ENABLE_CLIENT_VERSION_AND_OS_DEBUGGING QObject::connect ( pClient, SIGNAL ( CLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString ) ), diff --git a/src/clientdlg.h b/src/clientdlg.h index 7c3d8193..242bb4ec 100755 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -134,6 +134,10 @@ public slots: int iPingTime, int iNumClients ); + void OnControllerInFaderLevel ( const int iChannelIdx, + const double dValue ) { MainMixerBoard->SetFaderLevel ( iChannelIdx, + dValue ); } + #ifdef ENABLE_CLIENT_VERSION_AND_OS_DEBUGGING void OnCLVersionAndOSReceived ( CHostAddress InetAddr, COSUtil::EOpSystemType eOSType, diff --git a/src/main.cpp b/src/main.cpp index 55f3c4bf..68114b3f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,7 @@ int main ( int argc, char** argv ) bool bShowAnalyzerConsole = false; bool bCentServPingServerInList = false; int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; + int iCtrlMIDIChannel = INVALID_MIDI_CH; quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; ELicenceType eLicenceType = LT_NO_LICENCE; QString strConnOnStartupAddress = ""; @@ -199,6 +200,23 @@ int main ( int argc, char** argv ) } + // Controller MIDI channel --------------------------------------------- + if ( GetNumericArgument ( tsConsole, + argc, + argv, + i, + "--ctrlmidich", // no short form + "--ctrlmidich", + 0, + 15, + rDbleArgument ) ) + { + iCtrlMIDIChannel = static_cast ( rDbleArgument ); + tsConsole << "- selected controller MIDI channel: " << iCtrlMIDIChannel << endl; + continue; + } + + // Use logging --------------------------------------------------------- if ( GetStringArgument ( tsConsole, argc, @@ -412,7 +430,8 @@ int main ( int argc, char** argv ) // Client: // actual client object CClient Client ( iPortNumber, - strConnOnStartupAddress ); + strConnOnStartupAddress, + iCtrlMIDIChannel ); // load settings from init-file CSettings Settings ( &Client, strIniFileName ); @@ -558,6 +577,7 @@ QString UsageArguments ( char **argv ) " -y, --history enable connection history and set file\n" " name (server only)\n" " -z, --startminimized start minimizied (server only)\n" + " --ctrlmidich MIDI controller channel to listen (client only)" "\nExample: " + QString ( argv[0] ) + " -l -inifile myinifile.ini\n"; } diff --git a/src/soundbase.cpp b/src/soundbase.cpp index 1c608308..5ca31cdf 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -27,9 +27,10 @@ /* Implementation *************************************************************/ CSoundBase::CSoundBase ( const QString& strNewSystemDriverTechniqueName, - const bool bNewIsCallbackAudioInterface, - void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), - void* pParg ) : + const bool bNewIsCallbackAudioInterface, + void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), + void* pParg, + const int iCtrlMIDIChannel ) : fpProcessCallback ( fpNewProcessCallback ), pProcessCallbackArg ( pParg ), bRun ( false ), bIsCallbackAudioInterface ( bNewIsCallbackAudioInterface ), @@ -96,6 +97,15 @@ void CSoundBase::run() } } +void CSoundBase::ParseMIDIMessage ( const CVector& vMIDIPaketBytes ) +{ +// TODO +int iChannelIdx = 0; +double dFaderLevel = 0; +EmitControllerInFaderLevel ( iChannelIdx, dFaderLevel ); +} + + /******************************************************************************\ * Device handling * diff --git a/src/soundbase.h b/src/soundbase.h index d006a27b..420d1898 100755 --- a/src/soundbase.h +++ b/src/soundbase.h @@ -49,9 +49,10 @@ class CSoundBase : public QThread public: CSoundBase ( const QString& strNewSystemDriverTechniqueName, - const bool bNewIsCallbackAudioInterface, - void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), - void* pParg ); + const bool bNewIsCallbackAudioInterface, + void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), + void* pParg, + const int iCtrlMIDIChannel ); virtual int Init ( const int iNewPrefMonoBufferSize ); virtual void Start(); @@ -88,6 +89,9 @@ public: void EmitReinitRequestSignal ( const ESndCrdResetType eSndCrdResetType ) { emit ReinitRequest ( eSndCrdResetType ); } + void EmitControllerInFaderLevel ( const int iChannelIdx, + const double dValue ) { emit ControllerInFaderLevel ( iChannelIdx, dValue ); } + protected: // driver handling virtual QString LoadAndInitializeDriver ( int ) { return ""; } @@ -112,6 +116,8 @@ protected: void run(); bool bRun; + void ParseMIDIMessage ( const CVector& vMIDIPaketBytes ); + bool bIsCallbackAudioInterface; QString strSystemDriverTechniqueName; @@ -123,6 +129,7 @@ protected: signals: void ReinitRequest ( int iSndCrdResetType ); + void ControllerInFaderLevel ( int iChannelIdx, double dValue ); }; #endif /* !defined ( SOUNDBASE_HOIHGEH8_3_4344456456345634565KJIUHF1912__INCLUDED_ ) */ diff --git a/src/util.h b/src/util.h index 5c500410..c5b79f17 100755 --- a/src/util.h +++ b/src/util.h @@ -64,6 +64,7 @@ class CClient; // forward declaration of CClient /* Definitions ****************************************************************/ #define METER_FLY_BACK 2 +#define INVALID_MIDI_CH -1 // invalid MIDI channel definition /* Global functions ***********************************************************/ diff --git a/windows/sound.cpp b/windows/sound.cpp index e310e802..9650f4a5 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -449,8 +449,10 @@ void CSound::Stop() } } -CSound::CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), void* arg ) : - CSoundBase ( "ASIO", true, fpNewCallback, arg ), +CSound::CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), + void* arg, + const int iCtrlMIDIChannel ) : + CSoundBase ( "ASIO", true, fpNewCallback, arg, iCtrlMIDIChannel ), vSelectedInputChannels ( NUM_IN_OUT_CHANNELS ), vSelectedOutputChannels ( NUM_IN_OUT_CHANNELS ), lNumInChan ( 0 ), diff --git a/windows/sound.h b/windows/sound.h index 49292757..203e5467 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -48,7 +48,9 @@ class CSound : public CSoundBase { public: - CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), void* arg ); + CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), + void* arg, + const int ); virtual ~CSound() { UnloadCurrentDriver(); } virtual int Init ( const int iNewPrefMonoBufferSize );