1 /*
2  * Copyright (C) 2005-2007 Doug McLain <doug@nostar.net>
3  * Copyright (C) 2005-2017 Tim Mayberry <mojofunk@gmail.com>
4  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
6  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
7  * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
8  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
9  * Copyright (C) 2008-2010 Sakari Bergen <sakari.bergen@beatwaves.net>
10  * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
11  * Copyright (C) 2013-2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
12  * Copyright (C) 2013-2016 John Emmas <john@creativepost.co.uk>
13  * Copyright (C) 2013-2016 Nick Mainsbridge <mainsbridge@gmail.com>
14  * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
15  * Copyright (C) 2015 André Nusser <andre.nusser@googlemail.com>
16  * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
17  * Copyright (C) 2017 Johannes Mueller <github@johannes-mueller.org>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 2 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License along
30  * with this program; if not, write to the Free Software Foundation, Inc.,
31  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32  */
33 
34 #ifdef WAF_BUILD
35 #include "gtk2ardour-config.h"
36 #include "gtk2ardour-version.h"
37 #endif
38 
39 #include "ardour/monitor_processor.h"
40 #include "ardour/session.h"
41 #include "ardour/route.h"
42 
43 #include "actions.h"
44 #include "ardour_ui.h"
45 #include "audio_clock.h"
46 #include "gui_thread.h"
47 #include "main_clock.h"
48 #include "public_editor.h"
49 #include "ui_config.h"
50 
51 #include "pbd/i18n.h"
52 
53 using namespace ARDOUR;
54 using namespace PBD;
55 using namespace Gtkmm2ext;
56 using namespace ArdourWidgets;
57 using namespace Gtk;
58 using namespace std;
59 using namespace Editing;
60 
61 void
cancel_solo()62 ARDOUR_UI::cancel_solo ()
63 {
64 	if (_session) {
65 		_session->cancel_all_solo ();
66 	}
67 }
68 
69 void
reset_focus(Gtk::Widget * w)70 ARDOUR_UI::reset_focus (Gtk::Widget* w)
71 {
72 	/* this resets focus to the first focusable parent of the given widget,
73 	 * or, if there is no focusable parent, cancels focus in the toplevel
74 	 * window that the given widget is packed into (if there is one).
75 	 */
76 
77 	if (!w) {
78 		return;
79 	}
80 
81 	Gtk::Widget* top = w->get_toplevel();
82 
83 	if (!top || !top->is_toplevel()) {
84 		return;
85 	}
86 
87 	w = w->get_parent ();
88 
89 	while (w) {
90 
91 		if (w->is_toplevel()) {
92 			/* Setting the focus widget to a Gtk::Window causes all
93 			 * subsequent calls to ::has_focus() on the nominal
94 			 * focus widget in that window to return
95 			 * false. Workaround: never set focus to the toplevel
96 			 * itself.
97 			 */
98 			break;
99 		}
100 
101 		if (w->get_can_focus ()) {
102 			Gtk::Window* win = dynamic_cast<Gtk::Window*> (top);
103 			win->set_focus (*w);
104 			return;
105 		}
106 		w = w->get_parent ();
107 	}
108 
109 	if (top == &_main_window) {
110 
111 	}
112 
113 	/* no focusable parent found, cancel focus in top level window.
114 	   C++ API cannot be used for this. Thanks, references.
115 	*/
116 
117 	gtk_window_set_focus (GTK_WINDOW(top->gobj()), 0);
118 
119 }
120 
121 void
monitor_dim_all()122 ARDOUR_UI::monitor_dim_all ()
123 {
124 	boost::shared_ptr<Route> mon = _session->monitor_out ();
125 	if (!mon) {
126 		return;
127 	}
128 	boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();
129 
130 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-dim-all");
131 	_monitor->set_dim_all (tact->get_active());
132 }
133 
134 void
monitor_cut_all()135 ARDOUR_UI::monitor_cut_all ()
136 {
137 	boost::shared_ptr<Route> mon = _session->monitor_out ();
138 	if (!mon) {
139 		return;
140 	}
141 	boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();
142 
143 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-cut-all");
144 	_monitor->set_cut_all (tact->get_active());
145 }
146 
147 void
monitor_mono()148 ARDOUR_UI::monitor_mono ()
149 {
150 	boost::shared_ptr<Route> mon = _session->monitor_out ();
151 	if (!mon) {
152 		return;
153 	}
154 	boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();
155 
156 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-mono");
157 	_monitor->set_mono (tact->get_active());
158 }
159 
160 Gtk::Menu*
shared_popup_menu()161 ARDOUR_UI::shared_popup_menu ()
162 {
163 	ENSURE_GUI_THREAD (*this, &ARDOUR_UI::shared_popup_menu, ignored);
164 
165 	assert (!_shared_popup_menu || !_shared_popup_menu->is_visible());
166 	delete _shared_popup_menu;
167 	_shared_popup_menu = new Gtk::Menu;
168 	return _shared_popup_menu;
169 }
170 
171 void
set_flat_buttons()172 ARDOUR_UI::set_flat_buttons ()
173 {
174 	CairoWidget::set_flat_buttons( UIConfiguration::instance().get_flat_buttons() );
175 }
176 
177 
178 void
update_transport_clocks(samplepos_t pos)179 ARDOUR_UI::update_transport_clocks (samplepos_t pos)
180 {
181 	switch (UIConfiguration::instance().get_primary_clock_delta_mode()) {
182 		case NoDelta:
183 			primary_clock->set (pos);
184 			break;
185 		case DeltaEditPoint:
186 			primary_clock->set (pos, false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD));
187 			break;
188 		case DeltaOriginMarker:
189 			{
190 				Location* loc = _session->locations()->clock_origin_location ();
191 				primary_clock->set (pos, false, loc ? loc->start() : 0);
192 			}
193 			break;
194 	}
195 
196 	switch (UIConfiguration::instance().get_secondary_clock_delta_mode()) {
197 		case NoDelta:
198 			secondary_clock->set (pos);
199 			break;
200 		case DeltaEditPoint:
201 			secondary_clock->set (pos, false, editor->get_preferred_edit_position (EDIT_IGNORE_PHEAD));
202 			break;
203 		case DeltaOriginMarker:
204 			{
205 				Location* loc = _session->locations()->clock_origin_location ();
206 				secondary_clock->set (pos, false, loc ? loc->start() : 0);
207 			}
208 			break;
209 	}
210 
211 	if (big_clock_window) {
212 		big_clock->set (pos);
213 	}
214 
215 	if (!editor->preview_video_drag_active ()) {
216 		ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor(pos);
217 	}
218 }
219 
220 
221 void
record_state_changed()222 ARDOUR_UI::record_state_changed ()
223 {
224 	ENSURE_GUI_THREAD (*this, &ARDOUR_UI::record_state_changed);
225 
226 	if (!_session) {
227 		/* why bother - the clock isn't visible */
228 		return;
229 	}
230 
231 	ActionManager::set_sensitive (ActionManager::rec_sensitive_actions, !_session->actively_recording());
232 
233 	if (_session->record_status () == Session::Recording && _session->have_rec_enabled_track ()) {
234 		big_clock->set_active (true);
235 	} else {
236 		big_clock->set_active (false);
237 	}
238 }
239