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.
21 #include "gtk2ardour-config.h"
24 /* this file exists solely to break compilation dependencies that
25 would connect changes to the mixer or editor objects.
30 #include "pbd/error.h"
33 #include "ardour/session.h"
35 #include "gtkmm2ext/bindings.h"
38 #include "ardour_ui.h"
39 #include "public_editor.h"
40 #include "meterbridge.h"
41 #include "luainstance.h"
42 #include "luawindow.h"
45 #include "keyeditor.h"
47 #include "rc_option_editor.h"
48 #include "route_params_ui.h"
49 #include "time_info_box.h"
50 #include "step_entry.h"
63 using namespace ARDOUR;
64 using namespace Gtkmm2ext;
67 ARDOUR_UI::we_have_dependents ()
69 install_dependent_actions ();
71 /* The monitor section relies on at least 1 action defined by us. Since that
72 * action now exists, give it a chance to use it.
74 mixer->monitor_section().use_others_actions ();
76 /* Create "static" actions that apply to all ProcessorBoxes
78 ProcessorBox::register_actions ();
79 StepEntry::setup_actions_and_bindings ();
81 /* Global, editor, mixer, processor box actions are defined now. Link
82 them with any bindings, so that GTK does not get a chance to define
83 the GTK accel map entries first when we ask the GtkUIManager to
86 If GTK adds the actions to its accel map before we do, we lose our
87 freedom to use any keys. More precisely, we can use any keys, but
88 ones that GTK considers illegal as accelerators will not show up in
91 There are other dynamic actions that can be created by a monitor
92 section, by step entry dialogs. These need to be handled
93 separately. They don't tend to use GTK-illegal bindings and more
94 importantly they don't have menus showing the bindings, so it is
98 Gtkmm2ext::Bindings::associate_all ();
100 editor->setup_tooltips ();
101 editor->UpdateAllTransportClocks.connect (sigc::mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
103 /* catch up on tabbable state, in the right order to leave the editor
104 * selected by default
107 tabbable_state_change (*rc_option_editor);
108 tabbable_state_change (*mixer);
109 tabbable_state_change (*editor);
111 /* all actions are defined */
113 ActionManager::load_menus (ARDOUR_COMMAND_LINE::menus_file);
115 /* catch up on parameters */
117 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
118 Config->map_parameters (pc);
120 UIConfiguration::instance().reset_dpi ();
124 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
127 BootMessage (_("Setup Editor"));
128 editor->set_session (s);
129 BootMessage (_("Setup Mixer"));
130 mixer->set_session (s);
131 meterbridge->set_session (s);
132 luawindow->set_session (s);
134 /* its safe to do this now */
136 BootMessage (_("Reload Session History"));
137 s->restore_history ("");
140 /** The main editor window has been closed */
142 ARDOUR_UI::exit_on_main_window_close (GdkEventAny * /*ev*/)
145 /* just hide the window, and return - the top menu stays up */
149 /* time to get out of here */
156 ARDOUR_UI::tab_window_root_drop (GtkNotebook* src,
163 Gtk::Notebook* nb = 0;
164 Gtk::Window* win = 0;
165 ArdourWidgets::Tabbable* tabbable = 0;
168 if (w == GTK_WIDGET(editor->contents().gobj())) {
170 } else if (w == GTK_WIDGET(mixer->contents().gobj())) {
172 } else if (w == GTK_WIDGET(rc_option_editor->contents().gobj())) {
173 tabbable = rc_option_editor;
178 nb = tabbable->tab_root_drop ();
179 win = tabbable->own_window ();
188 return 0; /* what was that? */
192 ARDOUR_UI::idle_ask_about_quit ()
194 if (_session && _session->dirty()) {
197 /* no session or session not dirty, but still ask anyway */
199 Gtk::MessageDialog msg (string_compose (_("Quit %1?"), PROGRAM_NAME),
200 false, /* no markup */
204 msg.set_default_response (Gtk::RESPONSE_YES);
206 if (msg.run() == Gtk::RESPONSE_YES) {
211 /* not reached but keep the compiler happy */
217 ARDOUR_UI::main_window_delete_event (GdkEventAny* ev)
219 /* quit the application as soon as we go idle. If we call this here,
220 * the window manager/desktop can think we're taking too longer to
221 * handle the "delete" event
224 Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_ask_about_quit));
230 tab_window_root_drop (GtkNotebook* src,
236 return ARDOUR_UI::instance()->tab_window_root_drop (src, w, x, y, user_data);
240 ARDOUR_UI::setup_windows ()
242 _tabs.set_show_border(false);
243 _tabs.signal_switch_page().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_switch));
244 _tabs.signal_page_added().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_page_added));
245 _tabs.signal_page_removed().connect (sigc::mem_fun (*this, &ARDOUR_UI::tabs_page_removed));
247 rc_option_editor = new RCOptionEditor;
248 rc_option_editor->StateChange.connect (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_state_change));
250 if (create_editor ()) {
251 error << _("UI: cannot setup editor") << endmsg;
255 if (create_mixer ()) {
256 error << _("UI: cannot setup mixer") << endmsg;
260 if (create_meterbridge ()) {
261 error << _("UI: cannot setup meterbridge") << endmsg;
265 if (create_luawindow ()) {
266 error << _("UI: cannot setup luawindow") << endmsg;
270 time_info_box = new TimeInfoBox ("ToolbarTimeInfo", false);
271 /* all other dialogs are created conditionally */
273 we_have_dependents ();
275 /* order of addition affects order seen in initial window display */
277 rc_option_editor->add_to_notebook (_tabs, _("Preferences"));
278 mixer->add_to_notebook (_tabs, _("Mixer"));
279 editor->add_to_notebook (_tabs, _("Editor"));
281 top_packer.pack_start (menu_bar_base, false, false);
283 main_vpacker.pack_start (top_packer, false, false);
285 ArdourWidgets::ArdourDropShadow *spacer = manage (new (ArdourWidgets::ArdourDropShadow));
286 spacer->set_size_request( -1, 4 );
289 /* now add the transport sample to the top of main window */
291 main_vpacker.pack_start ( *spacer, false, false);
292 main_vpacker.pack_start (transport_frame, false, false);
293 main_vpacker.pack_start (_tabs, true, true);
295 LuaInstance::instance()->ActionChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::update_action_script_btn));
297 for (int i = 0; i < MAX_LUA_ACTION_SCRIPTS; ++i) {
298 std::string const a = string_compose (X_("script-action-%1"), i + 1);
299 Glib::RefPtr<Action> act = ActionManager::get_action(X_("Editor"), a.c_str());
301 action_script_call_btn[i].set_text (string_compose ("%1", i+1));
302 action_script_call_btn[i].set_related_action (act);
303 action_script_call_btn[i].signal_button_press_event().connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::bind_lua_action_script), i), false);
304 if (act->get_sensitive ()) {
305 action_script_call_btn[i].set_visual_state (Gtkmm2ext::VisualState (action_script_call_btn[i].visual_state() & ~Gtkmm2ext::Insensitive));
307 action_script_call_btn[i].set_visual_state (Gtkmm2ext::VisualState (action_script_call_btn[i].visual_state() | Gtkmm2ext::Insensitive));
309 const int row = i % 2;
310 const int col = i / 2;
311 action_script_table.attach (action_script_call_btn[i], col, col + 1, row, row + 1, EXPAND, EXPAND, 1, 0);
312 action_script_call_btn[i].set_no_show_all ();
314 action_script_table.show ();
320 _main_window.signal_delete_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::main_window_delete_event));
322 /* pack the main vpacker into the main window and show everything
325 _main_window.add (main_vpacker);
326 transport_frame.show_all ();
328 const XMLNode* mnode = main_window_settings ();
331 XMLProperty const * prop;
337 if ((prop = mnode->property (X_("x"))) != 0) {
338 x = atoi (prop->value());
341 if ((prop = mnode->property (X_("y"))) != 0) {
342 y = atoi (prop->value());
345 if ((prop = mnode->property (X_("w"))) != 0) {
346 w = atoi (prop->value());
349 if ((prop = mnode->property (X_("h"))) != 0) {
350 h = atoi (prop->value());
353 if (x >= 0 && y >= 0 && w >= 0 && h >= 0) {
354 _main_window.set_position (Gtk::WIN_POS_NONE);
357 if (x >= 0 && y >= 0) {
358 _main_window.move (x, y);
361 if (w > 0 && h > 0) {
362 _main_window.set_default_size (w, h);
365 std::string current_tab;
367 if ((prop = mnode->property (X_("current-tab"))) != 0) {
368 current_tab = prop->value();
370 current_tab = "editor";
372 if (mixer && current_tab == "mixer") {
373 _tabs.set_current_page (_tabs.page_num (mixer->contents()));
374 } else if (rc_option_editor && current_tab == "preferences") {
375 _tabs.set_current_page (_tabs.page_num (rc_option_editor->contents()));
377 _tabs.set_current_page (_tabs.page_num (editor->contents()));
381 setup_toplevel_window (_main_window, "", this);
382 _main_window.show_all ();
384 _tabs.set_show_tabs (false);
386 /* It would be nice if Gtkmm had wrapped this rather than just
387 * deprecating the old set_window_creation_hook() method, but oh well...
389 g_signal_connect (_tabs.gobj(), "create-window", (GCallback) ::tab_window_root_drop, this);
395 ARDOUR_UI::bind_lua_action_script (GdkEventButton*ev, int i)
397 if (ev->button != 3) {
400 LuaInstance *li = LuaInstance::instance();
401 if (Gtkmm2ext::Keyboard::modifier_state_equals (ev->state, Gtkmm2ext::Keyboard::TertiaryModifier)) {
402 li->remove_lua_action (i);
404 li->interactive_add (LuaScriptInfo::EditorAction, i);
410 ARDOUR_UI::update_action_script_btn (int i, const std::string& n)
412 if (LuaInstance::instance()->lua_action_has_icon (i)) {
414 action_script_call_btn[i].set_icon (&LuaInstance::render_action_icon, (void*)ii);
416 action_script_call_btn[i].set_icon (0, 0);
419 std::string const a = string_compose (X_("script-action-%1"), i + 1);
420 Glib::RefPtr<Action> act = ActionManager::get_action(X_("Editor"), a.c_str());
423 act->set_label (string_compose (_("Unset #%1"), i + 1));
424 act->set_tooltip (_("No action bound\nRight-click to assign"));
425 act->set_sensitive (false);
428 act->set_tooltip (string_compose (_("%1\n\nClick to run\nRight-click to re-assign\nShift+right-click to unassign"), n));
429 act->set_sensitive (true);
431 KeyEditor::UpdateBindings ();