compiles and runs, but crashes ... duh
[ardour.git] / gtk2_ardour / ardour_ui.cc
index b3c6f59da25530ea20695871aded54de13e6a8b3..cb41fc652e90b95670b4eba0e8c97d1744766185 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <iostream>
 
-#include <gtkmm.h>
 #include <pbd/error.h>
 #include <pbd/compose.h>
 #include <pbd/basename.h>
@@ -57,6 +56,7 @@
 #include <ardour/port.h>
 #include <ardour/audio_track.h>
 
+#include "actions.h"
 #include "ardour_ui.h"
 #include "ardour_message.h"
 #include "public_editor.h"
@@ -80,7 +80,6 @@ using namespace Gtk;
 using namespace sigc;
 
 ARDOUR_UI *ARDOUR_UI::theArdourUI = 0;
-SoundFileSelector* ARDOUR_UI::sfdb_window = 0;
 
 sigc::signal<void,bool> ARDOUR_UI::Blink;
 sigc::signal<void>      ARDOUR_UI::RapidScreenUpdate;
@@ -783,7 +782,7 @@ vector<string> channel_combo_strings;
 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], string rcfile)
 
        : Gtkmm2ext::UI ("ardour", argcp, argvp, rcfile),
-
+         
          primary_clock (X_("TransportClockDisplay"), true, false, true),
          secondary_clock (X_("SecondaryClockDisplay"), true, false, true),
          preroll_clock (X_("PreRollClock"), true, true),
@@ -833,6 +832,11 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], string rcfile)
                theArdourUI = this;
        }
 
+       ActionManager::init ();
+       
+       m_new_session_dialog = 0;
+       m_new_session_dialog_ref = NewSessionDialogFactory::create();
+       m_new_session_dialog_ref->get_widget_derived (NewSessionDialogFactory::top_level_widget_name(), m_new_session_dialog);
        editor = 0;
        mixer = 0;
        session = 0;
@@ -846,8 +850,6 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], string rcfile)
        meter_bridge = 0;
        option_editor = 0;
        location_ui = 0;
-       sfdb_window = 0;
-       new_session_window = 0;
        open_session_selector = 0;
        have_configure_timeout = false;
        have_disk_overrun_displayed = false;
@@ -855,11 +857,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], string rcfile)
        _will_create_new_session_automatically = false;
        session_loaded = false;
 
+
        last_configure_time.tv_sec = 0;
        last_configure_time.tv_usec = 0;
 
-       ui_manager = UIManager::create ();
-
        shuttle_grabbed = false;
        shuttle_fract = 0.0;
 
@@ -873,10 +874,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], string rcfile)
        shuttle_actions->add (Action::create (X_("SetShuttleActionSprung"), _("Sprung")), bind (mem_fun(*this, &ARDOUR_UI::set_shuttle_behaviour), Sprung));
        shuttle_actions->add (Action::create (X_("SetShuttleActionWheel"), _("Wheel")), bind (mem_fun(*this, &ARDOUR_UI::set_shuttle_behaviour), Wheel));
        
-       ui_manager->insert_action_group (shuttle_actions);
+       ActionManager::add_action_group (shuttle_actions);
 
-       shuttle_style_menu = dynamic_cast<Menu*> (ui_manager->get_widget ("ShuttleStylePopup"));
-       shuttle_unit_menu = dynamic_cast<Menu*> (ui_manager->get_widget ("ShuttleUnitPopup"));
+       shuttle_style_menu = dynamic_cast<Menu*> (ActionManager::get_widget ("ShuttleStylePopup"));
+       shuttle_unit_menu = dynamic_cast<Menu*> (ActionManager::get_widget ("ShuttleUnitPopup"));
        
        gettimeofday (&last_peak_grab, 0);
        gettimeofday (&last_shuttle_request, 0);
@@ -900,7 +901,7 @@ ARDOUR_UI::cannot_record_no_input (DiskStream* ds)
 {
        ENSURE_GUI_THREAD (bind (mem_fun(*this, &ARDOUR_UI::cannot_record_no_input), ds));
        
-       string msg = PBD::compose (_("\
+       string msg = string_compose (_("\
 You cannot record-enable\n\
 track %1\n\
 because it has no input connections.\n\
@@ -933,7 +934,8 @@ ARDOUR_UI::set_engine (AudioEngine& e)
        }
 
        if (GTK_ARDOUR::show_key_actions) {
-               KeyboardTarget::show_all_actions ();
+               // GTK2FIX
+               // show_all_actions ();
                exit (0);
        }
 
@@ -1104,17 +1106,17 @@ ARDOUR_UI::ask_about_saving_session (string what)
 
        string msg;
 
-       msg = PBD::compose(_("Save and %1"), what);
+       msg = string_compose(_("Save and %1"), what);
        
        Gtk::Button save_button (msg);
        save_button.set_name ("EditorGTKButton");
 
-       msg = PBD::compose(_("Just %1"), what);
+       msg = string_compose(_("Just %1"), what);
 
        Gtk::Button nosave_button (msg);
        nosave_button.set_name ("EditorGTKButton");
 
-       msg = PBD::compose(_("Don't %1"), what);
+       msg = string_compose(_("Don't %1"), what);
 
        Gtk::Button noquit_button (msg);
        noquit_button.set_name ("EditorGTKButton");
@@ -1127,7 +1129,7 @@ ARDOUR_UI::ask_about_saving_session (string what)
        } else {
                type = _("snapshot");
        }
-       prompt = PBD::compose(_("The %1\n\"%2\"\nhas not been saved.\n\nAny changes made this time\nwill be lost unless you save it.\n\nWhat do you want to do?"), 
+       prompt = string_compose(_("The %1\n\"%2\"\nhas not been saved.\n\nAny changes made this time\nwill be lost unless you save it.\n\nWhat do you want to do?"), 
                         type, session->snap_name());
        
        prompt_label.set_text (prompt);
@@ -1781,21 +1783,6 @@ ARDOUR_UI::open_recent_session ()
 
 }
 
-void
-ARDOUR_UI::fs_cancel_clicked (Gtk::FileSelection* fs)
-{
-       fs->hide_all();
-       fs->get_selection_entry()->set_text("");
-       allow_focus (false);
-}
-
-gint 
-ARDOUR_UI::fs_delete_event (GdkEventAny* ev, Gtk::FileSelection* fs)
-{
-       fs_cancel_clicked (fs);
-       return 1;
-}
-
 bool
 ARDOUR_UI::filter_ardour_session_dirs (const FileFilter::Info& info) 
 {
@@ -2564,14 +2551,6 @@ ARDOUR_UI::restore_state (string name)
        }
 }
 
-void
-ARDOUR_UI::allow_focus (bool yn)
-{
-       if (keyboard) {
-               keyboard->allow_focus (yn);
-       }
-}
-
 void
 ARDOUR_UI::primary_clock_value_changed ()
 {
@@ -2646,20 +2625,6 @@ ARDOUR_UI::transport_rec_enable_blink (bool onoff)
        }
 }
 
-gint
-ARDOUR_UI::generic_focus_in_event (GdkEventFocus *ev)
-{
-       ARDOUR_UI::instance()->allow_focus (true);
-       return FALSE;
-}
-
-gint
-ARDOUR_UI::generic_focus_out_event (GdkEventFocus *ev)
-{
-       ARDOUR_UI::instance()->allow_focus (false);
-       return FALSE;
-}
-
 gint
 ARDOUR_UI::hide_and_quit (GdkEventAny *ev, ArdourDialog *window)
 {
@@ -2700,87 +2665,81 @@ ARDOUR_UI::save_template ()
 }
 
 void
-ARDOUR_UI::new_session (bool startup, string predetermined_path)
+ARDOUR_UI::new_session (bool startup, std::string predetermined_path)
 {
-       if (new_session_window == 0){
-               new_session_window = new NewSessionDialog (*engine, startup, predetermined_path);
-               editor->ensure_float (*new_session_window);
-       }
+       m_new_session_dialog->show_all();
+       m_new_session_dialog->set_transient_for(*editor);
+       m_new_session_dialog->set_name(predetermined_path);
 
-       new_session_window->run ();
+       int response = Gtk::RESPONSE_CANCEL;
 
-#if 0
-       // GTK2FIX
+       do {
+               response = m_new_session_dialog->run ();
        
-       /* write favorites either way */
-       Session::FavoriteDirs favs;
-       new_session_window->file_selector.get_favorites (favs);
-       Session::write_favorite_dirs (favs);
-
-       if (new_session_window->run_status()) {
-               return;
-       }
-#endif
-
-       string session_path = new_session_window->file_selector.get_filename ();
-       string session_name = PBD::basename (session_path);
-
-       // Check that it doesn't already exist.
-       access(session_path.c_str(), R_OK); 
-       if (errno != ENOENT){
-               error << PBD::compose(_("Session %1 already exists at %2"), session_name, session_path) << endmsg;
-               return;
-       }
+               if(response == Gtk::RESPONSE_OK) {
 
-       _session_is_new = true;
-
-       if (session_path[session_path.length()-1] != '/') {
-
-               string template_name = new_session_window->get_template_name ();
-
-               if (template_name.length()) {
-
-                       load_session (session_path, session_name, &template_name);
-
-               } else {
-
-                       uint32_t cchns;
-                       uint32_t mchns;
-                       Session::AutoConnectOption iconnect;
-                       Session::AutoConnectOption oconnect;
-
-                       if (new_session_window->use_control_button.get_active()) {
-                               cchns = (uint32_t) channel_combo_get_channel_count (new_session_window->control_out_channel_combo);
-                       } else {
-                               cchns = 0;
-                       }
-                       if (new_session_window->use_master_button.get_active()) {
-                               mchns = (uint32_t) channel_combo_get_channel_count (new_session_window->master_out_channel_combo);
-                       } else {
-                               mchns = 0;
-                       }
-
-                       if (new_session_window->connect_to_physical_inputs_button.get_active()) {
-                               iconnect = Session::AutoConnectPhysical;
-                       } else {
-                               iconnect = Session::AutoConnectOption (0);
-                       }
-
-                       if (new_session_window->connect_to_master_button.get_active ()) {
-                               oconnect = Session::AutoConnectMaster;
-                       } else if (new_session_window->connect_to_physical_outputs_button.get_active ()) {
-                               oconnect = Session::AutoConnectPhysical;
+                       _session_is_new = true;
+                       
+                       std::string session_name = m_new_session_dialog->session_name();
+                       std::string session_path = m_new_session_dialog->session_folder();
+                       std::string template_name = m_new_session_dialog->session_template_name();
+                       
+                       if (m_new_session_dialog->use_session_template()) {
+                               
+                               load_session (session_path, session_name, &template_name);
+                               
                        } else {
-                               oconnect = Session::AutoConnectOption (0);
-                       } 
-
-                       uint32_t nphysin = (uint32_t) new_session_window->in_count_adjustment.get_value();
-                       uint32_t nphysout = (uint32_t) new_session_window->out_count_adjustment.get_value();
-
-                       build_session (session_path, session_name, cchns, mchns, iconnect, oconnect, nphysin, nphysout, 
-                                      engine->frame_rate() * 60 * 5);
+                               
+                               uint32_t cchns;
+                               uint32_t mchns;
+                               Session::AutoConnectOption iconnect;
+                               Session::AutoConnectOption oconnect;
+                               
+                               if (m_new_session_dialog->create_control_track()) {
+                                       cchns = (uint32_t) m_new_session_dialog->control_channel_count();
+                               } else {
+                                       cchns = 0;
+                               }
+                               
+                               if (m_new_session_dialog->create_master_track()) {
+                                       mchns = (uint32_t) m_new_session_dialog->master_channel_count();
+                               } else {
+                                       mchns = 0;
+                               }
+                               
+                               if (m_new_session_dialog->connect_inputs()) {
+                                       iconnect = Session::AutoConnectPhysical;
+                               } else {
+                                       iconnect = Session::AutoConnectOption (0);
+                               }
+                               
+                               /// @todo some minor tweaks.
+
+                               if (m_new_session_dialog->connect_outs_to_master()) {
+                                       oconnect = Session::AutoConnectMaster;
+                               } else if (m_new_session_dialog->connect_outs_to_physical()) {
+                                       oconnect = Session::AutoConnectPhysical;
+                               } else {
+                                       oconnect = Session::AutoConnectOption (0);
+                               } 
+                               
+                               uint32_t nphysin = (uint32_t) m_new_session_dialog->input_limit_count();
+                               uint32_t nphysout = (uint32_t) m_new_session_dialog->output_limit_count();
+                               
+                               build_session (session_path,
+                                              session_name,
+                                              cchns,
+                                              mchns,
+                                              iconnect,
+                                              oconnect,
+                                              nphysin,
+                                              nphysout, 
+                                              engine->frame_rate() * 60 * 5);
+                       }               
                }
-       }
+
+       } while(response == Gtk::RESPONSE_HELP);
+       m_new_session_dialog->hide_all();
 }
 
 int
@@ -2812,7 +2771,7 @@ This prevents the session from being loaded."));
 
        catch (...) {
 
-               error << PBD::compose(_("Session \"%1 (snapshot %2)\" did not load successfully"), path, snap_name) << endmsg;
+               error << string_compose(_("Session \"%1 (snapshot %2)\" did not load successfully"), path, snap_name) << endmsg;
                return -1;
        }
 
@@ -2865,7 +2824,7 @@ ARDOUR_UI::build_session (string path, string snap_name,
 
        catch (...) {
 
-               error << PBD::compose(_("Session \"%1 (snapshot %2)\" did not load successfully"), path, snap_name) << endmsg;
+               error << string_compose(_("Session \"%1 (snapshot %2)\" did not load successfully"), path, snap_name) << endmsg;
                return -1;
        }
 
@@ -2878,12 +2837,6 @@ ARDOUR_UI::build_session (string path, string snap_name,
        return 0;
 }
 
-void
-ARDOUR_UI::hide_dialog (ArdourDialog *dialog)
-{
-       dialog->hide_all();
-}
-
 void
 ARDOUR_UI::show ()
 {
@@ -2966,15 +2919,15 @@ require some unused files to continue to exist."));
 
        if (rep.space < 1048576.0f) {
                if (removed > 1) {
-                       txt.set_text (PBD::compose (msg, removed, _("files"), (float) rep.space / 1024.0f, "kilo"));
+                       txt.set_text (string_compose (msg, removed, _("files"), (float) rep.space / 1024.0f, "kilo"));
                } else {
-                       txt.set_text (PBD::compose (msg, removed, _("file"), (float) rep.space / 1024.0f, "kilo"));
+                       txt.set_text (string_compose (msg, removed, _("file"), (float) rep.space / 1024.0f, "kilo"));
                }
        } else {
                if (removed > 1) {
-                       txt.set_text (PBD::compose (msg, removed, _("files"), (float) rep.space / 1048576.0f, "mega"));
+                       txt.set_text (string_compose (msg, removed, _("files"), (float) rep.space / 1048576.0f, "mega"));
                } else {
-                       txt.set_text (PBD::compose (msg, removed, _("file"), (float) rep.space / 1048576.0f, "mega"));
+                       txt.set_text (string_compose (msg, removed, _("file"), (float) rep.space / 1048576.0f, "mega"));
                }
        }