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,12 +42,47 @@
namespace ARDOUR { 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 { class LIBARDOUR_API AudioBackend : public PortEngine {
public: public:
AudioBackend (AudioEngine& e) : PortEngine (e), engine (e) {} AudioBackend (AudioEngine& e, AudioBackendInfo& i) : PortEngine (e), _info (i), engine (e) {}
virtual ~AudioBackend () {} virtual ~AudioBackend () {}
/** Return the AudioBackendInfo object from which this backend
was constructed.
*/
AudioBackendInfo& info() const { return _info; }
/** Return the name of this backend. /** Return the name of this backend.
* *
* Should use a well-known, unique term. Expected examples * Should use a well-known, unique term. Expected examples
@ -482,41 +517,12 @@ class LIBARDOUR_API AudioBackend : public PortEngine {
} }
protected: protected:
AudioBackendInfo& _info;
AudioEngine& engine; AudioEngine& engine;
virtual int _start (bool for_latency_measurement) = 0; 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)();
};
} // namespace } // namespace
#endif /* __libardour_audiobackend_h__ */ #endif /* __libardour_audiobackend_h__ */

View file

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

View file

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

View file

@ -25,6 +25,19 @@ using namespace ARDOUR;
static boost::shared_ptr<JACKAudioBackend> backend; static boost::shared_ptr<JACKAudioBackend> backend;
static boost::shared_ptr<JackConnection> jack_connection; 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> static boost::shared_ptr<AudioBackend>
backend_factory (AudioEngine& ae) backend_factory (AudioEngine& ae)
{ {
@ -33,7 +46,7 @@ backend_factory (AudioEngine& ae)
} }
if (!backend) { if (!backend) {
backend.reset (new JACKAudioBackend (ae, jack_connection)); backend.reset (new JACKAudioBackend (ae, _descriptor, jack_connection));
} }
return backend; return backend;
@ -66,13 +79,5 @@ already_configured ()
return !JackConnection::in_control (); return !JackConnection::in_control ();
} }
static ARDOUR::AudioBackendInfo _descriptor = {
"JACK",
instantiate,
deinstantiate,
backend_factory,
already_configured,
};
extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor() { return &_descriptor; } 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(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; } #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) JACKAudioBackend::JACKAudioBackend (AudioEngine& e, AudioBackendInfo& info, boost::shared_ptr<JackConnection> jc)
: AudioBackend (e) : AudioBackend (e, info)
, _jack_connection (jc) , _jack_connection (jc)
, _running (false) , _running (false)
, _freewheeling (false) , _freewheeling (false)

View file

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

View file

@ -23,6 +23,16 @@
using namespace ARDOUR; 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) void WavesAudioBackend::AudioDeviceManagerNotification (NotificationReason reason, void* parameter)
{ {
switch (reason) { switch (reason) {
@ -83,8 +93,8 @@ void WavesAudioBackend::AudioDeviceManagerNotification (NotificationReason reaso
} }
WavesAudioBackend::WavesAudioBackend (AudioEngine& e) WavesAudioBackend::WavesAudioBackend (AudioEngine& e, AudioBackendInfo& info)
: AudioBackend (e) : AudioBackend (e, info)
, _audio_device_manager (this) , _audio_device_manager (this)
, _midi_device_manager (*this) , _midi_device_manager (*this)
, _device (NULL) , _device (NULL)
@ -1274,7 +1284,7 @@ WavesAudioBackend::__waves_backend_factory (AudioEngine& e)
{ {
// COMMENTED DBG LOGS */ std::cout << "WavesAudioBackend::__waves_backend_factory ():" << std::endl; // COMMENTED DBG LOGS */ std::cout << "WavesAudioBackend::__waves_backend_factory ():" << std::endl;
if (!__instance) { if (!__instance) {
__instance.reset (new WavesAudioBackend (e)); __instance.reset (new WavesAudioBackend (e, descriptor()));
} }
return __instance; return __instance;
} }
@ -1365,12 +1375,3 @@ AudioBackendInfo WavesAudioBackend::__backend_info = {
WavesAudioBackend::__already_configured, 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 class WavesAudioBackend : public AudioBackend, WCMRAudioDeviceManagerClient
{ {
public: public:
WavesAudioBackend (AudioEngine& e); WavesAudioBackend (AudioEngine& e, AudioBackendInfo&);
virtual ~WavesAudioBackend (); virtual ~WavesAudioBackend ();
/* AUDIOBACKEND API */ /* AUDIOBACKEND API */