position+width panning improvements (reverse width now works); relabel pan automation...
[ardour.git] / libs / ardour / ardour / audioengine.h
index e630e1a95e87d8fb3a2d2d1f3ea1a4928f580082..523a05b4c11911c0930aec6492459d6828db0178 100644 (file)
@@ -31,7 +31,6 @@
 #include <exception>
 #include <string>
 
-
 #include <glibmm/thread.h>
 
 #include "pbd/rcu.h"
@@ -44,6 +43,7 @@
 #include "ardour/data_type.h"
 #include "ardour/session_handle.h"
 #include "ardour/types.h"
+#include "ardour/chan_count.h"
 
 #ifdef HAVE_JACK_SESSION
 #include <jack/session.h>
@@ -55,12 +55,18 @@ class InternalPort;
 class MidiPort;
 class Port;
 class Session;
+class ProcessThread;
 
 class AudioEngine : public SessionHandlePtr
 {
    public:
        typedef std::set<Port*> Ports;
 
+        class disconnected_exception : public std::exception {
+          public:
+                virtual const char *what() const throw() { return "AudioEngine is disconnected"; }
+        };
+
        AudioEngine (std::string client_name, std::string session_uuid);
        virtual ~AudioEngine ();
 
@@ -69,6 +75,8 @@ class AudioEngine : public SessionHandlePtr
 
        bool is_realtime () const;
 
+        ProcessThread* main_thread() const { return _main_thread; }
+
        std::string client_name() const { return jack_client_name; }
 
        int reconnect_to_jack ();
@@ -131,13 +139,15 @@ class AudioEngine : public SessionHandlePtr
 
        class PortRegistrationFailure : public std::exception {
        public:
-               PortRegistrationFailure (const char* why = "") {
-                       reason = why;
-               }
-               virtual const char *what() const throw() { return reason; }
+               PortRegistrationFailure (std::string const & why = "")
+                       : reason (why) {}
+
+               ~PortRegistrationFailure () throw () {}
+
+               virtual const char *what() const throw () { return reason.c_str(); }
 
        private:
-               const char* reason;
+               std::string reason;
        };
 
        class NoBackendAvailable : public std::exception {
@@ -159,25 +169,16 @@ class AudioEngine : public SessionHandlePtr
 
        bool can_request_hardware_monitoring ();
 
-       uint32_t n_physical_outputs (DataType type) const;
-       uint32_t n_physical_inputs (DataType type) const;
+       ChanCount n_physical_outputs () const;
+       ChanCount n_physical_inputs () const;
 
        void get_physical_outputs (DataType type, std::vector<std::string>&);
        void get_physical_inputs (DataType type, std::vector<std::string>&);
 
-       std::string get_nth_physical_output (DataType type, uint32_t n) {
-               return get_nth_physical (type, n, JackPortIsInput);
-       }
-
-       std::string get_nth_physical_input (DataType type, uint32_t n) {
-               return get_nth_physical (type, n, JackPortIsOutput);
-       }
-
        void update_total_latencies ();
        void update_total_latency (const Port&);
 
        Port *get_port_by_name (const std::string &);
-       Port *get_port_by_name_locked (const std::string &);
 
        enum TransportState {
                TransportStopped = JackTransportStopped,
@@ -221,7 +222,7 @@ _      the regular process() call to session->process() is not made.
 
        /* this signal is sent if JACK ever disconnects us */
 
-       PBD::Signal0<void> Halted;
+       PBD::Signal1<void,const char*> Halted;
 
        /* these two are emitted when the engine itself is
           started and stopped
@@ -242,6 +243,8 @@ _      the regular process() call to session->process() is not made.
        static AudioEngine* instance() { return _instance; }
        void died ();
 
+        int create_process_thread (boost::function<void()>, pthread_t*, size_t stacksize);
+
   private:
        static AudioEngine*       _instance;
 
@@ -272,9 +275,12 @@ _     the regular process() call to session->process() is not made.
        Port *register_port (DataType type, const std::string& portname, bool input);
 
        int    process_callback (nframes_t nframes);
+       void*  process_thread ();
+        void   finish_process_cycle (int status);
        void   remove_all_ports ();
 
-       std::string get_nth_physical (DataType type, uint32_t n, int flags);
+       ChanCount n_physical (unsigned long) const;
+       void get_physical (DataType, unsigned long, std::vector<std::string> &);
 
        void port_registration_failure (const std::string& portname);
 
@@ -284,6 +290,7 @@ _      the regular process() call to session->process() is not made.
 #endif
        static int  _graph_order_callback (void *arg);
        static int  _process_callback (nframes_t nframes, void *arg);
+       static void* _process_thread (void *arg);
        static int  _sample_rate_callback (nframes_t nframes, void *arg);
        static int  _bufsize_callback (nframes_t nframes, void *arg);
        static void _jack_timebase_callback (jack_transport_state_t, nframes_t, jack_position_t*, int, void*);
@@ -300,6 +307,7 @@ _      the regular process() call to session->process() is not made.
        int connect_to_jack (std::string client_name, std::string session_uuid);
 
        static void halted (void *);
+       static void halted_info (jack_status_t,const char*,void *);
 
        void meter_thread ();
        void start_metering_thread ();
@@ -307,6 +315,19 @@ _     the regular process() call to session->process() is not made.
 
        Glib::Thread*    m_meter_thread;
        static gint      m_meter_exit;
+
+        ProcessThread* _main_thread;
+
+        struct ThreadData {
+            AudioEngine* engine;
+            boost::function<void()> f;
+            size_t stacksize;
+            
+            ThreadData (AudioEngine* ae, boost::function<void()> fp, size_t stacksz) 
+            : engine (ae) , f (fp) , stacksize (stacksz) {}
+        };
+        
+        static void* _start_process_thread (void*);
 };
 
 } // namespace ARDOUR