Add AudioBackend::info() method to retrieve AudioBackendInfo object
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 1 May 2014 13:14:25 +0000 (09:14 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 1 May 2014 13:14:25 +0000 (09:14 -0400)
Goal is to be able to call AudioBackendInfo::already_configured() from the right place.

libs/ardour/ardour/audio_backend.h
libs/backends/dummy/dummy_audiobackend.cc
libs/backends/dummy/dummy_audiobackend.h
libs/backends/jack/jack_api.cc
libs/backends/jack/jack_audiobackend.cc
libs/backends/jack/jack_audiobackend.h
libs/backends/wavesaudio/waves_audiobackend.cc
libs/backends/wavesaudio/waves_audiobackend.h

index e4add4e92ba0c18fc46876d082d14bef03bc331a..78e390318259597c9a708378acd906aaeb8bffda 100644 (file)
 
 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;
-
-    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);
+     AudioBackendInfo&  _info; 
+     AudioEngine&        engine;
 
-    /** 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
index f0eeb8db1218337e65606627085ed092f6f0da54..7a3aa78513caf726b0f08d80d3e402eb13cd5a61 100644 (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;
index 18d14cb8672591b174a52704787962e1df750531..7f97dd17f910213d226f383aeec07c7df018060e 100644 (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 */
index c8859a1fc97a8cd0d1dd1a005ef8625dcfda49db..abf733d0f556332234118de419b9dc87bcfa357e 100644 (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; }
 
index fc712a95f81453d6e4f7569d685be292eadd4f96..d61d83bc66c491bd17ef23be54ccd4d801d5188c 100644 (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)
index bbf78895a872350e8be9a208e31a4934eb70c1f1..52edd55c638d199cc6a8415e402497aaca84be8c 100644 (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 */
index e08c60af2bdbcf49f20b2dec16a5d8fdba446019..e64d65566c133f2d02745583985b09ca4ef56a6e 100644 (file)
 
 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 ();
-}
index 6fd91913d1d6faff955d2555b03d0a6f8f40f3d8..87e2a88cfb59cdaa8fd89217c88a0163dcf8a8f8 100644 (file)
@@ -70,7 +70,7 @@ class WavesMidiPort;
     class WavesAudioBackend : public AudioBackend, WCMRAudioDeviceManagerClient
 {
   public:
-    WavesAudioBackend (AudioEngine& e);
+    WavesAudioBackend (AudioEngine& e, AudioBackendInfo&);
     virtual ~WavesAudioBackend ();
 
     /* AUDIOBACKEND API */