summaryrefslogtreecommitdiff
path: root/libs/surfaces/faderport8/callbacks.cc
blob: 185f5dd4ef0cf9a75fc51e7484b36205ac1795da (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
/*
 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
 *
 * 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.
 */

/* Faderport 8 Control Surface
 * This is the button "View" of the MVC surface inteface,
 * see actions.cc for the "Controller"
 */

#include "ardour/plugin_insert.h"
#include "ardour/session.h"
#include "ardour/session_configuration.h"

#include "gtkmm2ext/actions.h"

#include "faderport8.h"

#include "pbd/i18n.h"

using namespace ARDOUR;
using namespace ArdourSurface::FP_NAMESPACE;
using namespace ArdourSurface::FP_NAMESPACE::FP8Types;

void
FaderPort8::connect_session_signals ()
{
	 session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_stripable_added_or_removed, this), this);
	 PresentationInfo::Change.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_pi_property_changed, this, _1), this);

	Config->ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_parameter_changed, this, _1), this);
	session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_parameter_changed, this, _1), this);

	session->TransportStateChange.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_transport_state_changed, this), this);
	session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_loop_state_changed, this), this);
	session->RecordStateChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_record_state_changed, this), this);

	session->DirtyChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_session_dirty_changed, this), this);
	session->SoloChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_solo_changed, this), this);
	session->MuteChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_mute_changed, this), this);
	session->history().Changed.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_history_changed, this), this);
}

void
FaderPort8::send_session_state ()
{
	notify_transport_state_changed ();
	notify_record_state_changed ();
	notify_session_dirty_changed ();
	notify_history_changed ();
	notify_solo_changed ();
	notify_mute_changed ();
	notify_parameter_changed ("clicking");

	notify_route_state_changed (); // XXX (stip specific, see below)
}

// TODO: AutomationState display of plugin & send automation
// TODO: link/lock control AS.
void
FaderPort8::notify_route_state_changed ()
{
	boost::shared_ptr<Stripable> s = first_selected_stripable();
	boost::shared_ptr<AutomationControl> ac;
	if (s) {
		switch (_ctrls.fader_mode ()) {
			case ModeTrack:
				ac = s->gain_control();
				break;
			case ModePan:
				ac = s->pan_azimuth_control();
				break;
			default:
				break;
		}
	}
	if (!s || !ac) {
		_ctrls.button (FP8Controls::BtnALatch).set_active (false);
		_ctrls.button (FP8Controls::BtnATrim).set_active (false);
		_ctrls.button (FP8Controls::BtnAOff).set_active (false);
		_ctrls.button (FP8Controls::BtnATouch).set_active (false);
		_ctrls.button (FP8Controls::BtnARead).set_active (false);
		_ctrls.button (FP8Controls::BtnAWrite).set_active (false);
#ifdef FADERPORT2
		_ctrls.button (FP8Controls::BtnArm).set_active (false);
#endif
		return;
	}

	ARDOUR::AutoState as = ac->automation_state();
	_ctrls.button (FP8Controls::BtnAOff).set_active (as == Off);
	_ctrls.button (FP8Controls::BtnATouch).set_active (as == Touch);
	_ctrls.button (FP8Controls::BtnARead).set_active (as == Play);
	_ctrls.button (FP8Controls::BtnAWrite).set_active (as == Write);
	_ctrls.button (FP8Controls::BtnALatch).set_active (as == Latch);

#ifdef FADERPORT2
	/* handle the Faderport's track-arm button */
	ac = s->rec_enable_control ();
	_ctrls.button (FP8Controls::BtnArm).set_active (ac ? ac->get_value() : false);
#endif
}

void
FaderPort8::notify_parameter_changed (std::string param)
{
	if (param == "clicking") {
		_ctrls.button (FP8Controls::BtnClick).set_active (Config->get_clicking ());
	}
}

void
FaderPort8::notify_transport_state_changed ()
{
	if (session->transport_rolling ()) {
		_ctrls.button (FP8Controls::BtnPlay).set_active (true);
		_ctrls.button (FP8Controls::BtnStop).set_active (false);
	} else {
		_ctrls.button (FP8Controls::BtnPlay).set_active (false);
		_ctrls.button (FP8Controls::BtnStop).set_active (true);
	}

	/* set rewind/fastforward lights */
	const float ts = session->transport_speed ();
	FP8ButtonInterface& b_rew = _ctrls.button (FP8Controls::BtnRewind);
	FP8ButtonInterface& b_ffw = _ctrls.button (FP8Controls::BtnFastForward);

	const bool rew = (ts < 0.f);
	const bool ffw = (ts > 0.f && ts != 1.f);
	if (b_rew.is_active() != rew) {
		b_rew.set_active (rew);
	}
	if (b_ffw.is_active() != ffw) {
		b_ffw.set_active (ffw);
	}

	notify_loop_state_changed ();
}

void
FaderPort8::notify_record_state_changed ()
{
	switch (session->record_status ()) {
		case Session::Disabled:
			_ctrls.button (FP8Controls::BtnRecord).set_active (0);
			_ctrls.button (FP8Controls::BtnRecord).set_blinking (false);
			break;
		case Session::Enabled:
			_ctrls.button (FP8Controls::BtnRecord).set_active (true);
			_ctrls.button (FP8Controls::BtnRecord).set_blinking (true);
			break;
		case Session::Recording:
			_ctrls.button (FP8Controls::BtnRecord).set_active (true);
			_ctrls.button (FP8Controls::BtnRecord).set_blinking (false);
			break;
	}
}

void
FaderPort8::notify_loop_state_changed ()
{
	bool looping = false;
	Location* looploc = session->locations ()->auto_loop_location ();
	if (looploc && session->get_play_loop ()) {
		looping = true;
	}
	_ctrls.button (FP8Controls::BtnLoop).set_active (looping);
}

void
FaderPort8::notify_session_dirty_changed ()
{
	const bool is_dirty = session->dirty ();
	_ctrls.button (FP8Controls::BtnSave).set_active (is_dirty);
	_ctrls.button (FP8Controls::BtnSave).set_color (is_dirty ? 0xff0000ff : 0x00ff00ff);
}

void
FaderPort8::notify_history_changed ()
{
	_ctrls.button (FP8Controls::BtnRedo).set_active (session->redo_depth() > 0);
	_ctrls.button (FP8Controls::BtnUndo).set_active (session->undo_depth() > 0);
}

void
FaderPort8::notify_solo_changed ()
{
	bool soloing = session->soloing() || session->listening();
#ifdef MIXBUS
	soloing |= session->mixbus_soloed();
#endif
	_ctrls.button (FP8Controls::BtnSoloClear).set_active (soloing);
#ifdef FP8_MUTESOLO_UNDO
	if (soloing) {
		_solo_state.clear ();
	}
#endif
}

void
FaderPort8::notify_mute_changed ()
{
	bool muted = session->muted ();
#ifdef FP8_MUTESOLO_UNDO
	if (muted) {
		_mute_state.clear ();
	}
#endif
	_ctrls.button (FP8Controls::BtnMuteClear).set_active (muted);
}

void
FaderPort8::notify_plugin_active_changed ()
{
	boost::shared_ptr<PluginInsert> pi = _plugin_insert.lock();
	if (pi) {
		_ctrls.button (FP8Controls::BtnBypass).set_active (true);
		_ctrls.button (FP8Controls::BtnBypass).set_color (pi->enabled () ? 0x00ff00ff : 0xff0000ff);
	} else {
		_ctrls.button (FP8Controls::BtnBypass).set_active (false);
		_ctrls.button (FP8Controls::BtnBypass).set_color (0x888888ff);
	}
}

void
FaderPort8::nofity_focus_control (boost::weak_ptr<PBD::Controllable> c)
{
	assert (_link_enabled && !_link_locked);
	// TODO consider subscribing to c's DropReferences
	// (in case the control goes away while it has focus, update the BtnColor)
	_link_control = c;
	if (c.expired () || 0 == boost::dynamic_pointer_cast<AutomationControl> (_link_control.lock ())) {
		_ctrls.button (FP8Controls::BtnLink).set_color (0xff8800ff);
		_ctrls.button (FP8Controls::BtnLock).set_color (0xff0000ff);
	} else {
		_ctrls.button (FP8Controls::BtnLink).set_color (0x88ff00ff);
		_ctrls.button (FP8Controls::BtnLock).set_color (0x00ff88ff);
	}
}