Unify the canvases by moving groups around rather than using set_scrolling_region...
[ardour.git] / gtk2_ardour / editor_audio_import.cc
index fa14e2b88fc51f14345867906bec6a2d0b19cafa..3d75de782c5c2017884d8af5c4c8cf0002287c25 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/time.h>
 #include <errno.h>
 #include <unistd.h>
+#include <algorithm>
 
 #include <sndfile.h>
 
@@ -69,7 +70,7 @@ void
 Editor::add_external_audio_action (ImportMode mode_hint)
 {
        if (session == 0) {
-               MessageDialog msg (0, _("You can't import or embed an audiofile until you have a session loaded."));
+               MessageDialog msg (_("You can't import or embed an audiofile until you have a session loaded."));
                msg.run ();
                return;
        }
@@ -90,7 +91,7 @@ Editor::external_audio_dialog ()
        uint32_t track_cnt;
 
        if (session == 0) {
-               MessageDialog msg (0, _("You can't import or embed an audiofile until you have a session loaded."));
+               MessageDialog msg (_("You can't import or embed an audiofile until you have a session loaded."));
                msg.run ();
                return;
        }
@@ -196,7 +197,7 @@ typedef std::map<PBD::ID,boost::shared_ptr<AudioSource> > AudioSourceList;
 int
 Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
 {
-       string wave_name (basename(path.c_str()));
+       string wave_name (Glib::path_get_basename(path));
 
        AudioSourceList all_sources = session->get_audio_sources();
        bool wave_name_exists = false;
@@ -204,7 +205,7 @@ Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
        for (AudioSourceList::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
                boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(i->second);
 
-               string tmp (basename(afs->path().c_str()));
+               string tmp (Glib::path_get_basename (afs->path()));
 
                if (tmp == wave_name) {
                        wave_name_exists = true;
@@ -222,7 +223,7 @@ Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
                        //message = string_compose(_("The session already contains a source file named %1. Do you want to update that file (and thus all regions using the file) or import this file as a new file?"),wave_name);
                        message = string_compose(_("The session already contains a source file named %1. This file will be imported as a new file, please confirm."),wave_name);
                } else {
-                       message = _("Lorem ipsum. Do you want to skidaddle?");
+                       message = string_compose(_("A source file %1 already exists. This operation will not update that source but import the file %2 as a new source, please confirm."), wave_name, wave_name);
 
                }
                MessageDialog dialog(message, false,Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
@@ -280,8 +281,25 @@ Editor::get_nth_selected_audio_track (int nth) const
        return atv->audio_track();
 }      
 
+bool
+Editor::idle_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
+{
+       _do_import (paths, chns, mode, quality, pos);
+       return false;
+}
+
 void
 Editor::do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
+{
+#ifdef GTKOSX
+       Glib::signal_idle().connect (bind (mem_fun (*this, &Editor::idle_do_import), paths, chns, mode, quality, pos));
+#else
+       _do_import (paths, chns, mode, quality, pos);
+#endif
+}
+
+void
+Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
 {
        boost::shared_ptr<AudioTrack> track;
        vector<ustring> to_import;
@@ -292,7 +310,6 @@ Editor::do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mod
                build_interthread_progress_window ();
        }
 
-
        if (chns == Editing::ImportMergeFiles) {
                /* create 1 region from all paths, add to 1 track,
                   ignore "track"
@@ -479,7 +496,6 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
 
        interthread_progress_window->set_title (title.get_string());
        interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
-       interthread_progress_window->show_all ();
        interthread_progress_bar.set_fraction (0.0f);
        interthread_cancel_label.set_text (_("Cancel Import"));
        current_interthread_info = &import_status;
@@ -493,9 +509,9 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
        import_status.replace_existing_source = replace;
 
        interthread_progress_connection = Glib::signal_timeout().connect 
-               (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
+               (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 500);
        
-       track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
+       track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
        ARDOUR_UI::instance()->flush_pending ();
 
        /* start import thread for this spec. this will ultimately call Session::import_audiofile()
@@ -527,7 +543,7 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
        }
 
   out:
-       track_canvas.get_window()->set_cursor (*current_canvas_cursor);
+       track_canvas->get_window()->set_cursor (*current_canvas_cursor);
        return 0;
 }
 
@@ -542,7 +558,7 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
        SoundFileInfo finfo;
        int ret = 0;
 
-       track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
+       track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
        ARDOUR_UI::instance()->flush_pending ();
 
        for (vector<Glib::ustring>::iterator p = paths.begin(); p != paths.end(); ++p) {
@@ -643,7 +659,7 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
                        }
                }
                
-               track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
+               track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
 
                for (int n = 0; n < finfo.channels; ++n) {
                        try {
@@ -653,6 +669,9 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
                                boost::shared_ptr<Source> s;
 
                                if ((s = session->source_by_path_and_channel (path, n)) == 0) {
+
+                                       cerr << "add embed/import source with defer_peaks = true\n";
+
                                        source = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createReadable 
                                                                                               (*session, path,  n,
                                                                                                (mode == ImportAsTapeTrack ? 
@@ -682,7 +701,7 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
        ret = add_sources (paths, sources, pos, mode, target_regions, target_tracks, track, true);
 
   out:
-       track_canvas.get_window()->set_cursor (*current_canvas_cursor);
+       track_canvas->get_window()->set_cursor (*current_canvas_cursor);
        return ret;
 }
 
@@ -860,6 +879,13 @@ Editor::import_thread ()
 gint
 Editor::import_progress_timeout (void *arg)
 {
+       bool reset = false;
+
+       if (!interthread_progress_window->is_visible()) {
+               interthread_progress_window->show_all ();
+               reset = true;
+       }
+       
        interthread_progress_label.set_text (import_status.doing_what);
 
        if (import_status.freeze) {
@@ -872,9 +898,20 @@ Editor::import_progress_timeout (void *arg)
                interthread_progress_bar.pulse ();
                return FALSE;
        } else {
-               interthread_progress_bar.set_fraction (import_status.progress);
+               float val = import_status.progress;
+               interthread_progress_bar.set_fraction (min (max (0.0f, val), 1.0f));
        }
 
-       return !(import_status.done || import_status.cancel);
+       if (reset) {
+
+               /* the window is now visible, speed up the updates */
+               
+               interthread_progress_connection.disconnect ();
+               interthread_progress_connection = Glib::signal_timeout().connect 
+                       (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
+               return false;
+       } else {
+               return !(import_status.done || import_status.cancel);
+       }
 }