2012-01-28 12:51:14 +01:00
|
|
|
/******************************************************************************\
|
2020-01-01 15:41:43 +01:00
|
|
|
* Copyright (c) 2004-2020
|
2012-01-28 12:51:14 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
2020-06-08 22:58:11 +02:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2012-01-28 12:51:14 +01:00
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2019-07-09 08:52:38 +02:00
|
|
|
#pragma once
|
2012-01-28 12:51:14 +01:00
|
|
|
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QString>
|
2020-06-17 19:34:51 +02:00
|
|
|
#ifndef HEADLESS
|
|
|
|
# include <QMessageBox>
|
|
|
|
#endif
|
2012-01-28 12:51:14 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
|
// TODO better solution with enum definition
|
|
|
|
// problem: in signals it seems not to work to use CSoundBase::ESndCrdResetType
|
|
|
|
enum ESndCrdResetType
|
|
|
|
{
|
2012-01-30 20:08:40 +01:00
|
|
|
RS_ONLY_RESTART = 1,
|
2012-01-28 12:51:14 +01:00
|
|
|
RS_ONLY_RESTART_AND_INIT,
|
|
|
|
RS_RELOAD_RESTART_AND_INIT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CSoundBase : public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
CSoundBase ( const QString& strNewSystemDriverTechniqueName,
|
2019-01-12 13:45:08 +01:00
|
|
|
const bool bNewIsCallbackAudioInterface,
|
|
|
|
void (*fpNewProcessCallback) ( CVector<int16_t>& psData, void* pParg ),
|
|
|
|
void* pParg,
|
2020-04-30 22:18:11 +02:00
|
|
|
const int iNewCtrlMIDIChannel );
|
2012-01-28 12:51:14 +01:00
|
|
|
|
|
|
|
virtual int Init ( const int iNewPrefMonoBufferSize );
|
|
|
|
virtual void Start();
|
|
|
|
virtual void Stop();
|
|
|
|
|
|
|
|
// device selection
|
|
|
|
virtual int GetNumDev() { return lNumDevs; }
|
|
|
|
virtual QString GetDeviceName ( const int iDiD ) { return strDriverNames[iDiD]; }
|
|
|
|
virtual QString SetDev ( const int );
|
|
|
|
virtual int GetDev() { return lCurDev; }
|
|
|
|
|
|
|
|
virtual int GetNumInputChannels() { return 2; }
|
|
|
|
virtual QString GetInputChannelName ( const int ) { return "Default"; }
|
|
|
|
virtual void SetLeftInputChannel ( const int ) {}
|
|
|
|
virtual void SetRightInputChannel ( const int ) {}
|
|
|
|
virtual int GetLeftInputChannel() { return 0; }
|
|
|
|
virtual int GetRightInputChannel() { return 1; }
|
|
|
|
|
|
|
|
virtual int GetNumOutputChannels() { return 2; }
|
|
|
|
virtual QString GetOutputChannelName ( const int ) { return "Default"; }
|
|
|
|
virtual void SetLeftOutputChannel ( const int ) {}
|
|
|
|
virtual void SetRightOutputChannel ( const int ) {}
|
|
|
|
virtual int GetLeftOutputChannel() { return 0; }
|
|
|
|
virtual int GetRightOutputChannel() { return 1; }
|
|
|
|
|
2013-12-17 21:52:38 +01:00
|
|
|
virtual double GetInOutLatencyMs() { return 0.0; } // "0.0" means no latency is available
|
|
|
|
|
2012-01-28 12:51:14 +01:00
|
|
|
virtual void OpenDriverSetup() {}
|
|
|
|
|
|
|
|
bool IsRunning() const { return bRun; }
|
|
|
|
|
|
|
|
// TODO this should be protected but since it is used
|
|
|
|
// in a callback function it has to be public -> better solution
|
|
|
|
void EmitReinitRequestSignal ( const ESndCrdResetType eSndCrdResetType )
|
|
|
|
{ emit ReinitRequest ( eSndCrdResetType ); }
|
|
|
|
|
2019-01-12 13:59:16 +01:00
|
|
|
void EmitControllerInFaderLevel ( const int iChannelIdx,
|
|
|
|
const int iValue ) { emit ControllerInFaderLevel ( iChannelIdx, iValue ); }
|
2019-01-12 13:45:08 +01:00
|
|
|
|
2012-01-28 12:51:14 +01:00
|
|
|
protected:
|
|
|
|
// driver handling
|
2020-04-20 19:57:21 +02:00
|
|
|
virtual QString LoadAndInitializeDriver ( int, bool ) { return ""; }
|
2012-01-28 12:51:14 +01:00
|
|
|
virtual void UnloadCurrentDriver() {}
|
2020-04-20 19:57:21 +02:00
|
|
|
QVector<QString> LoadAndInitializeFirstValidDriver ( const bool bOpenDriverSetup = false );
|
2012-01-28 12:51:14 +01:00
|
|
|
|
2020-05-01 14:21:08 +02:00
|
|
|
static void GetSelCHAndAddCH ( const int iSelCH, const int iNumInChan,
|
|
|
|
int& iSelCHOut, int& iSelAddCHOut )
|
|
|
|
{
|
|
|
|
// we have a mixed channel setup, definitions:
|
|
|
|
// - mixed channel setup only for 4 physical inputs:
|
|
|
|
// SelCH == 4: Ch 0 + Ch 2
|
|
|
|
// SelCh == 5: Ch 0 + Ch 3
|
|
|
|
// SelCh == 6: Ch 1 + Ch 2
|
|
|
|
// SelCh == 7: Ch 1 + Ch 3
|
|
|
|
if ( iSelCH >= iNumInChan )
|
|
|
|
{
|
|
|
|
iSelAddCHOut = ( ( iSelCH - iNumInChan ) % 2 ) + 2;
|
|
|
|
iSelCHOut = ( iSelCH - iNumInChan ) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-26 09:56:46 +02:00
|
|
|
iSelAddCHOut = INVALID_INDEX; // set it to an invalid number
|
2020-05-01 14:21:08 +02:00
|
|
|
iSelCHOut = iSelCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 12:51:14 +01:00
|
|
|
// function pointer to callback function
|
|
|
|
void (*fpProcessCallback) ( CVector<int16_t>& psData, void* arg );
|
|
|
|
void* pProcessCallbackArg;
|
|
|
|
|
|
|
|
// callback function call for derived classes
|
|
|
|
void ProcessCallback ( CVector<int16_t>& psData )
|
|
|
|
{
|
|
|
|
(*fpProcessCallback) ( psData, pProcessCallbackArg );
|
|
|
|
}
|
|
|
|
|
|
|
|
// these functions should be overwritten by derived class for
|
|
|
|
// non callback based audio interfaces
|
|
|
|
virtual bool Read ( CVector<int16_t>& ) { printf ( "no sound!" ); return false; }
|
|
|
|
virtual bool Write ( CVector<int16_t>& ) { printf ( "no sound!" ); return false; }
|
|
|
|
|
|
|
|
void run();
|
|
|
|
bool bRun;
|
|
|
|
|
2019-01-12 15:32:41 +01:00
|
|
|
void ParseMIDIMessage ( const CVector<uint8_t>& vMIDIPaketBytes );
|
2019-01-12 13:45:08 +01:00
|
|
|
|
2012-01-28 12:51:14 +01:00
|
|
|
bool bIsCallbackAudioInterface;
|
|
|
|
QString strSystemDriverTechniqueName;
|
2019-01-22 17:11:41 +01:00
|
|
|
int iCtrlMIDIChannel;
|
2012-01-28 12:51:14 +01:00
|
|
|
|
|
|
|
CVector<int16_t> vecsAudioSndCrdStereo;
|
|
|
|
|
|
|
|
long lNumDevs;
|
|
|
|
long lCurDev;
|
|
|
|
QString strDriverNames[MAX_NUMBER_SOUND_CARDS];
|
|
|
|
|
|
|
|
signals:
|
2012-01-30 20:08:40 +01:00
|
|
|
void ReinitRequest ( int iSndCrdResetType );
|
2019-01-12 13:59:16 +01:00
|
|
|
void ControllerInFaderLevel ( int iChannelIdx, int iValue );
|
2012-01-28 12:51:14 +01:00
|
|
|
};
|