enable videotimeline by default
[ardour.git] / gtk2_ardour / ardour_ui_dialogs.cc
1 /*
2     Copyright (C) 2000 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
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.
24 */
25
26 #include "ardour/session.h"
27 #include "ardour/audioengine.h"
28 #include "ardour/automation_watch.h"
29
30 #include "actions.h"
31 #include "add_route_dialog.h"
32 #include "ardour_ui.h"
33 #include "bundle_manager.h"
34 #include "global_port_matrix.h"
35 #include "gui_object.h"
36 #include "gui_thread.h"
37 #include "keyeditor.h"
38 #include "location_ui.h"
39 #include "main_clock.h"
40 #include "midi_tracer.h"
41 #include "mixer_ui.h"
42 #include "public_editor.h"
43 #include "rc_option_editor.h"
44 #include "route_params_ui.h"
45 #include "shuttle_control.h"
46 #include "session_option_editor.h"
47 #include "speaker_dialog.h"
48 #include "sfdb_ui.h"
49 #include "theme_manager.h"
50 #include "time_info_box.h"
51
52 #include "i18n.h"
53
54 using namespace ARDOUR;
55 using namespace PBD;
56 using namespace Glib;
57 using namespace Gtk;
58 using namespace Gtkmm2ext;
59
60 void
61 ARDOUR_UI::set_session (Session *s)
62 {
63         SessionHandlePtr::set_session (s);
64
65         for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
66                 GlobalPortMatrixWindow* w;
67                 if ((w = _global_port_matrix[*i]->get()) != 0) {
68                         w->set_session (s);
69                 }
70         }
71
72         if (!_session) {
73                 return;
74         }
75
76         const XMLNode* node = _session->extra_xml (X_("UI"));
77
78         if (node) {
79                 const XMLNodeList& children = node->children();
80                 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
81                         if ((*i)->name() == GUIObjectState::xml_node_name) {
82                                 gui_object_state->load (**i);
83                                 break;
84                         }
85                 }
86         }
87
88         AutomationWatch::instance().set_session (s);
89
90         if (location_ui->get()) {
91                 location_ui->get()->set_session(s);
92         }
93
94         if (speaker_config_window->get()) {
95                 speaker_config_window->get()->set_speakers (s->get_speakers());
96         }
97
98         if (route_params) {
99                 route_params->set_session (s);
100         }
101
102         if (add_route_dialog) {
103                 add_route_dialog->set_session (s);
104         }
105
106         if (session_option_editor) {
107                 session_option_editor->set_session (s);
108         }
109
110         if (shuttle_box) {
111                 shuttle_box->set_session (s);
112         }
113
114         for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
115                 if (_global_port_matrix[*i]->get()) {
116                         _global_port_matrix[*i]->get()->set_session (_session);
117                 }
118         }
119
120         primary_clock->set_session (s);
121         secondary_clock->set_session (s);
122         big_clock->set_session (s);
123         time_info_box->set_session (s);
124         video_timeline->set_session (s);
125
126         /* sensitize menu bar options that are now valid */
127
128         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
129         ActionManager::set_sensitive (ActionManager::write_sensitive_actions, _session->writable());
130
131         if (_session->locations()->num_range_markers()) {
132                 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
133         } else {
134                 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
135         }
136
137         if (!_session->monitor_out()) {
138                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), X_("SoloViaBus"));
139                 if (act) {
140                         act->set_sensitive (false);
141                 }
142         }
143
144         /* allow wastebasket flush again */
145
146         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
147         if (act) {
148                 act->set_sensitive (true);
149         }
150
151         /* there are never any selections on startup */
152
153         ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, false);
154         ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, false);
155         ActionManager::set_sensitive (ActionManager::line_selection_sensitive_actions, false);
156         ActionManager::set_sensitive (ActionManager::point_selection_sensitive_actions, false);
157         ActionManager::set_sensitive (ActionManager::playlist_selection_sensitive_actions, false);
158
159         rec_button.set_sensitive (true);
160
161         solo_alert_button.set_active (_session->soloing());
162
163         setup_session_options ();
164
165         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
166         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::solo_blink));
167         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::sync_blink));
168         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::audition_blink));
169         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::feedback_blink));
170
171         _session->RecordStateChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::record_state_changed, this), gui_context());
172         _session->StepEditStatusChange.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::step_edit_status_change, this, _1), gui_context());
173         _session->TransportStateChange.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::map_transport_state, this), gui_context());
174         _session->DirtyChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::update_autosave, this), gui_context());
175
176         _session->Xrun.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::xrun_handler, this, _1), gui_context());
177         _session->SoloActive.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::soloing_changed, this, _1), gui_context());
178         _session->AuditionActive.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::auditioning_changed, this, _1), gui_context());
179         _session->locations()->added.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::handle_locations_change, this, _1), gui_context());
180         _session->locations()->removed.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::handle_locations_change, this, _1), gui_context());
181         _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::session_parameter_changed, this, _1), gui_context ());
182
183 #ifdef HAVE_JACK_SESSION
184         engine->JackSessionEvent.connect (*_session, MISSING_INVALIDATOR, boost::bind (&Session::jack_session_event, _session, _1), gui_context());
185 #endif
186
187         /* Clocks are on by default after we are connected to a session, so show that here.
188         */
189
190         connect_dependents_to_session (s);
191
192         /* listen to clock mode changes. don't do this earlier because otherwise as the clocks
193            restore their modes or are explicitly set, we will cause the "new" mode to be saved
194            back to the session XML ("Extra") state.
195          */
196
197         AudioClock::ModeChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::store_clock_modes));
198
199         Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::first_idle));
200
201         start_clocking ();
202         start_blinking ();
203
204         map_transport_state ();
205
206         second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_second), 1000);
207         point_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
208         point_zero_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
209
210         update_format ();
211 }
212
213 int
214 ARDOUR_UI::unload_session (bool hide_stuff)
215 {
216         if (_session) {
217                 ARDOUR_UI::instance()->video_timeline->sync_session_state();
218         }
219
220         if (_session && _session->dirty()) {
221                 std::vector<std::string> actions;
222                 actions.push_back (_("Don't close"));
223                 actions.push_back (_("Just close"));
224                 actions.push_back (_("Save and close"));
225                 switch (ask_about_saving_session (actions)) {
226                 case -1:
227                         // cancel
228                         return 1;
229
230                 case 1:
231                         _session->save_state ("");
232                         break;
233                 }
234         }
235
236         if (hide_stuff) {
237                 editor->hide ();
238                 mixer->hide ();
239                 theme_manager->hide ();
240         }
241
242         second_connection.disconnect ();
243         point_one_second_connection.disconnect ();
244         point_oh_five_second_connection.disconnect ();
245         point_zero_one_second_connection.disconnect();
246
247         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
248
249         rec_button.set_sensitive (false);
250
251         ARDOUR_UI::instance()->video_timeline->close_session();
252
253         stop_blinking ();
254         stop_clocking ();
255
256         /* drop everything attached to the blink signal */
257
258         Blink.clear ();
259
260         delete _session;
261         _session = 0;
262
263         session_loaded = false;
264
265         update_buffer_load ();
266
267         return 0;
268 }
269
270 void
271 ARDOUR_UI::toggle_big_clock_window ()
272 {
273         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
274         if (act) {
275                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
276
277                 if (tact->get_active()) {
278                         big_clock_window->get()->show_all ();
279                         big_clock_window->get()->present ();
280                 } else {
281                         big_clock_window->get()->hide ();
282                 }
283         }
284 }
285
286 void
287 ARDOUR_UI::toggle_speaker_config_window ()
288 {
289         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-speaker-config"));
290         if (act) {
291                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
292
293                 if (tact->get_active()) {
294                         speaker_config_window->get()->show_all ();
295                         speaker_config_window->get()->present ();
296                 } else {
297                         speaker_config_window->get()->hide ();
298                 }
299         }
300 }
301
302 void
303 ARDOUR_UI::new_midi_tracer_window ()
304 {
305         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("NewMIDITracer"));
306         if (!act) {
307                 return;
308         }
309
310         std::list<MidiTracer*>::iterator i = _midi_tracer_windows.begin ();
311         while (i != _midi_tracer_windows.end() && (*i)->get_visible() == true) {
312                 ++i;
313         }
314
315         if (i == _midi_tracer_windows.end()) {
316                 /* all our MIDITracer windows are visible; make a new one */
317                 MidiTracer* t = new MidiTracer ();
318                 manage_window (*t);
319                 t->show_all ();
320                 _midi_tracer_windows.push_back (t);
321         } else {
322                 /* re-use the hidden one */
323                 (*i)->show_all ();
324         }
325 }
326
327 void
328 ARDOUR_UI::toggle_rc_options_window ()
329 {
330         if (rc_option_editor == 0) {
331                 rc_option_editor = new RCOptionEditor;
332                 rc_option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleRCOptionsEditor")));
333                 rc_option_editor->set_session (_session);
334         }
335
336         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleRCOptionsEditor"));
337         if (act) {
338                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
339
340                 if (tact->get_active()) {
341                         rc_option_editor->show_all ();
342                         rc_option_editor->present ();
343                 } else {
344                         rc_option_editor->hide ();
345                 }
346         }
347 }
348
349 void
350 ARDOUR_UI::toggle_session_options_window ()
351 {
352         if (session_option_editor == 0) {
353                 session_option_editor = new SessionOptionEditor (_session);
354                 session_option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSessionOptionsEditor")));
355         }
356
357         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSessionOptionsEditor"));
358         if (act) {
359                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
360
361                 if (tact->get_active()) {
362                         session_option_editor->show_all ();
363                         session_option_editor->present ();
364                 } else {
365                         session_option_editor->hide ();
366                 }
367         }
368 }
369
370 int
371 ARDOUR_UI::create_location_ui ()
372 {
373         if (location_ui->get() == 0) {
374                 location_ui->set (new LocationUIWindow ());
375                 location_ui->get()->set_session (_session);
376                 location_ui->get()->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
377         }
378         return 0;
379 }
380
381 void
382 ARDOUR_UI::toggle_location_window ()
383 {
384         if (create_location_ui()) {
385                 return;
386         }
387
388         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
389         if (act) {
390                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
391
392                 if (tact->get_active()) {
393                         location_ui->get()->show_all ();
394                         location_ui->get()->present ();
395                 } else {
396                         location_ui->get()->hide ();
397                 }
398         }
399 }
400
401 void
402 ARDOUR_UI::toggle_key_editor ()
403 {
404         if (key_editor == 0) {
405                 key_editor = new KeyEditor;
406                 key_editor->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleKeyEditor")));
407         }
408
409         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleKeyEditor"));
410         if (act) {
411                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
412
413                 if (tact->get_active()) {
414                         key_editor->show_all ();
415                         key_editor->present ();
416                 } else {
417                         key_editor->hide ();
418                 }
419         }
420 }
421
422 void
423 ARDOUR_UI::toggle_theme_manager ()
424 {
425         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleThemeManager"));
426         if (act) {
427                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
428
429                 if (tact->get_active()) {
430                         theme_manager->show_all ();
431                         theme_manager->present ();
432                 } else {
433                         theme_manager->hide ();
434                 }
435         }
436 }
437
438 void
439 ARDOUR_UI::create_bundle_manager ()
440 {
441         if (bundle_manager == 0) {
442                 bundle_manager = new BundleManager (_session);
443                 bundle_manager->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBundleManager")));
444         }
445 }
446
447 void
448 ARDOUR_UI::toggle_bundle_manager ()
449 {
450         create_bundle_manager ();
451
452         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBundleManager"));
453         if (act) {
454                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
455
456                 if (tact->get_active()) {
457                         bundle_manager->show_all ();
458                         bundle_manager->present ();
459                 } else {
460                         bundle_manager->hide ();
461                 }
462         }
463 }
464
465 int
466 ARDOUR_UI::create_route_params ()
467 {
468         if (route_params == 0) {
469                 route_params = new RouteParams_UI ();
470                 route_params->set_session (_session);
471                 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
472         }
473         return 0;
474 }
475
476 void
477 ARDOUR_UI::toggle_route_params_window ()
478 {
479         if (create_route_params ()) {
480                 return;
481         }
482
483         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
484         if (act) {
485                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
486
487                 if (tact->get_active()) {
488                         route_params->show_all ();
489                         route_params->present ();
490                 } else {
491                         route_params->hide ();
492                 }
493         }
494 }
495
496 void
497 ARDOUR_UI::handle_locations_change (Location *)
498 {
499         if (_session) {
500                 if (_session->locations()->num_range_markers()) {
501                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
502                 } else {
503                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
504                 }
505         }
506 }
507
508 bool
509 ARDOUR_UI::main_window_state_event_handler (GdkEventWindowState* ev, bool window_was_editor)
510 {
511         if (window_was_editor) {
512
513                 if ((ev->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) &&
514                     (ev->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
515                         float_big_clock (editor);
516                 }
517
518         } else {
519
520                 if ((ev->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) &&
521                     (ev->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
522                         float_big_clock (mixer);
523                 }
524         }
525
526         return false;
527 }