put the issue of using a monitor section into ~/.config/ardour.rc, not the session...
[ardour2.git] / gtk2_ardour / ardour_ui_dialogs.cc
bloba15d8fc2bee3c6878411c1bb4b037e6f54c33af7
1 /*
2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* This file contains any ARDOUR_UI methods that require knowledge of
21 the various dialog boxes, and exists so that no compilation dependency
22 exists between the main ARDOUR_UI modules and their respective classes.
23 This is to cut down on the compile times. It also helps with my sanity.
26 #include "ardour/session.h"
28 #include "actions.h"
29 #include "ardour_ui.h"
30 #include "location_ui.h"
31 #include "mixer_ui.h"
32 #include "rc_option_editor.h"
33 #include "session_option_editor.h"
34 #include "public_editor.h"
35 #include "route_params_ui.h"
36 #include "sfdb_ui.h"
37 #include "theme_manager.h"
38 #include "bundle_manager.h"
39 #include "keyeditor.h"
40 #include "gui_thread.h"
42 #include "i18n.h"
44 using namespace ARDOUR;
45 using namespace PBD;
46 using namespace Glib;
47 using namespace Gtk;
48 using namespace Gtkmm2ext;
50 void
51 ARDOUR_UI::set_session (Session *s)
53 SessionHandlePtr::set_session (s);
55 if (!_session) {
56 return;
59 if (location_ui) {
60 location_ui->set_session(s);
63 if (route_params) {
64 route_params->set_session (s);
67 primary_clock.set_session (s);
68 secondary_clock.set_session (s);
69 big_clock.set_session (s);
70 preroll_clock.set_session (s);
71 postroll_clock.set_session (s);
73 /* sensitize menu bar options that are now valid */
75 ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
76 ActionManager::set_sensitive (ActionManager::write_sensitive_actions, _session->writable());
78 if (_session->locations()->num_range_markers()) {
79 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
80 } else {
81 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
84 if (!_session->control_out()) {
85 Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), X_("SoloViaBus"));
86 if (act) {
87 act->set_sensitive (false);
91 /* allow wastebasket flush again */
93 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
94 if (act) {
95 act->set_sensitive (true);
98 /* there are never any selections on startup */
100 ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, false);
101 ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, false);
102 ActionManager::set_sensitive (ActionManager::line_selection_sensitive_actions, false);
103 ActionManager::set_sensitive (ActionManager::point_selection_sensitive_actions, false);
104 ActionManager::set_sensitive (ActionManager::playlist_selection_sensitive_actions, false);
106 rec_button.set_sensitive (true);
107 shuttle_box.set_sensitive (true);
108 solo_alert_button.set_active (_session->soloing());
110 setup_session_options ();
112 Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
113 Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::solo_blink));
114 Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::sync_blink));
115 Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::audition_blink));
117 _session->RecordStateChanged.connect (_session_connections, boost::bind (&ARDOUR_UI::record_state_changed, this), gui_context());
118 _session->TransportStateChange.connect (_session_connections, boost::bind (&ARDOUR_UI::map_transport_state, this), gui_context());
119 _session->DirtyChanged.connect (_session_connections, boost::bind (&ARDOUR_UI::update_autosave, this), gui_context());
121 _session->Xrun.connect (_session_connections, ui_bind (&ARDOUR_UI::xrun_handler, this, _1), gui_context());
122 _session->SoloActive.connect (_session_connections, ui_bind (&ARDOUR_UI::soloing_changed, this, _1), gui_context());
123 _session->AuditionActive.connect (_session_connections, ui_bind (&ARDOUR_UI::auditioning_changed, this, _1), gui_context());
124 _session->locations()->added.connect (_session_connections, ui_bind (&ARDOUR_UI::handle_locations_change, this, _1), gui_context());
125 _session->locations()->removed.connect (_session_connections, ui_bind (&ARDOUR_UI::handle_locations_change, this, _1), gui_context());
127 /* Clocks are on by default after we are connected to a session, so show that here.
130 connect_dependents_to_session (s);
132 /* listen to clock mode changes. don't do this earlier because otherwise as the clocks
133 restore their modes or are explicitly set, we will cause the "new" mode to be saved
134 back to the session XML ("Extra") state.
137 AudioClock::ModeChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::store_clock_modes));
139 Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::first_idle));
141 start_clocking ();
142 start_blinking ();
144 map_transport_state ();
146 second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_second), 1000);
147 point_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
148 point_zero_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
152 ARDOUR_UI::unload_session (bool hide_stuff)
154 if (_session && _session->dirty()) {
155 switch (ask_about_saving_session (_("close"))) {
156 case -1:
157 // cancel
158 return 1;
160 case 1:
161 _session->save_state ("");
162 break;
166 if (hide_stuff) {
167 editor->hide ();
168 mixer->hide ();
169 theme_manager->hide ();
172 second_connection.disconnect ();
173 point_one_second_connection.disconnect ();
174 point_oh_five_second_connection.disconnect ();
175 point_zero_one_second_connection.disconnect();
177 ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
179 rec_button.set_sensitive (false);
180 shuttle_box.set_sensitive (false);
182 stop_blinking ();
183 stop_clocking ();
185 /* drop everything attached to the blink signal */
187 Blink.clear ();
189 delete _session;
191 update_buffer_load ();
193 return 0;
196 void
197 ARDOUR_UI::toggle_big_clock_window ()
199 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
200 if (act) {
201 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
203 if (tact->get_active()) {
204 big_clock_window->show_all ();
205 big_clock_window->present ();
206 } else {
207 big_clock_window->hide ();
212 void
213 ARDOUR_UI::toggle_rc_options_window ()
215 if (rc_option_editor == 0) {
216 rc_option_editor = new RCOptionEditor;
217 rc_option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleRCOptionsEditor")));
218 rc_option_editor->set_session (_session);
221 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleRCOptionsEditor"));
222 if (act) {
223 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
225 if (tact->get_active()) {
226 rc_option_editor->show_all ();
227 rc_option_editor->present ();
228 } else {
229 rc_option_editor->hide ();
234 void
235 ARDOUR_UI::toggle_session_options_window ()
237 if (session_option_editor == 0) {
238 session_option_editor = new SessionOptionEditor (_session);
239 session_option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSessionOptionsEditor")));
242 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSessionOptionsEditor"));
243 if (act) {
244 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
246 if (tact->get_active()) {
247 session_option_editor->show_all ();
248 session_option_editor->present ();
249 } else {
250 session_option_editor->hide ();
256 ARDOUR_UI::create_location_ui ()
258 if (location_ui == 0) {
259 location_ui = new LocationUIWindow ();
260 location_ui->set_session (_session);
261 location_ui->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
263 return 0;
266 void
267 ARDOUR_UI::toggle_location_window ()
269 if (create_location_ui()) {
270 return;
273 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
274 if (act) {
275 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
277 if (tact->get_active()) {
278 location_ui->show_all ();
279 location_ui->present ();
280 } else {
281 location_ui->hide ();
286 void
287 ARDOUR_UI::toggle_key_editor ()
289 if (key_editor == 0) {
290 key_editor = new KeyEditor;
291 key_editor->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleKeyEditor")));
294 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleKeyEditor"));
295 if (act) {
296 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
298 if (tact->get_active()) {
299 key_editor->show_all ();
300 key_editor->present ();
301 } else {
302 key_editor->hide ();
307 void
308 ARDOUR_UI::toggle_theme_manager ()
310 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleThemeManager"));
311 if (act) {
312 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
314 if (tact->get_active()) {
315 theme_manager->show_all ();
316 theme_manager->present ();
317 } else {
318 theme_manager->hide ();
323 void
324 ARDOUR_UI::create_bundle_manager ()
326 if (bundle_manager == 0) {
327 bundle_manager = new BundleManager (_session);
328 bundle_manager->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBundleManager")));
332 void
333 ARDOUR_UI::toggle_bundle_manager ()
335 create_bundle_manager ();
337 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBundleManager"));
338 if (act) {
339 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
341 if (tact->get_active()) {
342 bundle_manager->show_all ();
343 bundle_manager->present ();
344 } else {
345 bundle_manager->hide ();
351 ARDOUR_UI::create_route_params ()
353 if (route_params == 0) {
354 route_params = new RouteParams_UI ();
355 route_params->set_session (_session);
356 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
358 return 0;
361 void
362 ARDOUR_UI::toggle_route_params_window ()
364 if (create_route_params ()) {
365 return;
368 RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
369 if (act) {
370 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
372 if (tact->get_active()) {
373 route_params->show_all ();
374 route_params->present ();
375 } else {
376 route_params->hide ();
381 void
382 ARDOUR_UI::handle_locations_change (Location *)
384 if (_session) {
385 if (_session->locations()->num_range_markers()) {
386 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
387 } else {
388 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
393 bool
394 ARDOUR_UI::main_window_state_event_handler (GdkEventWindowState* ev, bool window_was_editor)
396 if (window_was_editor) {
398 if ((ev->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) &&
399 (ev->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
400 float_big_clock (editor);
403 } else {
405 if ((ev->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) &&
406 (ev->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
407 float_big_clock (mixer);
411 return false;