change inheritance so that an AudioBackend IS-A PortEngine
[ardour.git] / libs / backends / jack / jack_portengine.h
1 /*
2     Copyright (C) 2013 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libardour_jack_portengine_h__
21 #define __libardour_jack_portengine_h__
22
23 #include <string>
24 #include <vector>
25
26 #include <stdint.h>
27
28 #include <jack/types.h>
29 #include <jack/midiport.h>
30
31 #include <boost/shared_ptr.hpp>
32
33 #include "pbd/signals.h"
34
35 #include "ardour/port_engine.h"
36 #include "ardour/types.h"
37
38 namespace ARDOUR {
39
40 class JackConnection;
41
42 class JACKPortEngine : public PortEngine 
43 {
44   public:
45     JACKPortEngine (PortManager&, boost::shared_ptr<JackConnection>);
46     ~JACKPortEngine();
47
48     void* private_handle() const;
49     bool connected() const;
50
51     const std::string& my_name() const;
52
53     uint32_t port_name_size() const;
54
55     int         set_port_name (PortHandle, const std::string&);
56     std::string get_port_name (PortHandle) const;
57     PortHandle* get_port_by_name (const std::string&) const;
58
59     int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>&) const;
60
61     DataType port_data_type (PortHandle) const;
62
63     PortHandle register_port (const std::string& shortname, ARDOUR::DataType, ARDOUR::PortFlags);
64     void  unregister_port (PortHandle);
65
66     bool  connected (PortHandle, bool process_callback_safe);
67     bool  connected_to (PortHandle, const std::string&, bool process_callback_safe);
68     bool  physically_connected (PortHandle, bool process_callback_safe);
69     int   get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe);
70     int   connect (PortHandle, const std::string&);
71
72     int   disconnect (PortHandle, const std::string&);
73     int   disconnect_all (PortHandle);
74     int   connect (const std::string& src, const std::string& dst);
75     int   disconnect (const std::string& src, const std::string& dst);
76     
77     /* MIDI */
78
79     int      midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
80     int      midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
81     uint32_t get_midi_event_count (void* port_buffer);
82     void     midi_clear (void* port_buffer);
83
84     /* Monitoring */
85
86     bool  can_monitor_input() const;
87     int   request_input_monitoring (PortHandle, bool);
88     int   ensure_input_monitoring (PortHandle, bool);
89     bool  monitoring_input (PortHandle);
90
91     /* Latency management
92      */
93     
94     void          set_latency_range (PortHandle, bool for_playback, LatencyRange);
95     LatencyRange  get_latency_range (PortHandle, bool for_playback);
96
97     /* Physical ports */
98
99     bool      port_is_physical (PortHandle) const;
100     void      get_physical_outputs (DataType type, std::vector<std::string>&);
101     void      get_physical_inputs (DataType type, std::vector<std::string>&);
102     ChanCount n_physical_outputs () const;
103     ChanCount n_physical_inputs () const;
104
105     /* Getting access to the data buffer for a port */
106
107     void* get_buffer (PortHandle, pframes_t);
108
109     /* Miscellany */
110
111     pframes_t sample_time_at_cycle_start ();
112     
113   private:
114     boost::shared_ptr<JackConnection> _jack_connection;
115
116     static int  _graph_order_callback (void *arg);
117     static void _registration_callback (jack_port_id_t, int, void *);
118     static void _connect_callback (jack_port_id_t, jack_port_id_t, int, void *);
119
120     void connect_callback (jack_port_id_t, jack_port_id_t, int);
121
122     ChanCount n_physical (unsigned long flags) const;
123     void get_physical (DataType type, unsigned long flags, std::vector<std::string>& phy) const;
124
125     PBD::ScopedConnection jack_connection_connection;
126     void connected_to_jack ();
127
128 };
129
130 } // namespace 
131
132 #endif /* __libardour_jack_portengine_h__ */