Add AudioBackend::info() method to retrieve AudioBackendInfo object

Goal is to be able to call AudioBackendInfo::already_configured() from the right place.
This commit is contained in:
Paul Davis 2014-05-01 09:14:25 -04:00
parent 6544df039b
commit 66559cd795
8 changed files with 87 additions and 70 deletions

View File

@ -42,11 +42,46 @@
namespace ARDOUR {
struct LIBARDOUR_API AudioBackendInfo {
const char* name;
/** Using arg1 and arg2, initialize this audiobackend.
*
* Returns zero on success, non-zero otherwise.
*/
int (*instantiate) (const std::string& arg1, const std::string& arg2);
/** Release all resources associated with this audiobackend
*/
int (*deinstantiate) (void);
/** Factory method to create an AudioBackend-derived class.
*
* Returns a valid shared_ptr to the object if successfull,
* or a "null" shared_ptr otherwise.
*/
boost::shared_ptr<AudioBackend> (*factory) (AudioEngine&);
/** Return true if the underlying mechanism/API has been
* configured and does not need (re)configuration in order
* to be usable. Return false otherwise.
*
* Note that this may return true if (re)configuration, even though
* not currently required, is still possible.
*/
bool (*already_configured)();
};
class LIBARDOUR_API AudioBackend : public PortEngine {
public:
AudioBackend (AudioEngine& e) : PortEngine (e), engine (e) {}
AudioBackend (AudioEngine& e, AudioBackendInfo& i) : PortEngine (e), _info (i), engine (e) {}
virtual ~AudioBackend () {}
/** Return the AudioBackendInfo object from which this backend
was constructed.
*/
AudioBackendInfo& info() const { return _info; }
/** Return the name of this backend.
*
@ -482,39 +517,10 @@ class LIBARDOUR_API AudioBackend : public PortEngine {
}
protected:
AudioEngine& engine;
AudioBackendInfo& _info;
AudioEngine& engine;
virtual int _start (bool for_latency_measurement) = 0;
};
struct LIBARDOUR_API AudioBackendInfo {
const char* name;
/** Using arg1 and arg2, initialize this audiobackend.
*
* Returns zero on success, non-zero otherwise.
*/
int (*instantiate) (const std::string& arg1, const std::string& arg2);
/** Release all resources associated with this audiobackend
*/
int (*deinstantiate) (void);
/** Factory method to create an AudioBackend-derived class.
*
* Returns a valid shared_ptr to the object if successfull,
* or a "null" shared_ptr otherwise.
*/
boost::shared_ptr<AudioBackend> (*factory) (AudioEngine&);
/** Return true if the underlying mechanism/API has been
* configured and does not need (re)configuration in order
* to be usable. Return false otherwise.
*
* Note that this may return true if (re)configuration, even though
* not currently required, is still possible.
*/
bool (*already_configured)();
virtual int _start (bool for_latency_measurement) = 0;
};
} // namespace

View File

@ -29,8 +29,8 @@ using namespace ARDOUR;
static std::string s_instance_name;
size_t DummyAudioBackend::_max_buffer_size = 8192;
DummyAudioBackend::DummyAudioBackend (AudioEngine& e)
: AudioBackend (e)
DummyAudioBackend::DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info)
: AudioBackend (e, info)
, _running (false)
, _freewheeling (false)
, _samplerate (48000)
@ -1017,11 +1017,24 @@ DummyAudioBackend::main_process_thread ()
static boost::shared_ptr<DummyAudioBackend> _instance;
static boost::shared_ptr<AudioBackend> backend_factory (AudioEngine& e);
static int instantiate (const std::string& arg1, const std::string& /* arg2 */);
static int deinstantiate ();
static bool already_configured ();
static ARDOUR::AudioBackendInfo _descriptor = {
"Dummy",
instantiate,
deinstantiate,
backend_factory,
already_configured,
};
static boost::shared_ptr<AudioBackend>
backend_factory (AudioEngine& e)
{
if (!_instance) {
_instance.reset (new DummyAudioBackend (e));
_instance.reset (new DummyAudioBackend (e, _descriptor));
}
return _instance;
}
@ -1046,14 +1059,6 @@ already_configured ()
return false;
}
static ARDOUR::AudioBackendInfo _descriptor = {
"Dummy",
instantiate,
deinstantiate,
backend_factory,
already_configured,
};
extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor ()
{
return &_descriptor;

View File

@ -142,7 +142,7 @@ class DummyMidiPort : public DummyPort {
class DummyAudioBackend : public AudioBackend {
public:
DummyAudioBackend (AudioEngine& e);
DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info);
~DummyAudioBackend ();
/* AUDIOBACKEND API */

View File

@ -25,6 +25,19 @@ using namespace ARDOUR;
static boost::shared_ptr<JACKAudioBackend> backend;
static boost::shared_ptr<JackConnection> jack_connection;
static boost::shared_ptr<AudioBackend> backend_factory (AudioEngine& ae);
static int instantiate (const std::string& arg1, const std::string& arg2);
static int deinstantiate ();
static bool already_configured ();
static ARDOUR::AudioBackendInfo _descriptor = {
"JACK",
instantiate,
deinstantiate,
backend_factory,
already_configured,
};
static boost::shared_ptr<AudioBackend>
backend_factory (AudioEngine& ae)
{
@ -33,7 +46,7 @@ backend_factory (AudioEngine& ae)
}
if (!backend) {
backend.reset (new JACKAudioBackend (ae, jack_connection));
backend.reset (new JACKAudioBackend (ae, _descriptor, jack_connection));
}
return backend;
@ -66,13 +79,5 @@ already_configured ()
return !JackConnection::in_control ();
}
static ARDOUR::AudioBackendInfo _descriptor = {
"JACK",
instantiate,
deinstantiate,
backend_factory,
already_configured,
};
extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor() { return &_descriptor; }

View File

@ -50,8 +50,8 @@ using std::vector;
#define GET_PRIVATE_JACK_POINTER(localvar) jack_client_t* localvar = _jack_connection->jack(); if (!(localvar)) { return; }
#define GET_PRIVATE_JACK_POINTER_RET(localvar,r) jack_client_t* localvar = _jack_connection->jack(); if (!(localvar)) { return r; }
JACKAudioBackend::JACKAudioBackend (AudioEngine& e, boost::shared_ptr<JackConnection> jc)
: AudioBackend (e)
JACKAudioBackend::JACKAudioBackend (AudioEngine& e, AudioBackendInfo& info, boost::shared_ptr<JackConnection> jc)
: AudioBackend (e, info)
, _jack_connection (jc)
, _running (false)
, _freewheeling (false)

View File

@ -41,7 +41,7 @@ class JACKSession;
class JACKAudioBackend : public AudioBackend {
public:
JACKAudioBackend (AudioEngine& e, boost::shared_ptr<JackConnection>);
JACKAudioBackend (AudioEngine& e, AudioBackendInfo& info, boost::shared_ptr<JackConnection>);
~JACKAudioBackend ();
/* AUDIOBACKEND API */

View File

@ -23,6 +23,16 @@
using namespace ARDOUR;
#ifdef __MINGW64__
extern "C" __declspec(dllexport) ARDOUR::AudioBackendInfo* descriptor ()
#else
extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor ()
#endif
{
// COMMENTED DBG LOGS */ std::cout << "waves_backend.dll : ARDOUR::AudioBackendInfo* descriptor (): " << std::endl;
return &WavesAudioBackend::backend_info ();
}
void WavesAudioBackend::AudioDeviceManagerNotification (NotificationReason reason, void* parameter)
{
switch (reason) {
@ -83,8 +93,8 @@ void WavesAudioBackend::AudioDeviceManagerNotification (NotificationReason reaso
}
WavesAudioBackend::WavesAudioBackend (AudioEngine& e)
: AudioBackend (e)
WavesAudioBackend::WavesAudioBackend (AudioEngine& e, AudioBackendInfo& info)
: AudioBackend (e, info)
, _audio_device_manager (this)
, _midi_device_manager (*this)
, _device (NULL)
@ -1274,7 +1284,7 @@ WavesAudioBackend::__waves_backend_factory (AudioEngine& e)
{
// COMMENTED DBG LOGS */ std::cout << "WavesAudioBackend::__waves_backend_factory ():" << std::endl;
if (!__instance) {
__instance.reset (new WavesAudioBackend (e));
__instance.reset (new WavesAudioBackend (e, descriptor()));
}
return __instance;
}
@ -1365,12 +1375,3 @@ AudioBackendInfo WavesAudioBackend::__backend_info = {
WavesAudioBackend::__already_configured,
};
#ifdef __MINGW64__
extern "C" __declspec(dllexport) ARDOUR::AudioBackendInfo* descriptor ()
#else
extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor ()
#endif
{
// COMMENTED DBG LOGS */ std::cout << "waves_backend.dll : ARDOUR::AudioBackendInfo* descriptor (): " << std::endl;
return &WavesAudioBackend::backend_info ();
}

View File

@ -70,7 +70,7 @@ class WavesMidiPort;
class WavesAudioBackend : public AudioBackend, WCMRAudioDeviceManagerClient
{
public:
WavesAudioBackend (AudioEngine& e);
WavesAudioBackend (AudioEngine& e, AudioBackendInfo&);
virtual ~WavesAudioBackend ();
/* AUDIOBACKEND API */