2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2013 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <gtkmm/sizegroup.h>
22 #include "ardour/dB.h"
23 #include "widgets/tooltips.h"
24 #include "gtkmm2ext/gui_thread.h"
27 #include "ardour_ui.h"
29 #include "transport_control_ui.h"
35 using namespace ARDOUR;
36 using namespace ArdourWidgets;
38 TransportControlUI::TransportControlUI ()
40 Config->ParameterChanged.connect (config_connection, MISSING_INVALIDATOR, boost::bind (&TransportControlUI::parameter_changed, this, _1), gui_context());
44 TransportControlUI::map_actions ()
49 act = ActionManager::get_action (X_("Transport"), X_("ToggleClick"));
50 click_button.set_related_action (act);
51 act = ActionManager::get_action (X_("Transport"), X_("Stop"));
52 stop_button.set_related_action (act);
53 act = ActionManager::get_action (X_("Transport"), X_("Roll"));
54 roll_button.set_related_action (act);
55 act = ActionManager::get_action (X_("Transport"), X_("Record"));
56 rec_button.set_related_action (act);
57 act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
58 goto_start_button.set_related_action (act);
59 act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
60 goto_end_button.set_related_action (act);
61 act = ActionManager::get_action (X_("Transport"), X_("Loop"));
62 auto_loop_button.set_related_action (act);
63 act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
64 play_selection_button.set_related_action (act);
66 act = ActionManager::get_action (X_("MIDI"), X_("panic"));
67 midi_panic_button.set_related_action (act);
69 /* tooltips depend on actions */
70 set_tooltip (roll_button, _("Play from playhead"));
71 set_tooltip (stop_button, _("Stop playback"));
72 set_tooltip (rec_button, _("Toggle record"));
73 set_tooltip (play_selection_button, _("Play range/selection"));
74 set_tooltip (goto_start_button, _("Go to start of session"));
75 set_tooltip (goto_end_button, _("Go to end of session"));
76 set_tooltip (auto_loop_button, _("Play loop range"));
77 set_tooltip (midi_panic_button, _("MIDI Panic\nSend note off and reset controller messages on all MIDI channels"));
79 /* set click_button tooltip */
80 parameter_changed ("click-gain");
84 TransportControlUI::setup (TransportControlProvider* ui)
86 click_button.signal_button_press_event().connect (sigc::mem_fun (*ui, &TransportControlProvider::click_button_clicked), false);
87 click_button.signal_scroll_event().connect (sigc::mem_fun (*this, &TransportControlUI::click_button_scroll), false);
91 click_button.set_icon (ArdourIcon::TransportMetronom);
92 goto_start_button.set_icon (ArdourIcon::TransportStart);
93 goto_end_button.set_icon (ArdourIcon::TransportEnd);
94 roll_button.set_icon (ArdourIcon::TransportPlay);
95 stop_button.set_icon (ArdourIcon::TransportStop);
96 play_selection_button.set_icon (ArdourIcon::TransportRange);
97 auto_loop_button.set_icon (ArdourIcon::TransportLoop);
98 rec_button.set_icon (ArdourIcon::RecButton);
99 midi_panic_button.set_icon (ArdourIcon::TransportPanic);
101 /* transport control size-group */
103 Glib::RefPtr<SizeGroup> transport_button_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
104 transport_button_size_group->add_widget (goto_start_button);
105 transport_button_size_group->add_widget (goto_end_button);
106 transport_button_size_group->add_widget (auto_loop_button);
107 transport_button_size_group->add_widget (rec_button);
108 transport_button_size_group->add_widget (play_selection_button);
109 transport_button_size_group->add_widget (roll_button);
110 transport_button_size_group->add_widget (stop_button);
112 transport_button_size_group->add_widget (midi_panic_button);
113 transport_button_size_group->add_widget (click_button);
115 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
117 click_button.set_size_request (PX_SCALE(20), PX_SCALE(20));
118 set_spacing (PX_SCALE(2));
122 pack_start (midi_panic_button, true, true, 0);
123 pack_start (click_button, true, true, 0);
124 pack_start (goto_start_button, true, true);
125 pack_start (goto_end_button, true, true);
126 pack_start (auto_loop_button, true, true);
127 pack_start (play_selection_button, true, true);
128 pack_start (roll_button, true, true);
129 pack_start (stop_button, true, true);
130 pack_start (rec_button, true, true, 3);
132 roll_button.set_name ("transport button");
133 stop_button.set_name ("transport button");
134 goto_start_button.set_name ("transport button");
135 goto_end_button.set_name ("transport button");
136 auto_loop_button.set_name ("transport button");
137 play_selection_button.set_name ("transport button");
138 rec_button.set_name ("transport recenable button");
139 midi_panic_button.set_name ("transport button"); // XXX ???
140 click_button.set_name ("transport button");
142 roll_button.set_controllable (ui->roll_controllable);
143 stop_button.set_controllable (ui->stop_controllable);
144 goto_start_button.set_controllable (ui->goto_start_controllable);
145 goto_end_button.set_controllable (ui->goto_end_controllable);
146 auto_loop_button.set_controllable (ui->auto_loop_controllable);
147 play_selection_button.set_controllable (ui->play_selection_controllable);
148 rec_button.set_controllable (ui->rec_controllable);
150 stop_button.set_active (true);
152 Timers::blink_connect (sigc::mem_fun (*this, &TransportControlUI::blink_rec_enable));
156 TransportControlUI::set_session (ARDOUR::Session *s)
158 SessionHandlePtr::set_session (s);
159 set_loop_sensitivity ();
162 rec_button.set_sensitive (false);
166 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&TransportControlUI::parameter_changed, this, _1), gui_context());
167 _session->StepEditStatusChange.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&TransportControlUI::step_edit_status_change, this, _1), gui_context());
168 _session->TransportStateChange.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&TransportControlUI::map_transport_state, this), gui_context());
169 _session->auto_loop_location_changed.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&TransportControlUI::set_loop_sensitivity, this), gui_context ());
171 rec_button.set_sensitive (true);
175 TransportControlUI::parameter_changed (std::string p)
177 if (p == "external-sync") {
178 set_loop_sensitivity ();
179 } else if (p == "click-record-only") {
180 // TODO set a flag, blink or gray-out metronome button while rolling, only
181 if (Config->get_click_record_only()) {
182 click_button.set_name ("generic button"); // XXX
184 click_button.set_name ("transport button");
186 } else if (p == "click-gain") {
187 float gain_db = accurate_coefficient_to_dB (Config->get_click_gain());
189 snprintf(tmp, 31, "%+.1f", gain_db);
190 set_tooltip (click_button, string_compose (_("Enable/Disable metronome\n\nRight-click to access preferences\nMouse-wheel to modify level\nSignal Level: %1 dBFS"), tmp));
195 TransportControlUI::map_transport_state ()
198 auto_loop_button.unset_active_state ();
199 play_selection_button.unset_active_state ();
200 roll_button.unset_active_state ();
201 stop_button.set_active_state (Gtkmm2ext::ExplicitActive);
205 float sp = _session->transport_speed();
211 if (_session->get_play_range()) {
213 play_selection_button.set_active_state (Gtkmm2ext::ExplicitActive);
214 roll_button.unset_active_state ();
215 auto_loop_button.unset_active_state ();
217 } else if (_session->get_play_loop ()) {
219 auto_loop_button.set_active (true);
220 play_selection_button.set_active (false);
222 if (Config->get_loop_is_mode()) {
223 roll_button.set_active (true);
225 roll_button.set_active (false);
230 roll_button.set_active (true);
231 play_selection_button.set_active (false);
232 auto_loop_button.set_active (false);
236 if (UIConfiguration::instance().get_follow_edits() && !_session->config.get_external_sync()) {
237 /* light up both roll and play-selection if they are joined */
238 roll_button.set_active (true);
239 play_selection_button.set_active (true);
242 stop_button.set_active (false);
246 stop_button.set_active (true);
247 roll_button.set_active (false);
248 play_selection_button.set_active (false);
249 if (Config->get_loop_is_mode ()) {
250 auto_loop_button.set_active (_session->get_play_loop());
252 auto_loop_button.set_active (false);
258 TransportControlUI::step_edit_status_change (bool yn)
260 // XXX should really store pre-step edit status of things
261 // we make insensitive
264 rec_button.set_active_state (Gtkmm2ext::ImplicitActive);
265 rec_button.set_sensitive (false);
267 rec_button.unset_active_state ();;
268 rec_button.set_sensitive (true);
273 TransportControlUI::set_loop_sensitivity ()
275 if (!_session || _session->config.get_external_sync()) {
276 auto_loop_button.set_sensitive (false);
278 auto_loop_button.set_sensitive (_session && _session->locations()->auto_loop_location());
283 TransportControlUI::blink_rec_enable (bool onoff)
289 if (_session->step_editing()) {
293 Session::RecordState const r = _session->record_status ();
294 bool const h = _session->have_rec_enabled_track ();
296 if (r == Session::Enabled || (r == Session::Recording && !h)) {
298 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
300 rec_button.set_active_state (Gtkmm2ext::Off);
302 } else if (r == Session::Recording && h) {
303 rec_button.set_active_state (Gtkmm2ext::ExplicitActive);
305 rec_button.unset_active_state ();
310 TransportControlUI::click_button_scroll (GdkEventScroll* ev)
312 gain_t gain = Config->get_click_gain();
313 float gain_db = accurate_coefficient_to_dB (gain);
315 switch (ev->direction) {
317 case GDK_SCROLL_LEFT:
320 case GDK_SCROLL_DOWN:
321 case GDK_SCROLL_RIGHT:
325 gain_db = std::max (-60.f, gain_db);
326 gain = dB_to_coefficient (gain_db);
327 gain = std::min (gain, Config->get_max_gain());
328 Config->set_click_gain (gain);