Tempo ramps - possible fix for loading bjbjb's session, remove insane level 3 map...
[ardour.git] / gtk2_ardour / ardour_ui.cc
index c368572e9c6fc25849b5ef278f5a83abaf7cfd4f..31450f2b23684944a1ee4fa1914ea8939d229f4b 100644 (file)
@@ -226,14 +226,19 @@ libxml_structured_error_func (void* /* parsing_context*/,
 
        replace_all (msg, "\n", "");
 
-       if (err->file && err->line) {
-               error << X_("XML error: ") << msg << " in " << err->file << " at line " << err->line;
+       if (!msg.empty()) {
+               if (err->file && err->line) {
+                       error << X_("XML error: ") << msg << " in " << err->file << " at line " << err->line;
 
-               if (err->int2) {
-                       error << ':' << err->int2;
+                       if (err->int2) {
+                               error << ':' << err->int2;
+                       }
+
+                       error << endmsg;
+               } else {
+                       error << X_("XML error: ") << msg << endmsg;
                }
        }
-       error << endmsg;
 }
 
 
@@ -247,6 +252,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        , video_timeline(0)
        , global_actions (X_("global"))
        , ignore_dual_punch (false)
+       , main_window_visibility (0)
        , editor (0)
        , mixer (0)
        , nsm (0)
@@ -321,6 +327,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
                theArdourUI = this;
        }
 
+       /* track main window visibility */
+
+       main_window_visibility = new VisibilityTracker (_main_window);
+
        /* stop libxml from spewing to stdout/stderr */
 
        xmlSetGenericErrorFunc (this, libxml_generic_error_func);
@@ -368,6 +378,9 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
 
        ARDOUR::Session::AskAboutSampleRateMismatch.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::sr_mismatch_dialog, this, _1, _2));
 
+       /* handle sr mismatch with a dialog - cross-thread from engine */
+       ARDOUR::Session::NotifyAboutSampleRateMismatch.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::sr_mismatch_message, this, _1, _2), gui_context ());
+
        /* handle requests to quit (coming from JACK session) */
 
        ARDOUR::Session::Quit.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::finish, this), gui_context ());
@@ -675,6 +688,7 @@ ARDOUR_UI::~ARDOUR_UI ()
                delete mixer; mixer = 0;
                delete nsm; nsm = 0;
                delete gui_object_state; gui_object_state = 0;
+               delete main_window_visibility;
                FastMeter::flush_pattern_cache ();
                PixFader::flush_pattern_cache ();
        }
@@ -733,7 +747,7 @@ ARDOUR_UI::configure_handler (GdkEventConfigure* /*conf*/)
 void
 ARDOUR_UI::set_transport_controllable_state (const XMLNode& node)
 {
-       const XMLProperty* prop;
+       XMLProperty const * prop;
 
        if ((prop = node.property ("roll")) != 0) {
                roll_controllable->set_id (prop->value());
@@ -1706,6 +1720,10 @@ ARDOUR_UI::open_recent_session ()
 
                can_return = false;
        }
+       if (splash && splash->is_visible()) {
+               // in 1 second, hide the splash screen
+               Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (_hide_splash), this), 1000);
+       }
 }
 
 bool
@@ -1786,7 +1804,8 @@ ARDOUR_UI::session_add_mixed_track (
                uint32_t how_many,
                const string& name_template,
                bool strict_io,
-               PluginInfoPtr instrument)
+               PluginInfoPtr instrument,
+               Plugin::PresetRecord* pset)
 {
        list<boost::shared_ptr<MidiTrack> > tracks;
 
@@ -1796,7 +1815,7 @@ ARDOUR_UI::session_add_mixed_track (
        }
 
        try {
-               tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template);
+               tracks = _session->new_midi_track (input, output, instrument, ARDOUR::Normal, route_group, how_many, name_template, pset);
 
                if (tracks.size() != how_many) {
                        error << string_compose(P_("could not create %1 new mixed track", "could not create %1 new mixed tracks", how_many), how_many) << endmsg;
@@ -1821,7 +1840,8 @@ ARDOUR_UI::session_add_midi_bus (
                uint32_t how_many,
                const string& name_template,
                bool strict_io,
-               PluginInfoPtr instrument)
+               PluginInfoPtr instrument,
+               Plugin::PresetRecord* pset)
 {
        RouteList routes;
 
@@ -1831,7 +1851,7 @@ ARDOUR_UI::session_add_midi_bus (
        }
 
        try {
-               routes = _session->new_midi_route (route_group, how_many, name_template, instrument);
+               routes = _session->new_midi_route (route_group, how_many, name_template, instrument, pset);
                if (routes.size() != how_many) {
                        error << string_compose(P_("could not create %1 new Midi Bus", "could not create %1 new Midi Busses", how_many), how_many) << endmsg;
                }
@@ -1856,15 +1876,16 @@ ARDOUR_UI::session_add_midi_route (
                uint32_t how_many,
                const string& name_template,
                bool strict_io,
-               PluginInfoPtr instrument)
+               PluginInfoPtr instrument,
+               Plugin::PresetRecord* pset)
 {
        ChanCount one_midi_channel;
        one_midi_channel.set (DataType::MIDI, 1);
 
        if (disk) {
-               session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, strict_io, instrument);
+               session_add_mixed_track (one_midi_channel, one_midi_channel, route_group, how_many, name_template, strict_io, instrument, pset);
        } else {
-               session_add_midi_bus (route_group, how_many, name_template, strict_io, instrument);
+               session_add_midi_bus (route_group, how_many, name_template, strict_io, instrument, pset);
        }
 }
 
@@ -2626,7 +2647,7 @@ ARDOUR_UI::snapshot_session (bool switch_to_it)
        prompter.set_name ("Prompter");
        prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
        if (switch_to_it) {
-               prompter.set_title (_("Save as..."));
+               prompter.set_title (_("Snapshot and switch"));
                prompter.set_prompt (_("New session name"));
        } else {
                prompter.set_title (_("Take Snapshot"));
@@ -3264,6 +3285,10 @@ ARDOUR_UI::close_session()
        if (get_session_parameters (true, false)) {
                exit (1);
        }
+       if (splash && splash->is_visible()) {
+               // in 1 second, hide the splash screen
+               Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (_hide_splash), this), 1000);
+       }
 }
 
 /** @param snap_name Snapshot name (without .ardour suffix).
@@ -3934,7 +3959,7 @@ ARDOUR_UI::start_duplicate_routes ()
 }
 
 void
-ARDOUR_UI::add_route (Gtk::Window* /* ignored */)
+ARDOUR_UI::add_route ()
 {
        int count;
 
@@ -4001,13 +4026,13 @@ ARDOUR_UI::add_route (Gtk::Window* /* ignored */)
                session_add_midi_track (route_group, count, name_template, strict_io, instrument);
                break;
        case AddRouteDialog::MixedTrack:
-               session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, strict_io, instrument);
+               session_add_mixed_track (input_chan, output_chan, route_group, count, name_template, strict_io, instrument, 0);
                break;
        case AddRouteDialog::AudioBus:
                session_add_audio_bus (input_chan.n_audio(), output_chan.n_audio(), route_group, count, name_template, strict_io);
                break;
        case AddRouteDialog::MidiBus:
-               session_add_midi_bus (route_group, count, name_template, strict_io, instrument);
+               session_add_midi_bus (route_group, count, name_template, strict_io, instrument, 0);
                break;
        }
 }
@@ -4808,6 +4833,21 @@ audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual
         return 1;
 }
 
+void
+ARDOUR_UI::sr_mismatch_message (framecnt_t desired, framecnt_t actual)
+{
+       MessageDialog msg (string_compose (_("\
+This session was created with a sample rate of %1 Hz, but\n\
+%2 is currently running at %3 Hz.\n\
+Audio will be recorded and played at the wrong sample rate.\n\
+Re-Configure the Audio Engine in\n\
+Menu > Window > Audio/Midi Setup"),
+                               desired, PROGRAM_NAME, actual),
+                       true,
+                       Gtk::MESSAGE_WARNING);
+       msg.run ();
+}
+
 void
 ARDOUR_UI::use_config ()
 {
@@ -5122,11 +5162,7 @@ ARDOUR_UI::do_audio_midi_setup (uint32_t desired_sample_rate)
        audio_midi_setup->set_desired_sample_rate (desired_sample_rate);
        audio_midi_setup->set_position (WIN_POS_CENTER);
 
-       // TODO make this a preference.
-       // (engine state is parsed by the GUI, but currently saved
-       // in preferences: ARDOUR::Config->extra_xml
-       // soooo where should this option go?)
-       if (getenv("TRY_AUTOSTART_ENGINE")) {
+       if (Config->get_try_autostart_engine () || getenv ("TRY_AUTOSTART_ENGINE")) {
                audio_midi_setup->try_autostart ();
                if (ARDOUR::AudioEngine::instance()->running()) {
                        return 0;
@@ -5273,16 +5309,16 @@ ARDOUR_UI::setup_toplevel_window (Gtk::Window& window, const string& name, void*
 
        if (window_icons.empty()) {
                Glib::RefPtr<Gdk::Pixbuf> icon;
-               if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
+               if ((icon = ::get_icon (PROGRAM_NAME "-icon_16px")) != 0) {
                        window_icons.push_back (icon);
                }
-               if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
+               if ((icon = ::get_icon (PROGRAM_NAME "-icon_22px")) != 0) {
                        window_icons.push_back (icon);
                }
-               if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
+               if ((icon = ::get_icon (PROGRAM_NAME "-icon_32px")) != 0) {
                        window_icons.push_back (icon);
                }
-               if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
+               if ((icon = ::get_icon (PROGRAM_NAME "-icon_48px")) != 0) {
                        window_icons.push_back (icon);
                }
        }
@@ -5366,7 +5402,7 @@ ARDOUR_UI::key_event_handler (GdkEventKey* ev, Gtk::Window* event_window)
 static Gtkmm2ext::Bindings*
 get_bindings_from_widget_heirarchy (GtkWidget* w)
 {
-       void* p;
+       void* p = NULL;
 
        while (w) {
                if ((p = g_object_get_data (G_OBJECT(w), "ardour-bindings")) != 0) {