summaryrefslogtreecommitdiff
path: root/libs/surfaces/control_protocol/control_protocol/control_protocol.h
blob: f5af008e4a85881c2c55165ccfe7cdd470e99230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
    Copyright (C) 2006 Paul Davis 

    This program is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser
    General Public License as published by the Free Software
    Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef ardour_control_protocols_h
#define ardour_control_protocols_h

#include <string>
#include <vector>
#include <list>

#include <boost/shared_ptr.hpp>

#include "pbd/stateful.h"
#include "pbd/signals.h"

#include "control_protocol/visibility.h"
#include "control_protocol/basic_ui.h"
#include "control_protocol/types.h"

namespace ARDOUR {

class Route;
class Session;
class Bundle;

class LIBCONTROLCP_API ControlProtocol : public PBD::Stateful, public PBD::ScopedConnectionList, public BasicUI
{
  public:
	ControlProtocol (Session&, std::string name);
	virtual ~ControlProtocol();

	std::string name() const { return _name; }

        virtual int set_active (bool yn);
        bool active() const { return _active; }

	virtual int set_feedback (bool /*yn*/) { return 0; }
	virtual bool get_feedback () const { return false; }

	virtual void midi_connectivity_established () {}

	PBD::Signal0<void> ActiveChanged;

	/* signals that a control protocol can emit and other (presumably graphical)
	   user interfaces can respond to
	*/

	static PBD::Signal0<void> ZoomToSession;
	static PBD::Signal0<void> ZoomIn;
	static PBD::Signal0<void> ZoomOut;
	static PBD::Signal0<void> Enter;
	static PBD::Signal0<void> Undo;
	static PBD::Signal0<void> Redo;
	static PBD::Signal1<void,float> ScrollTimeline;
	static PBD::Signal1<void,uint32_t> GotoView;
	static PBD::Signal0<void> CloseDialog;
	static PBD::Signal0<void> VerticalZoomInAll;
	static PBD::Signal0<void> VerticalZoomOutAll;
	static PBD::Signal0<void> VerticalZoomInSelected;
	static PBD::Signal0<void> VerticalZoomOutSelected;
	static PBD::Signal0<void> StepTracksDown;
	static PBD::Signal0<void> StepTracksUp;

	static PBD::Signal1<void,uint32_t> AddRouteToSelection;
	static PBD::Signal1<void,uint32_t> SetRouteSelection;
	static PBD::Signal1<void,uint32_t> ToggleRouteSelection;
	static PBD::Signal1<void,uint32_t> RemoveRouteFromSelection;
	static PBD::Signal0<void>          ClearRouteSelection;

	/* signals that one UI (e.g. the GUI) can emit to get all other UI's to 
	   respond. Typically this will always be GUI->"others" - the GUI pays
	   no attention to these signals.
	*/
	
	static PBD::Signal1<void,RouteNotificationListPtr> TrackSelectionChanged;

	/* the model here is as follows:

	   we imagine most control surfaces being able to control
	   from 1 to N tracks at a time, with a session that may
	   contain 1 to M tracks, where M may be smaller, larger or
	   equal to N. 

	   the control surface has a fixed set of physical controllers
	   which can potentially be mapped onto different tracks/busses
	   via some mechanism.

	   therefore, the control protocol object maintains
	   a table that reflects the current mapping between
	   the controls and route object.
	*/

	void set_route_table_size (uint32_t size);
	void set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route>);
	bool set_route_table (uint32_t table_index, uint32_t remote_control_id);

	void route_set_rec_enable (uint32_t table_index, bool yn);
	bool route_get_rec_enable (uint32_t table_index);

	float route_get_gain (uint32_t table_index);
	void route_set_gain (uint32_t table_index, float);
	float route_get_effective_gain (uint32_t table_index);

	float route_get_peak_input_power (uint32_t table_index, uint32_t which_input);

	bool route_get_muted (uint32_t table_index);
	void route_set_muted (uint32_t table_index, bool);

	bool route_get_soloed (uint32_t table_index);
	void route_set_soloed (uint32_t table_index, bool);

	std::string route_get_name (uint32_t table_index);

	virtual std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();

	virtual bool  has_editor () const { return false; }
	virtual void* get_gui() const { return 0; }
	virtual void  tear_down_gui() { }

        XMLNode& get_state ();
        static const std::string state_node_name;

  protected:
	std::vector<boost::shared_ptr<ARDOUR::Route> > route_table;
	std::string _name;

	void next_track (uint32_t initial_id);
	void prev_track (uint32_t initial_id);

  private:
	LIBCONTROLCP_LOCAL ControlProtocol (const ControlProtocol&); /* noncopyable */
        bool _active;
};

extern "C" {
	class ControlProtocolDescriptor {
	public:
	    const char* name;      /* descriptive */
	    const char* id;        /* unique and version-specific */
	    void*       ptr;       /* protocol can store a value here */
	    void*       module;    /* not for public access */
	    int         mandatory; /* if non-zero, always load and do not make optional */
	    bool        supports_feedback; /* if true, protocol has toggleable feedback mechanism */
	    bool             (*probe)(ControlProtocolDescriptor*);
	    ControlProtocol* (*initialize)(ControlProtocolDescriptor*,Session*);
	    void             (*destroy)(ControlProtocolDescriptor*,ControlProtocol*);
	    
	};
}

}

#endif // ardour_control_protocols_h