~ubuntu-branches/ubuntu/lucid/ardour/lucid-proposed

« back to all changes in this revision

Viewing changes to gtk2_ardour/ardour_ui.cc

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-02-07 20:51:55 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080207205155-xzi5lq5s2o1okvx8
Tags: 1:2.3.1-1
* New upstream release
* debian/control:
   - build-depend on libfftw3-dev (Closes: #463803)
   - added Homepage, Vcs-Svn, Vcs-Browser
* debian/patches
   - dropped 50-soundtouch.patch (fixed upstream)
   - updated 80_ardourino.patch
   - dropped unused patches from source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
#include "add_route_dialog.h"
76
76
#include "new_session_dialog.h"
77
77
#include "about.h"
 
78
#include "splash.h"
78
79
#include "utils.h"
79
80
#include "gui_thread.h"
80
81
#include "theme_manager.h"
166
167
        }
167
168
        
168
169
        about = 0;
 
170
        splash = 0;
 
171
 
 
172
        if (ARDOUR_COMMAND_LINE::session_name.length()) {       
 
173
                /* only show this if we're not going to post the new session dialog */
 
174
                show_splash ();
 
175
        }
169
176
 
170
177
        if (theArdourUI == 0) {
171
178
                theArdourUI = this;
194
201
        have_disk_speed_dialog_displayed = false;
195
202
        _will_create_new_session_automatically = false;
196
203
        session_loaded = false;
197
 
        loading_dialog = 0;
198
204
        last_speed_displayed = -1.0f;
199
205
 
200
206
        keybindings_path = ARDOUR::find_config_file ("ardour.bindings");
225
231
 
226
232
        ARDOUR::Session::AskAboutPendingState.connect (mem_fun(*this, &ARDOUR_UI::pending_state_dialog));
227
233
 
 
234
        /* handle sr mismatch with a dialog */
 
235
 
 
236
        ARDOUR::Session::AskAboutSampleRateMismatch.connect (mem_fun(*this, &ARDOUR_UI::sr_mismatch_dialog));
 
237
 
228
238
        /* lets get this party started */
229
239
 
230
240
        try {
261
271
                return 0;
262
272
        }
263
273
 
 
274
        loading_message (_("Starting audio engine"));
 
275
 
264
276
        try { 
265
277
                engine = new ARDOUR::AudioEngine (ARDOUR_COMMAND_LINE::jack_client_name);
266
278
 
380
392
        }
381
393
}
382
394
 
 
395
void
 
396
ARDOUR_UI::pop_back_splash ()
 
397
{
 
398
        if (Splash::instance()) {
 
399
                // Splash::instance()->pop_back();
 
400
                Splash::instance()->hide ();
 
401
        }
 
402
}
 
403
 
383
404
gint
384
405
ARDOUR_UI::configure_timeout ()
385
406
{
591
612
        
592
613
        win.show_all ();
593
614
        win.set_position (Gtk::WIN_POS_CENTER);
594
 
 
595
 
        if (!ARDOUR_COMMAND_LINE::no_splash) {
596
 
                hide_splash ();
597
 
        }
 
615
        pop_back_splash ();
598
616
 
599
617
        /* we just don't care about the result, but we want to block */
600
618
 
605
623
ARDOUR_UI::startup ()
606
624
{
607
625
        string name, path;
608
 
        bool isnew;
609
626
 
610
627
        new_session_dialog = new NewSessionDialog();
611
 
        
612
 
        /* If no session name is given: we're not loading a session yet, nor creating a new one */
613
 
        
614
 
        if (ARDOUR_COMMAND_LINE::session_name.length()) {
615
 
        
616
 
                /* Load session or start the new session dialog */
617
 
                
618
 
                if (Session::find_session (ARDOUR_COMMAND_LINE::session_name, path, name, isnew)) {
619
 
                        
620
 
                        MessageDialog msg (string_compose(_("Could not find command line session \"%1\""), 
621
 
                                                          ARDOUR_COMMAND_LINE::session_name),
622
 
                                           true,
623
 
                                           Gtk::MESSAGE_ERROR,
624
 
                                           Gtk::BUTTONS_OK);
625
 
                        
626
 
                        msg.set_position (Gtk::WIN_POS_MOUSE);
627
 
                        msg.present ();
628
 
                        msg.run ();
629
 
                        
630
 
                        exit (1);
631
 
                }
632
 
 
633
 
                if (!ARDOUR_COMMAND_LINE::new_session) {
634
 
                        
635
 
                        /* Supposed to be loading an existing session, but the session doesn't exist */
636
 
                        
637
 
                        if (isnew) {
638
 
                                MessageDialog msg (string_compose (_("\n\nNo session named \"%1\" exists.\n"
639
 
                                                                     "To create it from the command line, start ardour as:\n   ardour --new %1"), path),
640
 
                                                   true,
641
 
                                                   Gtk::MESSAGE_ERROR,
642
 
                                                   Gtk::BUTTONS_OK);
643
 
 
644
 
                                msg.set_position (Gtk::WIN_POS_MOUSE);
645
 
                                msg.present ();
646
 
                                msg.run ();
647
 
 
648
 
                                exit (1);
649
 
                        }
650
 
                }
651
 
        }
652
 
 
653
 
        hide_splash ();
654
 
 
655
 
        bool have_backend = EngineControl::engine_running();
 
628
 
 
629
        bool backend_audio_is_running = EngineControl::engine_running();
656
630
        XMLNode* audio_setup = Config->extra_xml ("AudioSetup");
657
631
        
658
632
        if (audio_setup) {
659
633
                new_session_dialog->engine_control.set_state (*audio_setup);
660
634
        }
661
635
        
662
 
        if (!get_session_parameters (ARDOUR_COMMAND_LINE::session_name, have_backend, ARDOUR_COMMAND_LINE::new_session)) {
 
636
        if (!get_session_parameters (backend_audio_is_running, ARDOUR_COMMAND_LINE::new_session)) {
663
637
                return;
664
638
        }
665
639
        
719
693
                                hbox.pack_start (cb, true, false);
720
694
                                vbox->pack_start (hbox);
721
695
                                hbox.show_all ();
 
696
 
 
697
                                pop_back_splash ();
722
698
                                
723
699
                                msg.run ();
724
700
                        }
752
728
Ardour was unable to save your session.\n\n\
753
729
If you still wish to quit, please use the\n\n\
754
730
\"Just quit\" option."));
 
731
                                        pop_back_splash();
755
732
                                        msg.run ();
756
733
                                        return;
757
734
                                }
1024
1001
                        fullpath = fullpath.substr (0, fullpath.length()-1);
1025
1002
                }
1026
1003
 
 
1004
                /* check whether session still exists */
 
1005
                if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
 
1006
                        /* session doesn't exist */
 
1007
                        cerr << "skipping non-existent session " << fullpath << endl;
 
1008
                        continue;
 
1009
                }               
 
1010
                
1027
1011
                /* now get available states for this session */
1028
1012
 
1029
1013
                if ((states = Session::possible_states (fullpath)) == 0) {
1178
1162
                if (!engine->connected()) {
1179
1163
                        MessageDialog msg (_("Ardour is not connected to JACK\n"
1180
1164
                                             "You cannot open or close sessions in this condition"));
 
1165
                        pop_back_splash ();
1181
1166
                        msg.run ();
1182
1167
                        return false;
1183
1168
                }
1299
1284
to create a new track or bus.\n\
1300
1285
You should save Ardour, exit and\n\
1301
1286
restart JACK with more ports."));
 
1287
                pop_back_splash ();
1302
1288
                msg.run ();
1303
1289
        }
1304
1290
}
1675
1661
disconnected Ardour because Ardour\n\
1676
1662
was not fast enough. You can save the\n\
1677
1663
session and/or try to reconnect to JACK ."));
 
1664
        pop_back_splash ();
1678
1665
        msg.run ();
1679
1666
}
1680
1667
 
2022
2009
                                   true,
2023
2010
                                   Gtk::MESSAGE_INFO,
2024
2011
                                   Gtk::BUTTONS_OK);
 
2012
                pop_back_splash ();
2025
2013
                msg.show_all ();
2026
2014
                msg.present ();
2027
2015
                msg.run ();
2029
2017
#endif
2030
2018
}
2031
2019
 
2032
 
bool
2033
 
ARDOUR_UI::get_session_parameters (Glib::ustring predetermined_path, bool have_engine, bool should_be_new)
 
2020
void
 
2021
ARDOUR_UI::parse_cmdline_path (const Glib::ustring& cmdline_path, Glib::ustring& session_name, Glib::ustring& session_path, bool& existing_session)
 
2022
{
 
2023
        existing_session = false;
 
2024
 
 
2025
        if (Glib::file_test (cmdline_path, Glib::FILE_TEST_IS_DIR)) {
 
2026
                session_path = cmdline_path;
 
2027
                existing_session = true;
 
2028
        } else if (Glib::file_test (cmdline_path, Glib::FILE_TEST_IS_REGULAR)) {
 
2029
                session_path = Glib::path_get_dirname (string (cmdline_path));
 
2030
                existing_session = true;
 
2031
        } else {
 
2032
                /* it doesn't exist, assume the best */
 
2033
                session_path = Glib::path_get_dirname (string (cmdline_path));
 
2034
        }
 
2035
        
 
2036
        session_name = basename_nosuffix (string (cmdline_path));
 
2037
}
 
2038
 
 
2039
int
 
2040
ARDOUR_UI::load_cmdline_session (const Glib::ustring& session_name, const Glib::ustring& session_path, bool& existing_session)
 
2041
{
 
2042
        /* when this is called, the backend audio system must be running */
 
2043
 
 
2044
        /* the main idea here is to deal with the fact that a cmdline argument for the session
 
2045
           can be interpreted in different ways - it could be a directory or a file, and before
 
2046
           we load, we need to know both the session directory and the snapshot (statefile) within it
 
2047
           that we are supposed to use.
 
2048
        */
 
2049
 
 
2050
        if (session_name.length() == 0 || session_path.length() == 0) {
 
2051
                return false;
 
2052
        }
 
2053
        
 
2054
        if (Glib::file_test (session_path, Glib::FILE_TEST_IS_DIR)) {
 
2055
 
 
2056
                Glib::ustring predicted_session_file;
 
2057
                
 
2058
                predicted_session_file = session_path;
 
2059
                predicted_session_file += '/';
 
2060
                predicted_session_file += session_name;
 
2061
                predicted_session_file += Session::statefile_suffix();
 
2062
                
 
2063
                if (Glib::file_test (predicted_session_file, Glib::FILE_TEST_EXISTS)) {
 
2064
                        existing_session = true;
 
2065
                }
 
2066
                
 
2067
        } else if (Glib::file_test (session_path, Glib::FILE_TEST_EXISTS)) {
 
2068
                
 
2069
                if (session_path.find (Session::statefile_suffix()) == session_path.length() - 7) {
 
2070
                        /* existing .ardour file */
 
2071
                        existing_session = true;
 
2072
                }
 
2073
 
 
2074
        } else {
 
2075
                existing_session = false;
 
2076
        }
 
2077
        
 
2078
        /* lets just try to load it */
 
2079
        
 
2080
        if (create_engine ()) {
 
2081
                backend_audio_error (false, new_session_dialog);
 
2082
                return -1;
 
2083
        }
 
2084
        
 
2085
        return load_session (session_path, session_name);
 
2086
}
 
2087
 
 
2088
bool
 
2089
ARDOUR_UI::ask_about_loading_existing_session (const Glib::ustring& session_path)
 
2090
{
 
2091
        Glib::ustring str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
 
2092
        
 
2093
        MessageDialog msg (str,
 
2094
                           false,
 
2095
                           Gtk::MESSAGE_WARNING,
 
2096
                           Gtk::BUTTONS_YES_NO,
 
2097
                           true);
 
2098
        
 
2099
        
 
2100
        msg.set_name (X_("CleanupDialog"));
 
2101
        msg.set_wmclass (X_("existing_session"), "Ardour");
 
2102
        msg.set_position (Gtk::WIN_POS_MOUSE);
 
2103
        pop_back_splash ();
 
2104
 
 
2105
        switch (msg.run()) {
 
2106
        case RESPONSE_YES:
 
2107
                return true;
 
2108
                break;
 
2109
        }
 
2110
        return false;
 
2111
}
 
2112
 
 
2113
int
 
2114
ARDOUR_UI::build_session_from_nsd (const Glib::ustring& session_path, const Glib::ustring& session_name)
 
2115
{
 
2116
        
 
2117
        uint32_t cchns;
 
2118
        uint32_t mchns;
 
2119
        AutoConnectOption iconnect;
 
2120
        AutoConnectOption oconnect;
 
2121
        uint32_t nphysin;
 
2122
        uint32_t nphysout;
 
2123
        
 
2124
        if (Profile->get_sae()) {
 
2125
                
 
2126
                cchns = 0;
 
2127
                mchns = 2;
 
2128
                iconnect = AutoConnectPhysical;
 
2129
                oconnect = AutoConnectMaster;
 
2130
                nphysin = 0; // use all available
 
2131
                nphysout = 0; // use all available
 
2132
                
 
2133
        } else {
 
2134
                
 
2135
                /* get settings from advanced section of NSD */
 
2136
                
 
2137
                if (new_session_dialog->create_control_bus()) {
 
2138
                        cchns = (uint32_t) new_session_dialog->control_channel_count();
 
2139
                } else {
 
2140
                        cchns = 0;
 
2141
                }
 
2142
                
 
2143
                if (new_session_dialog->create_master_bus()) {
 
2144
                        mchns = (uint32_t) new_session_dialog->master_channel_count();
 
2145
                } else {
 
2146
                        mchns = 0;
 
2147
                }
 
2148
                
 
2149
                if (new_session_dialog->connect_inputs()) {
 
2150
                        iconnect = AutoConnectPhysical;
 
2151
                } else {
 
2152
                        iconnect = AutoConnectOption (0);
 
2153
                }
 
2154
                
 
2155
                /// @todo some minor tweaks.
 
2156
                
 
2157
                if (new_session_dialog->connect_outs_to_master()) {
 
2158
                        oconnect = AutoConnectMaster;
 
2159
                } else if (new_session_dialog->connect_outs_to_physical()) {
 
2160
                        oconnect = AutoConnectPhysical;
 
2161
                } else {
 
2162
                        oconnect = AutoConnectOption (0);
 
2163
                } 
 
2164
                
 
2165
                nphysin = (uint32_t) new_session_dialog->input_limit_count();
 
2166
                nphysout = (uint32_t) new_session_dialog->output_limit_count();
 
2167
        }
 
2168
        
 
2169
        if (build_session (session_path,
 
2170
                           session_name,
 
2171
                           cchns,
 
2172
                           mchns,
 
2173
                           iconnect,
 
2174
                           oconnect,
 
2175
                           nphysin,
 
2176
                           nphysout, 
 
2177
                           engine->frame_rate() * 60 * 5)) {
 
2178
                
 
2179
                return -1;
 
2180
        }
 
2181
 
 
2182
        return 0;
 
2183
}
 
2184
 
 
2185
void
 
2186
ARDOUR_UI::end_loading_messages ()
 
2187
{
 
2188
        // hide_splash ();
 
2189
}
 
2190
 
 
2191
void
 
2192
ARDOUR_UI::loading_message (const std::string& msg)
 
2193
{
 
2194
        show_splash ();
 
2195
        splash->message (msg);
 
2196
        flush_pending ();
 
2197
}
 
2198
        
 
2199
bool
 
2200
ARDOUR_UI::get_session_parameters (bool backend_audio_is_running, bool should_be_new)
2034
2201
{
2035
2202
        bool existing_session = false;
2036
2203
        Glib::ustring session_name;
2037
2204
        Glib::ustring session_path;
2038
2205
        Glib::ustring template_name;
2039
2206
 
2040
 
        if (!loading_dialog) {
2041
 
                loading_dialog = new MessageDialog (*new_session_dialog, 
2042
 
                                                    "",
2043
 
                                                    false,
2044
 
                                                    Gtk::MESSAGE_INFO,
2045
 
                                                    Gtk::BUTTONS_NONE);
2046
 
        }
2047
 
 
2048
 
 
2049
2207
        int response = Gtk::RESPONSE_NONE;
2050
2208
 
2051
 
        if (predetermined_path.length()) {
2052
 
                
2053
 
                /* before we start, lets see if the given path looks like
2054
 
                   an existing ardour session. if it does, skip the
2055
 
                   tabs that we don't need
2056
 
                */
2057
 
 
2058
 
                if (Glib::file_test (predetermined_path, Glib::FILE_TEST_IS_DIR)) {
2059
 
                        session_path = predetermined_path;
2060
 
                        existing_session = true;
2061
 
                } else if (Glib::file_test (predetermined_path, Glib::FILE_TEST_IS_REGULAR)) {
2062
 
                        session_path = Glib::path_get_dirname (string (predetermined_path));
2063
 
                        existing_session = true;
2064
 
                } else {
2065
 
                        /* it doesn't exist, assume the best */
2066
 
                        session_path = Glib::path_get_dirname (string (predetermined_path));
 
2209
        if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
 
2210
 
 
2211
                parse_cmdline_path (ARDOUR_COMMAND_LINE::session_name, session_name, session_path, existing_session);
 
2212
 
 
2213
                /* don't ever reuse this */
 
2214
 
 
2215
                ARDOUR_COMMAND_LINE::session_name = string();
 
2216
 
 
2217
                if (existing_session && backend_audio_is_running) {
 
2218
 
 
2219
                        /* just load the thing already */
 
2220
 
 
2221
                        if (load_cmdline_session (session_name, session_path, existing_session) == 0) {
 
2222
                                return true;
 
2223
                        }
2067
2224
                }
2068
 
                       
2069
 
                session_name = basename_nosuffix (string (predetermined_path));
 
2225
 
 
2226
                /* make the NSD use whatever information we have */
2070
2227
 
2071
2228
                new_session_dialog->set_session_name (session_name);
2072
2229
                new_session_dialog->set_session_folder (session_path);
2073
 
                new_session_dialog->set_modal (true);
2074
 
 
2075
 
                if (existing_session) {
2076
 
 
2077
 
                        if (session_name.length() == 0 || session_path.length() == 0) {
2078
 
                                error << string_compose (_("Ardour cannot understand \"%1\" as a session name"), predetermined_path) << endmsg;
2079
 
                                return false;
2080
 
                        }
2081
 
                        
2082
 
                        if (Glib::file_test (predetermined_path, Glib::FILE_TEST_IS_DIR)) {
2083
 
                                Glib::ustring predicted_session_file;
2084
 
                                
2085
 
                                predicted_session_file = predetermined_path;
2086
 
                                predicted_session_file += '/';
2087
 
                                predicted_session_file += session_name;
2088
 
                                predicted_session_file += Session::statefile_suffix();
2089
 
                                
2090
 
                                if (Glib::file_test (predicted_session_file, Glib::FILE_TEST_EXISTS)) {
2091
 
                                        existing_session = true;
2092
 
                                }
2093
 
                                
2094
 
                        } else if (Glib::file_test (predetermined_path, Glib::FILE_TEST_EXISTS)) {
2095
 
                                
2096
 
                                if (predetermined_path.find (Session::statefile_suffix()) == predetermined_path.length() - 7) {
2097
 
                                        /* existing .ardour file */
2098
 
                                        existing_session = true;
2099
 
                                }
2100
 
                        } else {
2101
 
                                existing_session = false;
2102
 
                        }
2103
 
                        
2104
 
                        if (existing_session && have_engine) {
2105
 
                                /* lets just try to load it */
2106
 
                                
2107
 
                                loading_dialog->set_message (_("Starting audio engine"));
2108
 
                                loading_dialog->show_all ();
2109
 
                                flush_pending ();
2110
 
                                
2111
 
                                if (create_engine ()) {
2112
 
                                        backend_audio_error (!have_engine, new_session_dialog);
2113
 
                                        loading_dialog->hide ();
2114
 
                                        return false;
2115
 
                                }
2116
 
                                
2117
 
                                if (load_session (session_path, session_name) == 0) {
2118
 
                                        goto done;
2119
 
                                }
2120
 
                        }
2121
 
                }
2122
2230
        }
2123
2231
 
2124
2232
        /* loading failed, or we need the NSD for something */
2125
2233
 
 
2234
        new_session_dialog->set_modal (false);
2126
2235
        new_session_dialog->set_position (WIN_POS_CENTER);
2127
2236
        new_session_dialog->set_current_page (0);
2128
2237
        new_session_dialog->set_existing_session (existing_session);
2129
2238
        new_session_dialog->reset_recent();
2130
2239
 
2131
2240
        do {
2132
 
                new_session_dialog->set_have_engine (have_engine);
 
2241
                new_session_dialog->set_have_engine (backend_audio_is_running);
2133
2242
                new_session_dialog->present ();
2134
2243
                response = new_session_dialog->run ();
2135
 
                loading_dialog->hide ();
2136
2244
                
2137
2245
                _session_is_new = false;
2138
2246
                
2139
2247
                /* handle possible negative responses */
2140
2248
 
2141
 
                if (response == Gtk::RESPONSE_CANCEL || response == Gtk::RESPONSE_DELETE_EVENT) {
2142
 
                        
 
2249
                switch (response) {
 
2250
                case Gtk::RESPONSE_CANCEL:
 
2251
                case Gtk::RESPONSE_DELETE_EVENT:
2143
2252
                        if (!session) {
2144
2253
                                quit();
2145
2254
                        }
2146
2255
                        new_session_dialog->hide ();
2147
2256
                        return false;
2148
2257
                        
2149
 
                } else if (response == Gtk::RESPONSE_NONE) {
 
2258
                case Gtk::RESPONSE_NONE:
2150
2259
                        /* "Clear" was pressed */
2151
 
                        
2152
2260
                        goto try_again;
2153
2261
                }
2154
2262
 
2155
2263
                fontconfig_dialog();
2156
2264
 
2157
 
                /* if we're here to help set up audio parameters this is where want to do that.
2158
 
                */
2159
 
 
2160
 
                if (!have_engine) {
 
2265
                if (!backend_audio_is_running) {
2161
2266
                        if (new_session_dialog->engine_control.setup_engine ()) {
2162
2267
                                new_session_dialog->hide ();
2163
2268
                                return false;
2164
2269
                        } 
2165
 
 
2166
 
                        loading_dialog->set_message (_("Starting audio engine"));
2167
 
                        loading_dialog->show_all ();
2168
 
                        flush_pending ();
2169
2270
                }
2170
 
 
 
2271
                
2171
2272
                if (create_engine ()) {
2172
 
                        backend_audio_error (!have_engine, new_session_dialog);
2173
 
                        loading_dialog->hide ();
 
2273
 
 
2274
                        backend_audio_error (!backend_audio_is_running, new_session_dialog);
2174
2275
                        flush_pending ();
2175
 
                        /* audio setup page */
 
2276
 
2176
2277
                        new_session_dialog->set_existing_session (false);
2177
2278
                        new_session_dialog->set_current_page (2);
 
2279
 
2178
2280
                        response = Gtk::RESPONSE_NONE;
2179
2281
                        goto try_again;
2180
2282
                }
2181
2283
 
2182
 
                loading_dialog->hide ();
2183
 
                have_engine = true;             
2184
 
                        
2185
 
                /* now handle possible affirmative responses */
2186
 
 
2187
 
                if (response == Gtk::RESPONSE_YES) {
2188
 
 
2189
 
                        /* YES == OPEN from the session selector */
2190
 
 
2191
 
                        session_name = new_session_dialog->session_name();
2192
 
                        
 
2284
                backend_audio_is_running = true;                
 
2285
                        
 
2286
                if (response == Gtk::RESPONSE_OK) {
 
2287
 
 
2288
                        session_name = new_session_dialog->session_name();
 
2289
 
2193
2290
                        if (session_name.empty()) {
2194
2291
                                response = Gtk::RESPONSE_NONE;
2195
2292
                                goto try_again;
2196
2293
                        } 
2197
2294
 
 
2295
                        /* if the user mistakenly typed path information into the session filename entry,
 
2296
                           convert what they typed into a path & a name
 
2297
                        */
 
2298
                        
2198
2299
                        if (session_name[0] == '/' || 
2199
2300
                            (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == '/') ||
2200
2301
                            (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == '/')) {
2201
 
                                if (load_session (Glib::path_get_dirname (session_name), session_name)) {
2202
 
                                        response = Gtk::RESPONSE_NONE;
2203
 
                                        goto try_again;
2204
 
                                }
 
2302
                                
 
2303
                                session_path = Glib::path_get_dirname (session_name);
 
2304
                                session_name = Glib::path_get_basename (session_name);
 
2305
                                
2205
2306
                        } else {
 
2307
 
2206
2308
                                session_path = new_session_dialog->session_folder();
2207
 
                                if (load_session (session_path, session_name)) {
2208
 
                                        response = Gtk::RESPONSE_NONE;
2209
 
                                        goto try_again;
2210
 
                                }
2211
2309
                        }
2212
 
                        
2213
 
                } else if (response == Gtk::RESPONSE_OK) {
2214
 
 
2215
 
                        /* OK == OPEN button */
2216
 
 
2217
 
                        session_name = new_session_dialog->session_name();
2218
 
                
2219
 
                        if (session_name.empty()) {
2220
 
                                response = Gtk::RESPONSE_NONE;
2221
 
                                goto try_again;
2222
 
                        } 
2223
 
 
 
2310
 
 
2311
                        template_name = Glib::ustring();                        
2224
2312
                        switch (new_session_dialog->which_page()) {
 
2313
 
2225
2314
                        case NewSessionDialog::OpenPage: 
2226
2315
                        case NewSessionDialog::EnginePage:
2227
 
 
2228
 
                                if (session_name[0] == '/' || 
2229
 
                                    (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == '/') ||
2230
 
                                    (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == '/')) {
2231
 
 
2232
 
                                        if (load_session (Glib::path_get_dirname (session_name), session_name)) {
2233
 
                                                response = Gtk::RESPONSE_NONE;
2234
 
                                                goto try_again;
2235
 
                                        }
2236
 
 
2237
 
                                } else {
2238
 
                                        session_path = new_session_dialog->session_folder();
2239
 
                                        if (load_session (session_path, session_name)) {
2240
 
                                                response = Gtk::RESPONSE_NONE;
2241
 
                                                goto try_again;
2242
 
                                        }
2243
 
                                }
 
2316
                                goto loadit;
2244
2317
                                break;
2245
2318
 
2246
2319
                        case NewSessionDialog::NewPage: /* nominally the "new" session creator, but could be in use for an old session */
2247
 
 
2248
 
                                if (new_session_dialog->get_current_page() == 0 && ARDOUR_COMMAND_LINE::session_name.empty()) {
2249
 
                                        should_be_new = true;
2250
 
                                }
2251
 
 
2252
 
                                /* handle what appear to be paths rather than just a name */
2253
 
 
2254
 
                                if (session_name[0] == '/' || 
2255
 
                                    (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == '/') ||
2256
 
                                    (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == '/')) {
2257
 
 
2258
 
                                        session_path = Glib::path_get_dirname (session_name);
2259
 
                                        session_name = Glib::path_get_basename (session_name);
2260
 
 
2261
 
                                } else {
2262
 
 
2263
 
                                        session_path = new_session_dialog->session_folder();
2264
 
 
2265
 
                                }
2266
 
 
 
2320
                                
 
2321
                                should_be_new = true;
 
2322
                                
2267
2323
                                //XXX This is needed because session constructor wants a 
2268
2324
                                //non-existant path. hopefully this will be fixed at some point.
2269
2325
                                
2270
2326
                                session_path = Glib::build_filename (session_path, session_name);
2271
2327
 
2272
 
                                if (!should_be_new) {
 
2328
                                if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
2273
2329
 
2274
 
                                        if (load_session (session_path, session_name)) {
2275
 
                                                response = Gtk::RESPONSE_NONE;
 
2330
                                        if (ask_about_loading_existing_session (session_path)) {
 
2331
                                                goto loadit;
 
2332
                                        } else {
 
2333
                                                response = RESPONSE_NONE;
2276
2334
                                                goto try_again;
2277
 
                                        }
2278
 
 
2279
 
                                        continue; /* leaves while() loop because response != NONE */
2280
 
 
2281
 
                                } else if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
2282
 
 
2283
 
                                        Glib::ustring str = string_compose (_("This session\n%1\nalready exists. Do you want to open it?"), session_path);
2284
 
 
2285
 
                                        MessageDialog msg (str,
2286
 
                                                           false,
2287
 
                                                           Gtk::MESSAGE_WARNING,
2288
 
                                                           Gtk::BUTTONS_YES_NO,
2289
 
                                                           true);
2290
 
 
2291
 
 
2292
 
                                        msg.set_name (X_("CleanupDialog"));
2293
 
                                        msg.set_wmclass (X_("existing_session"), "Ardour");
2294
 
                                        msg.set_position (Gtk::WIN_POS_MOUSE);
2295
 
                                        
2296
 
                                        switch (msg.run()) {
2297
 
                                        case RESPONSE_YES:
2298
 
                                                new_session_dialog->hide ();
2299
 
                                                goto_editor_window ();
2300
 
                                                flush_pending ();
2301
 
                                                if (load_session (session_path, session_name)) {
2302
 
                                                        response = Gtk::RESPONSE_NONE;
2303
 
                                                        goto try_again;
2304
 
                                                }
2305
 
                                                goto done;
2306
 
                                                break;
2307
 
                                        default:
2308
 
                                                response = RESPONSE_NONE;
2309
 
                                                new_session_dialog->reset ();
2310
 
                                                new_session_dialog->set_existing_session (false);
2311
 
                                                loading_dialog->hide ();
2312
 
                                                continue;
2313
 
                                        }
2314
 
                                } 
 
2335
                                        } 
 
2336
                                }
2315
2337
 
2316
2338
                                _session_is_new = true;
2317
2339
                                                
2318
2340
                                if (new_session_dialog->use_session_template()) {
2319
2341
 
2320
2342
                                        template_name = new_session_dialog->session_template_name();
2321
 
 
2322
 
                                        new_session_dialog->hide ();
2323
 
                                        goto_editor_window ();
2324
 
                                        flush_pending ();
2325
 
 
2326
 
                                        if (load_session (session_path, session_name, template_name)) {
2327
 
                                                response = Gtk::RESPONSE_NONE;
2328
 
                                                goto try_again;
2329
 
                                        }
2330
 
 
 
2343
                                        goto loadit;
2331
2344
                          
2332
2345
                                } else {
2333
 
 
2334
 
                                        uint32_t cchns;
2335
 
                                        uint32_t mchns;
2336
 
                                        AutoConnectOption iconnect;
2337
 
                                        AutoConnectOption oconnect;
2338
 
                                        uint32_t nphysin;
2339
 
                                        uint32_t nphysout;
2340
 
                                        
2341
 
                                        if (Profile->get_sae()) {
2342
 
 
2343
 
                                                cchns = 0;
2344
 
                                                mchns = 2;
2345
 
                                                iconnect = AutoConnectPhysical;
2346
 
                                                oconnect = AutoConnectMaster;
2347
 
                                                nphysin = 0; // use all available
2348
 
                                                nphysout = 0; // use all available
2349
 
 
2350
 
                                        } else {
2351
 
 
2352
 
                                                /* get settings from advanced section of NSD */
2353
 
                                                
2354
 
                                                if (new_session_dialog->create_control_bus()) {
2355
 
                                                        cchns = (uint32_t) new_session_dialog->control_channel_count();
2356
 
                                                } else {
2357
 
                                                        cchns = 0;
2358
 
                                                }
2359
 
                                                
2360
 
                                                if (new_session_dialog->create_master_bus()) {
2361
 
                                                        mchns = (uint32_t) new_session_dialog->master_channel_count();
2362
 
                                                } else {
2363
 
                                                        mchns = 0;
2364
 
                                                }
2365
 
                                                
2366
 
                                                if (new_session_dialog->connect_inputs()) {
2367
 
                                                        iconnect = AutoConnectPhysical;
2368
 
                                                } else {
2369
 
                                                        iconnect = AutoConnectOption (0);
2370
 
                                                }
2371
 
                                                
2372
 
                                                /// @todo some minor tweaks.
2373
 
                                                
2374
 
                                                if (new_session_dialog->connect_outs_to_master()) {
2375
 
                                                        oconnect = AutoConnectMaster;
2376
 
                                                } else if (new_session_dialog->connect_outs_to_physical()) {
2377
 
                                                        oconnect = AutoConnectPhysical;
2378
 
                                                } else {
2379
 
                                                        oconnect = AutoConnectOption (0);
2380
 
                                                } 
2381
 
                                                
2382
 
                                                nphysin = (uint32_t) new_session_dialog->input_limit_count();
2383
 
                                                nphysout = (uint32_t) new_session_dialog->output_limit_count();
2384
 
                                        }
2385
 
 
2386
 
                                        if (build_session (session_path,
2387
 
                                                           session_name,
2388
 
                                                           cchns,
2389
 
                                                           mchns,
2390
 
                                                           iconnect,
2391
 
                                                           oconnect,
2392
 
                                                           nphysin,
2393
 
                                                           nphysout, 
2394
 
                                                           engine->frame_rate() * 60 * 5)) {
2395
 
                                                
2396
 
                                                response = Gtk::RESPONSE_NONE;
 
2346
                                        if (build_session_from_nsd (session_path, session_name)) {
 
2347
                                                response = RESPONSE_NONE;
2397
2348
                                                goto try_again;
2398
2349
                                        }
2399
 
 
2400
 
                                        new_session_dialog->hide ();
2401
 
                                        goto_editor_window ();
2402
 
                                        flush_pending ();
 
2350
                                        goto done;
2403
2351
                                }
2404
2352
                                break;
2405
 
 
 
2353
                                
2406
2354
                        default:
2407
2355
                                break;
2408
2356
                        }
2409
 
                }
2410
 
 
2411
 
          try_again:
2412
 
                if (response == Gtk::RESPONSE_NONE) {
2413
 
                        loading_dialog->hide ();
2414
 
                        new_session_dialog->set_existing_session (false);
2415
 
                        new_session_dialog->reset ();
2416
 
                }
2417
 
                
 
2357
                        
 
2358
                  loadit:
 
2359
                        new_session_dialog->hide ();
 
2360
                        
 
2361
                        if (load_session (session_path, session_name, template_name)) {
 
2362
                                /* force a retry */
 
2363
                                response = Gtk::RESPONSE_NONE;
 
2364
                        }
 
2365
 
 
2366
                  try_again:
 
2367
                        if (response == Gtk::RESPONSE_NONE) {
 
2368
                                new_session_dialog->set_existing_session (false);
 
2369
                                new_session_dialog->reset ();
 
2370
                        }
 
2371
                }
 
2372
 
2418
2373
        } while (response == Gtk::RESPONSE_NONE);
2419
2374
 
2420
2375
  done:
2421
2376
        show();
2422
 
        loading_dialog->hide ();
2423
2377
        new_session_dialog->hide();
 
2378
        new_session_dialog->reset();
 
2379
        goto_editor_window ();
2424
2380
        return true;
2425
 
}
 
2381
}       
2426
2382
 
2427
2383
void
2428
2384
ARDOUR_UI::close_session ()
2433
2389
 
2434
2390
        unload_session (true);
2435
2391
        
2436
 
        get_session_parameters ("", true, false);
 
2392
        get_session_parameters (true, false);
2437
2393
}
2438
2394
 
2439
2395
int
2463
2419
        if (Glib::file_test (path.c_str(), Glib::FILE_TEST_EXISTS) && ::access (path.c_str(), W_OK)) {
2464
2420
                MessageDialog msg (*editor, _("You do not have write access to this session.\n"
2465
2421
                                              "This prevents the session from being loaded."));
 
2422
                pop_back_splash ();
2466
2423
                msg.run ();
2467
2424
                goto out;
2468
2425
        }
2469
2426
 
2470
 
        if (loading_dialog) {
2471
 
                loading_dialog->set_markup (_("Please wait while Ardour loads your session"));
2472
 
                flush_pending ();
2473
 
        }
2474
 
 
 
2427
        loading_message (_("Please wait while Ardour loads your session"));
2475
2428
        disable_screen_updates ();
2476
2429
 
2477
2430
        try {
2490
2443
                msg.set_title (_("Loading Error"));
2491
2444
                msg.set_secondary_text (_("Click the OK button to try again."));
2492
2445
                msg.set_position (Gtk::WIN_POS_CENTER);
 
2446
                pop_back_splash ();
2493
2447
                msg.present ();
2494
2448
 
2495
2449
                int response = msg.run ();
2515
2469
                msg.set_title (_("Loading Error"));
2516
2470
                msg.set_secondary_text (_("Click the OK button to try again."));
2517
2471
                msg.set_position (Gtk::WIN_POS_CENTER);
 
2472
                pop_back_splash ();
2518
2473
                msg.present ();
2519
2474
 
2520
2475
                int response = msg.run ();
2587
2542
        catch (...) {
2588
2543
 
2589
2544
                MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
 
2545
                pop_back_splash ();
2590
2546
                msg.run ();
2591
2547
                return -1;
2592
2548
        }
2612
2568
}
2613
2569
 
2614
2570
void
2615
 
ARDOUR_UI::show_splash ()
 
2571
ARDOUR_UI::show_about ()
2616
2572
{
2617
2573
        if (about == 0) {
2618
 
                about = new About();
 
2574
                about = new About;
2619
2575
                about->signal_response().connect(mem_fun (*this, &ARDOUR_UI::about_signal_response) );
2620
2576
        }
2621
 
        about->present();
2622
 
        flush_pending ();
 
2577
 
 
2578
        about->show_all ();
 
2579
}
 
2580
 
 
2581
void
 
2582
ARDOUR_UI::hide_about ()
 
2583
{
 
2584
        if (about) {
 
2585
                about->get_window()->set_cursor ();
 
2586
                about->hide ();
 
2587
        }
2623
2588
}
2624
2589
 
2625
2590
void
2626
2591
ARDOUR_UI::about_signal_response(int response)
2627
2592
{
2628
 
        hide_splash();
 
2593
        hide_about();
 
2594
}
 
2595
 
 
2596
void
 
2597
ARDOUR_UI::show_splash ()
 
2598
{
 
2599
        if (splash == 0) {
 
2600
                try {
 
2601
                        splash = new Splash;
 
2602
                } catch (...) {
 
2603
                        return;
 
2604
                }
 
2605
        }
 
2606
 
 
2607
        splash->show ();
 
2608
        splash->present ();
 
2609
        splash->queue_draw ();
 
2610
        splash->get_window()->process_updates (true);
 
2611
        flush_pending ();
2629
2612
}
2630
2613
 
2631
2614
void
2632
2615
ARDOUR_UI::hide_splash ()
2633
2616
{
2634
 
        if (about) {
2635
 
                about->get_window()->set_cursor ();
2636
 
                about->hide();
 
2617
        if (splash) {
 
2618
                splash->hide();
2637
2619
        }
2638
2620
}
2639
2621
 
3014
2996
                return 0;
3015
2997
        }
3016
2998
}
 
2999
 
 
3000
int
 
3001
ARDOUR_UI::sr_mismatch_dialog (nframes_t desired, nframes_t actual)
 
3002
{
 
3003
        HBox* hbox = new HBox();
 
3004
        Image* image = new Image (Stock::DIALOG_QUESTION, ICON_SIZE_DIALOG);
 
3005
        ArdourDialog dialog (_("Sample Rate Mismatch"), true);
 
3006
        Label  message (string_compose (_("\
 
3007
This session was created with a sample rate of %1 Hz\n\
 
3008
\n\
 
3009
The audioengine is currently running at %2 Hz\n"), desired, actual));
 
3010
 
 
3011
        image->set_alignment(ALIGN_CENTER, ALIGN_TOP);
 
3012
        hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12);
 
3013
        hbox->pack_end (message, PACK_EXPAND_PADDING, 12);
 
3014
        dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6);
 
3015
        dialog.add_button (_("Do not load session"), RESPONSE_REJECT);
 
3016
        dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT);
 
3017
        dialog.set_default_response (RESPONSE_ACCEPT);
 
3018
        dialog.set_position (WIN_POS_CENTER);
 
3019
        message.show();
 
3020
        image->show();
 
3021
        hbox->show();
 
3022
 
 
3023
        switch (dialog.run ()) {
 
3024
        case RESPONSE_ACCEPT:
 
3025
                return 0;
 
3026
        default:
 
3027
                return 1;
 
3028
        }
 
3029
}
 
3030
 
3017
3031
        
3018
3032
void
3019
3033
ARDOUR_UI::disconnect_from_jack ()
3041
3055
        }
3042
3056
}
3043
3057
 
3044
 
int
3045
 
ARDOUR_UI::cmdline_new_session (string path)
3046
 
{
3047
 
        if (path[0] != '/') {
3048
 
                char buf[PATH_MAX+1];
3049
 
                string str;
3050
 
 
3051
 
                getcwd (buf, sizeof (buf));
3052
 
                str = buf;
3053
 
                str += '/';
3054
 
                str += path;
3055
 
                path = str;
3056
 
        }
3057
 
 
3058
 
        get_session_parameters (path, false, true);
3059
 
 
3060
 
        _will_create_new_session_automatically = false; /* done it */
3061
 
        return FALSE; /* don't call it again */
3062
 
}
3063
 
 
3064
3058
void
3065
3059
ARDOUR_UI::use_config ()
3066
3060
{