initial pass at session-renaming functionality
[ardour.git] / gtk2_ardour / ardour_ui.cc
index 1fa4b21b56e89e4b7ff3885467e1f821928d2375..9e34ac0641e30a9234604225565d1dd7d8a4ce99 100644 (file)
@@ -91,6 +91,7 @@ typedef uint64_t microseconds_t;
 #include "engine_dialog.h"
 #include "gain_meter.h"
 #include "global_port_matrix.h"
+#include "gui_object.h"
 #include "gui_thread.h"
 #include "keyboard.h"
 #include "location_ui.h"
@@ -133,6 +134,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
 
        : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
 
+       , gui_object_state (new GUIObjectState)
        , primary_clock (new AudioClock (X_("primary"), false, X_("TransportClockDisplay"), true, true, false, true))
        , secondary_clock (new AudioClock (X_("secondary"), false, X_("SecondaryClockDisplay"), true, true, false, true))
        , preroll_clock (new AudioClock (X_("preroll"), false, X_("PreRollClock"), true, false, true))
@@ -165,12 +167,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
        , play_selection_button (play_selection_controllable)
        , rec_button (rec_controllable)
 
-       , punch_in_button (_("Punch In"))
-       , punch_out_button (_("Punch Out"))
        , auto_return_button (_("Auto Return"))
        , auto_play_button (_("Auto Play"))
        , auto_input_button (_("Auto Input"))
-       , click_button (_("Click"))
+         // , click_button (_("Click"))
        , time_master_button (_("time\nmaster"))
 
        , auditioning_alert_button (_("AUDITION"))
@@ -295,7 +295,6 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
 
        keyboard = new ArdourKeyboard(*this);
 
-
        XMLNode* node = ARDOUR_UI::instance()->keyboard_settings();
        if (node) {
                keyboard->set_state (*node, Stateful::loading_state_version);
@@ -986,6 +985,57 @@ ARDOUR_UI::update_sample_rate (framecnt_t)
        sample_rate_label.set_text (buf);
 }
 
+void
+ARDOUR_UI::update_format ()
+{
+       if (!_session) {
+               format_label.set_text ("");
+               return;
+       }
+
+       stringstream s;
+
+       switch (_session->config.get_native_file_header_format ()) {
+       case BWF:
+               s << "BWF";
+               break;
+       case WAVE:
+               s << "WAV";
+               break;
+       case WAVE64:
+               s << "WAV64";
+               break;
+       case CAF:
+               s << "CAF";
+               break;
+       case AIFF:
+               s << "AIFF";
+               break;
+       case iXML:
+               s << "iXML";
+               break;
+       case RF64:
+               s << "RF64";
+               break;
+       }
+
+       s << " ";
+       
+       switch (_session->config.get_native_file_data_format ()) {
+       case FormatFloat:
+               s << "32-float";
+               break;
+       case FormatInt24:
+               s << "24-int";
+               break;
+       case FormatInt16:
+               s << "16-int";
+               break;
+       }
+
+       format_label.set_text (s.str ());
+}
+
 void
 ARDOUR_UI::update_cpu_load ()
 {
@@ -998,12 +1048,8 @@ void
 ARDOUR_UI::update_buffer_load ()
 {
        char buf[64];
-       uint32_t c, p;
 
        if (_session) {
-               c = _session->capture_load ();
-               p = _session->playback_load ();
-
                snprintf (buf, sizeof (buf), _("Buffers p:%" PRIu32 "%% c:%" PRIu32 "%%"),
                          _session->playback_load(), _session->capture_load());
                buffer_load_label.set_text (buf);
@@ -2074,7 +2120,6 @@ ARDOUR_UI::snapshot_session (bool switch_to_it)
        prompter.set_name ("Prompter");
        prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
        prompter.set_title (_("Take Snapshot"));
-       prompter.set_title (_("Take Snapshot"));
        prompter.set_prompt (_("Name of new snapshot"));
 
        if (!switch_to_it) {
@@ -2139,6 +2184,73 @@ ARDOUR_UI::snapshot_session (bool switch_to_it)
        }
 }
 
+/** Ask the user for the name of a new shapshot and then take it.
+ */
+
+void
+ARDOUR_UI::rename_session ()
+{
+       if (!_session) {
+               return;
+       }
+
+       ArdourPrompter prompter (true);
+       string name;
+
+       prompter.set_name ("Prompter");
+       prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
+       prompter.set_title (_("Rename Session"));
+       prompter.set_prompt (_("New session name"));
+
+  again:
+       switch (prompter.run()) {
+       case RESPONSE_ACCEPT:
+       {
+               prompter.get_result (name);
+
+               bool do_rename = (name.length() != 0);
+
+               if (do_rename) {
+                       if (name.find ('/') != string::npos) {
+                               MessageDialog msg (_("To ensure compatibility with various systems\n"
+                                                    "session names may not contain a '/' character"));
+                               msg.run ();
+                               goto again;
+                       }
+                       if (name.find ('\\') != string::npos) {
+                               MessageDialog msg (_("To ensure compatibility with various systems\n"
+                                                    "session names may not contain a '\\' character"));
+                               msg.run ();
+                               goto again;
+                       }
+
+                       switch (_session->rename (name)) {
+                       case -1: {
+                               MessageDialog msg (_("That name is already in use by another directory/folder. Please try again."));
+                               msg.set_position (WIN_POS_MOUSE);
+                               msg.run ();
+                               goto again;
+                               break;
+                       }
+                       case 0:
+                               break;
+                       default: {
+                               MessageDialog msg (_("Renaming this session failed.\nThings could be seriously messed up at this point"));
+                               msg.set_position (WIN_POS_MOUSE);
+                               msg.run ();
+                               break;
+                       }
+                       }
+               }
+               
+               break;
+       }
+
+       default:
+               break;
+       }
+}
+
 void
 ARDOUR_UI::save_state (const string & name, bool switch_to_it)
 {
@@ -2150,6 +2262,8 @@ ARDOUR_UI::save_state (const string & name, bool switch_to_it)
                }
        }
 
+       node->add_child_nocopy (gui_object_state->get_state());
+
        _session->add_extra_xml (*node);
 
        save_state_canfail (name, switch_to_it);
@@ -3482,15 +3596,19 @@ ARDOUR_UI::store_clock_modes ()
        XMLNode* node = new XMLNode(X_("ClockModes"));
 
        for (vector<AudioClock*>::iterator x = AudioClock::clocks.begin(); x != AudioClock::clocks.end(); ++x) {
-               node->add_property ((*x)->name().c_str(), enum_2_string ((*x)->mode()));
+               XMLNode* child = new XMLNode (X_("Clock"));
+               
+               child->add_property (X_("name"), (*x)->name());
+               child->add_property (X_("mode"), enum_2_string ((*x)->mode()));
+               child->add_property (X_("on"), ((*x)->off() ? X_("no") : X_("yes")));
+
+               node->add_child_nocopy (*child);
        }
 
        _session->add_extra_xml (*node);
        _session->set_dirty ();
 }
 
-
-
 ARDOUR_UI::TransportControllable::TransportControllable (std::string name, ARDOUR_UI& u, ToggleType tp)
        : Controllable (name), ui (u), type(tp)
 {