summaryrefslogtreecommitdiff
path: root/libs/surfaces/mackie/subview.h
blob: 9c214726e8b970e937f641ee3102ba0d05f1ddb9 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * Copyright (C) 2006-2007 John Anderson
 * Copyright (C) 2012-2015 Paul Davis <paul@linuxaudiosystems.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __ardour_mackie_control_protocol_subview_h__
#define __ardour_mackie_control_protocol_subview_h__

#include <boost/smart_ptr.hpp>

#include "ardour/types.h"

namespace ARDOUR {
	class ParameterDescriptor;
	class Plugin;
	class PluginInsert;
}

namespace ArdourSurface {

class MackieControlProtocol;

namespace Mackie {

class Pot;
class Strip;
class Subview;
class Surface;

enum SubViewMode {
	None,
	EQ,
	Dynamics,
	Sends,
	TrackView,
	Plugin,
};

class SubviewFactory {
  public:
	static SubviewFactory* instance();

	boost::shared_ptr<Subview> create_subview(SubViewMode svm,
		MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
  protected:
	SubviewFactory();
  private:
	static SubviewFactory* _instance;
};


/**
	This implements the subviews of the Mackie control in a Strategy pattern
*/
class Subview {
  public:
	Subview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~Subview();

	virtual SubViewMode subview_mode () const = 0;
	virtual void update_global_buttons() = 0;
	virtual bool permit_flipping_faders_and_pots() { return false; }
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]) = 0;
	virtual void handle_vselect_event(uint32_t global_strip_position);
	// returns true if press was handled in the subview, default is false
	virtual bool handle_cursor_right_press() { return false; }
	// returns true if press was handled in the subview, default is false
	virtual bool handle_cursor_left_press() { return false; }

	static bool subview_mode_would_be_ok (SubViewMode, boost::shared_ptr<ARDOUR::Stripable>, std::string& reason_why_not);
	boost::shared_ptr<ARDOUR::Stripable> subview_stripable() const { return _subview_stripable; }

	void notify_subview_stripable_deleted ();
	MackieControlProtocol& mcp() { return _mcp; }

	PBD::ScopedConnectionList& subview_stripable_connections() { return _subview_stripable_connections; }
	PBD::ScopedConnectionList& subview_connections() { return _subview_connections; }

	void do_parameter_display(std::string& display, const ARDOUR::ParameterDescriptor& pd, float param_val, Strip* strip, bool screen_hold);

  protected:
	void init_strip_vectors();
	void store_pointers(Strip* strip, Pot* vpot, std::string* pending_display, uint32_t global_strip_position);
	bool retrieve_pointers(Strip** strip, Pot** vpot, std::string** pending_display, uint32_t global_strip_position);

	MackieControlProtocol& _mcp;
	boost::shared_ptr<ARDOUR::Stripable> _subview_stripable;
	PBD::ScopedConnectionList _subview_stripable_connections;

	std::vector<Strip*> _strips_over_all_surfaces;
	std::vector<Pot*> _strip_vpots_over_all_surfaces;
	std::vector<std::string*> _strip_pending_displays_over_all_surfaces;
	PBD::ScopedConnectionList _subview_connections;
  private:
	void reset_all_vpot_controls();
};

class NoneSubview : public Subview {
  public:
	NoneSubview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~NoneSubview();

	virtual SubViewMode subview_mode () const { return SubViewMode::None; }
	static bool subview_mode_would_be_ok (boost::shared_ptr<ARDOUR::Stripable> r, std::string& reason_why_not);

	virtual void update_global_buttons();
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]);
};

class EQSubview : public Subview {
  public:
	EQSubview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~EQSubview();

	virtual SubViewMode subview_mode () const { return SubViewMode::EQ; }
	static bool subview_mode_would_be_ok (boost::shared_ptr<ARDOUR::Stripable> r, std::string& reason_why_not);
	virtual void update_global_buttons();
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]);
	void notify_change (boost::weak_ptr<ARDOUR::AutomationControl>, uint32_t global_strip_position, bool force);
};

class DynamicsSubview : public Subview {
  public:
	DynamicsSubview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~DynamicsSubview();

	virtual SubViewMode subview_mode () const { return SubViewMode::Dynamics; }
	static bool subview_mode_would_be_ok (boost::shared_ptr<ARDOUR::Stripable> r, std::string& reason_why_not);
	virtual void update_global_buttons();
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]);
	void notify_change (boost::weak_ptr<ARDOUR::AutomationControl>, uint32_t global_strip_position, bool force, bool propagate_mode_change);
};

class SendsSubview : public Subview {
  public:
	SendsSubview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~SendsSubview();

	virtual SubViewMode subview_mode () const { return SubViewMode::Sends; }
	static bool subview_mode_would_be_ok (boost::shared_ptr<ARDOUR::Stripable> r, std::string& reason_why_not);
	virtual void update_global_buttons();
	virtual bool permit_flipping_faders_and_pots() { return true; }
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]);
	void notify_send_level_change (uint32_t global_strip_position, bool force);

	virtual void handle_vselect_event(uint32_t global_strip_position);
};

class TrackViewSubview : public Subview {
  public:
	TrackViewSubview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~TrackViewSubview();

	virtual SubViewMode subview_mode () const { return SubViewMode::TrackView; }
	static bool subview_mode_would_be_ok (boost::shared_ptr<ARDOUR::Stripable> r, std::string& reason_why_not);
	virtual void update_global_buttons();
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]);
	void notify_change (ARDOUR::AutomationType, uint32_t global_strip_position, bool force);
};

class PluginSubviewState;

class PluginSubview : public Subview {
  public:
    PluginSubview(MackieControlProtocol& mcp, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual ~PluginSubview();

	virtual SubViewMode subview_mode () const { return SubViewMode::Plugin; }
	static bool subview_mode_would_be_ok (boost::shared_ptr<ARDOUR::Stripable> r, std::string& reason_why_not);
	virtual void update_global_buttons();
	virtual bool permit_flipping_faders_and_pots();
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2]);
	virtual void handle_vselect_event(uint32_t global_strip_position);
	virtual bool handle_cursor_right_press();
	virtual bool handle_cursor_left_press();

	void set_state(boost::shared_ptr<PluginSubviewState> new_state);

  protected:
	void connect_processors_changed_signal();
	void handle_processors_changed();

    boost::shared_ptr<PluginSubviewState> _plugin_subview_state;
};

class PluginSubviewState {
  public:
    PluginSubviewState(PluginSubview& context);
	virtual ~PluginSubviewState();

	virtual bool permit_flipping_faders_and_pots() { return false; }
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2],
		uint32_t global_strip_position,
		boost::shared_ptr<ARDOUR::Stripable> subview_stripable) = 0;
	virtual void handle_vselect_event(uint32_t global_strip_position, boost::shared_ptr<ARDOUR::Stripable> subview_stripable) = 0;
	static std::string shorten_display_text(const std::string& text, std::string::size_type target_length);
	virtual bool handle_cursor_right_press();
	virtual bool handle_cursor_left_press();
	virtual void bank_changed() = 0;

  protected:
	uint32_t calculate_virtual_strip_position(uint32_t strip_index) const;

    PluginSubview& _context;
	const uint32_t _bank_size;
	uint32_t _current_bank;
};

class PluginSelect : public PluginSubviewState {
  public:
	PluginSelect(PluginSubview& context);
	virtual ~PluginSelect();

	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2],
		uint32_t global_strip_position,
		boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual void handle_vselect_event(uint32_t global_strip_position, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual void bank_changed();
};

class PluginEdit : public PluginSubviewState {
  public:
	PluginEdit(PluginSubview& context, boost::weak_ptr<ARDOUR::PluginInsert> weak_subview_plugin);
	virtual ~PluginEdit();

	virtual bool permit_flipping_faders_and_pots() { return true; }
	virtual void setup_vpot(
		Strip* strip,
		Pot* vpot,
		std::string pending_display[2],
		uint32_t global_strip_position,
		boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual void handle_vselect_event(uint32_t global_strip_position, boost::shared_ptr<ARDOUR::Stripable> subview_stripable);
	virtual void bank_changed();

	void notify_parameter_change(Strip* strip, Pot* vpot, std::string pending_display[2], uint32_t global_strip_position);
	void init();
	bool plugin_went_away() const;
	void switch_to_plugin_select_state();

	boost::shared_ptr<ARDOUR::AutomationControl> parameter_control(uint32_t global_strip_position) const;

	boost::weak_ptr<ARDOUR::PluginInsert> _weak_subview_plugin_insert;
	boost::weak_ptr<ARDOUR::Plugin> _weak_subview_plugin;
	std::vector<uint32_t> _plugin_input_parameter_indices;
};

}
}

#endif /* __ardour_mackie_control_protocol_subview_h__ */