summaryrefslogtreecommitdiff
path: root/gtk2_ardour/ardour_ui3.cc
blob: a35eb28a397f22ef7d15c312b4927eef7fe8c541 (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
/*
 * Copyright (C) 2005-2007 Doug McLain <doug@nostar.net>
 * Copyright (C) 2005-2017 Tim Mayberry <mojofunk@gmail.com>
 * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
 * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
 * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
 * Copyright (C) 2008-2010 Sakari Bergen <sakari.bergen@beatwaves.net>
 * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
 * Copyright (C) 2013-2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
 * Copyright (C) 2013-2016 John Emmas <john@creativepost.co.uk>
 * Copyright (C) 2013-2016 Nick Mainsbridge <mainsbridge@gmail.com>
 * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
 * Copyright (C) 2015 André Nusser <andre.nusser@googlemail.com>
 * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
 * Copyright (C) 2017 Johannes Mueller <github@johannes-mueller.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.
 */

#ifdef WAF_BUILD
#include "gtk2ardour-config.h"
#include "gtk2ardour-version.h"
#endif

#include "ardour/monitor_processor.h"
#include "ardour/session.h"
#include "ardour/route.h"

#include "actions.h"
#include "ardour_ui.h"
#include "audio_clock.h"
#include "gui_thread.h"
#include "main_clock.h"
#include "public_editor.h"
#include "ui_config.h"

#include "pbd/i18n.h"

using namespace ARDOUR;
using namespace PBD;
using namespace Gtkmm2ext;
using namespace ArdourWidgets;
using namespace Gtk;
using namespace std;
using namespace Editing;

void
ARDOUR_UI::cancel_solo ()
{
	if (_session) {
		_session->cancel_all_solo ();
	}
}

void
ARDOUR_UI::reset_focus (Gtk::Widget* w)
{
	/* this resets focus to the first focusable parent of the given widget,
	 * or, if there is no focusable parent, cancels focus in the toplevel
	 * window that the given widget is packed into (if there is one).
	 */

	if (!w) {
		return;
	}

	Gtk::Widget* top = w->get_toplevel();

	if (!top || !top->is_toplevel()) {
		return;
	}

	w = w->get_parent ();

	while (w) {

		if (w->is_toplevel()) {
			/* Setting the focus widget to a Gtk::Window causes all
			 * subsequent calls to ::has_focus() on the nominal
			 * focus widget in that window to return
			 * false. Workaround: never set focus to the toplevel
			 * itself.
			 */
			break;
		}

		if (w->get_can_focus ()) {
			Gtk::Window* win = dynamic_cast<Gtk::Window*> (top);
			win->set_focus (*w);
			return;
		}
		w = w->get_parent ();
	}

	if (top == &_main_window) {

	}

	/* no focusable parent found, cancel focus in top level window.
	   C++ API cannot be used for this. Thanks, references.
	*/

	gtk_window_set_focus (GTK_WINDOW(top->gobj()), 0);

}

void
ARDOUR_UI::monitor_dim_all ()
{
	boost::shared_ptr<Route> mon = _session->monitor_out ();
	if (!mon) {
		return;
	}
	boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();

	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-dim-all");
	_monitor->set_dim_all (tact->get_active());
}

void
ARDOUR_UI::monitor_cut_all ()
{
	boost::shared_ptr<Route> mon = _session->monitor_out ();
	if (!mon) {
		return;
	}
	boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();

	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-cut-all");
	_monitor->set_cut_all (tact->get_active());
}

void
ARDOUR_UI::monitor_mono ()
{
	boost::shared_ptr<Route> mon = _session->monitor_out ();
	if (!mon) {
		return;
	}
	boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();

	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-mono");
	_monitor->set_mono (tact->get_active());
}

Gtk::Menu*
ARDOUR_UI::shared_popup_menu ()
{
	ENSURE_GUI_THREAD (*this, &ARDOUR_UI::shared_popup_menu, ignored);

	assert (!_shared_popup_menu || !_shared_popup_menu->is_visible());
	delete _shared_popup_menu;
	_shared_popup_menu = new Gtk::Menu;
	return _shared_popup_menu;
}

void
ARDOUR_UI::set_flat_buttons ()
{
	CairoWidget::set_flat_buttons( UIConfiguration::instance().get_flat_buttons() );
}


void
ARDOUR_UI::update_transport_clocks (samplepos_t pos)
{
	switch (UIConfiguration::instance().get_primary_clock_delta_mode()) {
		case NoDelta:
			primary_clock->set (pos);
			break;
		case DeltaEditPoint:
			primary_clock->set (pos, false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD));
			break;
		case DeltaOriginMarker:
			{
				Location* loc = _session->locations()->clock_origin_location ();
				primary_clock->set (pos, false, loc ? loc->start() : 0);
			}
			break;
	}

	switch (UIConfiguration::instance().get_secondary_clock_delta_mode()) {
		case NoDelta:
			secondary_clock->set (pos);
			break;
		case DeltaEditPoint:
			secondary_clock->set (pos, false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD));
			break;
		case DeltaOriginMarker:
			{
				Location* loc = _session->locations()->clock_origin_location ();
				secondary_clock->set (pos, false, loc ? loc->start() : 0);
			}
			break;
	}

	if (big_clock_window) {
		big_clock->set (pos);
	}

	if (!editor->preview_video_drag_active ()) {
		ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor(pos);
	}
}


void
ARDOUR_UI::record_state_changed ()
{
	ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);

	if (!_session) {
		/* why bother - the clock isn't visible */
		return;
	}

	ActionManager::set_sensitive (ActionManager::rec_sensitive_actions, !_session->actively_recording());

	if (big_clock_window) {
		if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
			big_clock->set_active (true);
		} else {
			big_clock->set_active (false);
		}
	}

}