1 /*
2  * Copyright (C) 2005-2008 Nick Mainsbridge <mainsbridge@gmail.com>
3  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
5  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
6  * Copyright (C) 2007-2011 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2014 Ben Loftis <ben@harrisonconsoles.com>
9  * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifdef WAF_BUILD
27 #include "gtk2ardour-config.h"
28 #endif
29 
30 #include <glibmm/miscutils.h>
31 #include <gtkmm/messagedialog.h>
32 #include <gtkmm2ext/utils.h>
33 #include <gtkmm2ext/window_title.h>
34 
35 #include "pbd/enumwriter.h"
36 
37 #include "ardour/rc_configuration.h"
38 
39 #include "control_protocol/control_protocol.h"
40 
41 #include "actions.h"
42 #include "ardour_ui.h"
43 #include "audio_time_axis.h"
44 #include "automation_time_axis.h"
45 #include "editor.h"
46 #include "editor_route_groups.h"
47 #include "editor_regions.h"
48 #include "enums_convert.h"
49 #include "gui_thread.h"
50 #include "midi_time_axis.h"
51 #include "mixer_strip.h"
52 #include "mixer_ui.h"
53 #include "selection.h"
54 #include "ui_config.h"
55 
56 #include "pbd/i18n.h"
57 
58 using namespace std;
59 using namespace Gtkmm2ext;
60 using namespace PBD;
61 
62 void
editor_mixer_button_toggled()63 Editor::editor_mixer_button_toggled ()
64 {
65 	Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
66 	if (act) {
67 		Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
68 		show_editor_mixer (tact->get_active());
69 	}
70 }
71 
72 void
editor_list_button_toggled()73 Editor::editor_list_button_toggled ()
74 {
75 	Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
76 	if (act) {
77 		Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
78 		show_editor_list (tact->get_active());
79 	}
80 }
81 
82 void
show_editor_mixer(bool yn)83 Editor::show_editor_mixer (bool yn)
84 {
85 	boost::shared_ptr<ARDOUR::Route> r;
86 
87 	show_editor_mixer_when_tracks_arrive = false;
88 
89 	if (yn) {
90 		Gtk::Window* toplevel = current_toplevel();
91 		Glib::RefPtr<Gdk::Window> win;
92 		Glib::RefPtr<Gdk::Screen> screen;
93 
94 		if (toplevel) {
95 			win = toplevel->get_window();
96 		}
97 
98 		if (win) {
99 			screen = win->get_screen();
100 		} else {
101 			screen = Gdk::Screen::get_default();
102 		}
103 
104 		if (g_getenv ("ARDOUR_LOVES_STUPID_TINY_SCREENS") == 0 && screen && screen->get_height() < 700) {
105 			Gtk::MessageDialog msg (_("This screen is not tall enough to display the editor mixer"));
106 			msg.run ();
107 			return;
108 		}
109 	}
110 
111 	if (!_session) {
112 		show_editor_mixer_when_tracks_arrive = yn;
113 		return;
114 	}
115 
116 	if (yn) {
117 
118 		if (selection->tracks.empty()) {
119 
120 			if (track_views.empty()) {
121 				show_editor_mixer_when_tracks_arrive = true;
122 				return;
123 			}
124 
125 			for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
126 				RouteTimeAxisView* atv;
127 
128 				if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
129 					r = atv->route();
130 					break;
131 				}
132 			}
133 
134 		} else {
135 			sort_track_selection (selection->tracks);
136 
137 			for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
138 				RouteTimeAxisView* atv;
139 
140 				if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
141 					r = atv->route();
142 					break;
143 				}
144 			}
145 		}
146 
147 		if (r) {
148 			if (current_mixer_strip == 0) {
149 				create_editor_mixer ();
150 			}
151 		}
152 
153 		if (current_mixer_strip && current_mixer_strip->get_parent() == 0) {
154 			global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
155 			global_hpacker.reorder_child (*current_mixer_strip, 0);
156 			current_mixer_strip->show ();
157 		}
158 
159 		if (r) {
160 			current_mixer_strip->set_route (r);
161 			current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
162 		}
163 
164 	} else {
165 
166 		if (current_mixer_strip) {
167 			if (current_mixer_strip->get_parent() != 0) {
168 				global_hpacker.remove (*current_mixer_strip);
169 			}
170 		}
171 	}
172 
173 #ifdef __APPLE__
174 	/* XXX gtk problem here */
175 	ensure_all_elements_drawn();
176 #endif
177 }
178 
179 #ifdef __APPLE__
180 void
ensure_all_elements_drawn()181 Editor::ensure_all_elements_drawn ()
182 {
183 	controls_layout.queue_draw ();
184 	time_bars_event_box.queue_draw ();
185 }
186 #endif
187 
188 void
create_editor_mixer()189 Editor::create_editor_mixer ()
190 {
191 	current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(), _session, false);
192 	current_mixer_strip->Hiding.connect (sigc::mem_fun(*this, &Editor::current_mixer_strip_hidden));
193 	current_mixer_strip->WidthChanged.connect (sigc::mem_fun (*this, &Editor::mixer_strip_width_changed));
194 
195 #ifdef __APPLE__
196 	current_mixer_strip->WidthChanged.connect (sigc::mem_fun(*this, &Editor::ensure_all_elements_drawn));
197 #endif
198 	current_mixer_strip->set_embedded (true);
199 
200 }
201 
202 void
set_selected_mixer_strip(TimeAxisView & view)203 Editor::set_selected_mixer_strip (TimeAxisView& view)
204 {
205 	if (!_session) {
206 		return;
207 	}
208 
209 	// if this is an automation track, then we shold the mixer strip should
210 	// show the parent
211 
212 	boost::shared_ptr<ARDOUR::Stripable> stripable;
213 	AutomationTimeAxisView* atv;
214 
215 	if ((atv = dynamic_cast<AutomationTimeAxisView*>(&view)) != 0) {
216 		AudioTimeAxisView *parent = dynamic_cast<AudioTimeAxisView*>(view.get_parent());
217 		if (parent) {
218 			stripable = parent->stripable ();
219 		}
220 	} else {
221 		StripableTimeAxisView* stav = dynamic_cast<StripableTimeAxisView*> (&view);
222 		if (stav) {
223 			stripable = stav->stripable();
224 		}
225 	}
226 
227 	Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
228 
229 	if (act) {
230 		Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
231 		if (!tact || !tact->get_active()) {
232 			/* not showing mixer strip presently */
233 			return;
234 		}
235 	}
236 
237 	if (current_mixer_strip == 0) {
238 		create_editor_mixer ();
239 	}
240 
241 	boost::shared_ptr<ARDOUR::Route> route = boost::dynamic_pointer_cast<ARDOUR::Route> (stripable);
242 	if (current_mixer_strip->route() == route) {
243 		return;
244 	}
245 
246 	if (route) {
247 		current_mixer_strip->set_route (route);
248 		current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
249 	}
250 }
251 
252 void
current_mixer_strip_hidden()253 Editor::current_mixer_strip_hidden ()
254 {
255 	Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
256 	if (act) {
257 		Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
258 		tact->set_active (false);
259 	}
260 }
261 
262 void
maybe_add_mixer_strip_width(XMLNode & node)263 Editor::maybe_add_mixer_strip_width (XMLNode& node)
264 {
265 	if (current_mixer_strip) {
266 		node.set_property ("mixer-width", editor_mixer_strip_width);
267 	}
268 }
269 
270 void
mixer_strip_width_changed()271 Editor::mixer_strip_width_changed ()
272 {
273 #ifdef __APPLE__
274 	ensure_all_elements_drawn ();
275 #endif
276 
277 	editor_mixer_strip_width = current_mixer_strip->get_width_enum ();
278 }
279