summaryrefslogtreecommitdiff
path: root/gtk2_ardour/editor_audio_import.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2008-11-13 10:00:09 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2008-11-13 10:00:09 +0000
commit45b4721be3d310c157d8e7f7a656f39eae69510f (patch)
tree3d697dcda1947918d00809639cde737d950f8367 /gtk2_ardour/editor_audio_import.cc
parent02c49688c72cf88d2e2f8eb6908355c8b37e6c95 (diff)
speed up track resizing; fixup file DnD; stop use CAAudioFile for imported files
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@4148 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour/editor_audio_import.cc')
-rw-r--r--gtk2_ardour/editor_audio_import.cc186
1 files changed, 71 insertions, 115 deletions
diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc
index 41f07692ca..fa946f90c9 100644
--- a/gtk2_ardour/editor_audio_import.cc
+++ b/gtk2_ardour/editor_audio_import.cc
@@ -52,6 +52,7 @@
#include "editing.h"
#include "audio_time_axis.h"
#include "utils.h"
+#include "gui_thread.h"
#include "i18n.h"
@@ -203,6 +204,7 @@ Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
bool wave_name_exists = false;
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 (Glib::path_get_basename (afs->path()));
@@ -215,7 +217,6 @@ Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
int function = 1;
-
if (wave_name_exists) {
string message;
if (all_or_nothing) {
@@ -238,7 +239,6 @@ Editor::check_whether_and_how_to_import(string path, bool all_or_nothing)
dialog.add_button("Cancel", 2);
}
-
//dialog.add_button("Skip all", 4); // All or rest?
dialog.show();
@@ -281,39 +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)
{
- _do_import (paths, chns, mode, quality, pos);
-}
-
-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;
- bool ok = true;
int nth = 0;
if (interthread_progress_window == 0) {
build_interthread_progress_window ();
}
- cerr << "Here we go .. disp = " << chns << " mode = " << mode << " @ " << pos << endl;
-
if (chns == Editing::ImportMergeFiles) {
+
/* create 1 region from all paths, add to 1 track,
ignore "track"
*/
+
bool cancel = false;
- for (vector<ustring>::iterator a = paths.begin(); a != paths.end() && ok; ++a) {
+ for (vector<ustring>::iterator a = paths.begin(); a != paths.end(); ++a) {
int check = check_whether_and_how_to_import(*a, false);
if (check == 2) {
cancel = true;
@@ -322,14 +308,14 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
}
if (!cancel) {
- cerr << "Here we REALLY go ..\n";
- if (import_sndfiles (paths, mode, quality, pos, 1, 1, track, false)) {
- ok = false;
- }
+ import_sndfiles (paths, mode, quality, pos, 1, 1, track, false, paths.size());
}
} else {
+
bool replace = false;
+ bool ok = true;
+ vector<ustring>::size_type total = paths.size();
for (vector<ustring>::iterator a = paths.begin(); a != paths.end() && ok; ++a) {
@@ -337,7 +323,7 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
switch (check) {
case 2:
- // skip
+ // user said skip
continue;
case 0:
fatal << "Updating existing sources should be disabled!" << endmsg;
@@ -351,81 +337,49 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
/* NOTREACHED*/
}
- switch (chns) {
- case Editing::ImportDistinctFiles:
- to_import.clear ();
- to_import.push_back (*a);
-
- if (mode == Editing::ImportToTrack) {
- track = get_nth_selected_audio_track (nth++);
- }
-
- cerr << "Here we REALLY go 2 ..\n";
- if (import_sndfiles (to_import, mode, quality, pos, 1, -1, track, replace)) {
- ok = false;
- }
-
- break;
-
- case Editing::ImportDistinctChannels:
-
- to_import.clear ();
- to_import.push_back (*a);
-
- cerr << "Here we REALLY go 3 ..\n";
- if (import_sndfiles (to_import, mode, quality, pos, -1, -1, track, replace)) {
- ok = false;
- }
-
- break;
-
- case Editing::ImportSerializeFiles:
-
- to_import.clear ();
- to_import.push_back (*a);
-
- /* create 1 region from this path, add to 1 track,
- reuse "track" across paths
- */
-
- cerr << "Here we REALLY go 4 ..\n";
- if (import_sndfiles (to_import, mode, quality, pos, 1, 1, track, replace)) {
- ok = false;
- }
+ switch (chns) {
+ case Editing::ImportDistinctFiles:
+
+ to_import.clear ();
+ to_import.push_back (*a);
+
+ if (mode == Editing::ImportToTrack) {
+ track = get_nth_selected_audio_track (nth++);
+ }
+
+ ok = (import_sndfiles (to_import, mode, quality, pos, 1, -1, track, replace, total) == 0);
+ break;
+
+ case Editing::ImportDistinctChannels:
+
+ to_import.clear ();
+ to_import.push_back (*a);
+
+ ok = (import_sndfiles (to_import, mode, quality, pos, -1, -1, track, replace, total) == 0);
+ break;
+
+ case Editing::ImportSerializeFiles:
+
+ to_import.clear ();
+ to_import.push_back (*a);
- break;
+ ok = (import_sndfiles (to_import, mode, quality, pos, 1, 1, track, replace, total) == 0);
+ break;
- case Editing::ImportMergeFiles:
- // Not entered
- break;
+ case Editing::ImportMergeFiles:
+ // Not entered, handled in earlier if() branch
+ break;
}
}
-
- if (ok) {
- session->save_state ("");
- }
-
- interthread_progress_window->hide_all ();
}
-}
-bool
-Editor::idle_do_embed (vector<ustring> paths, ImportDisposition chns, ImportMode mode, nframes64_t& pos)
-{
- _do_embed (paths, chns, mode, pos);
- return false;
+ interthread_progress_window->hide_all ();
}
void
Editor::do_embed (vector<ustring> paths, ImportDisposition chns, ImportMode mode, nframes64_t& pos)
{
- _do_embed (paths, chns, mode, pos);
-}
-
-void
-Editor::_do_embed (vector<ustring> paths, ImportDisposition chns, ImportMode mode, nframes64_t& pos)
-{
boost::shared_ptr<AudioTrack> track;
bool check_sample_rate = true;
bool ok = false;
@@ -491,7 +445,8 @@ Editor::_do_embed (vector<ustring> paths, ImportDisposition chns, ImportMode mod
int
Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality quality, nframes64_t& pos,
- int target_regions, int target_tracks, boost::shared_ptr<AudioTrack>& track, bool replace)
+ int target_regions, int target_tracks, boost::shared_ptr<AudioTrack> track, bool replace,
+ uint32_t total)
{
WindowTitle title = string_compose (_("importing %1"), paths.front());
@@ -508,7 +463,14 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
import_status.done = 0.0;
import_status.quality = quality;
import_status.replace_existing_source = replace;
-
+ import_status.total = total;
+
+ import_status.mode = mode;
+ import_status.pos = pos;
+ import_status.target_tracks = target_tracks;
+ import_status.target_regions = target_regions;
+ import_status.track = track;
+ import_status.replace = replace;
interthread_progress_connection = Glib::signal_timeout().connect
(bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 500);
@@ -516,42 +478,38 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
gdk_flush ();
/* start import thread for this spec. this will ultimately call Session::import_audiofile()
- and if successful will add the file(s) as a region to the session region list.
+ which, if successful, will add the files as regions to the region list. its up to us
+ (the GUI) to direct additional steps after that.
*/
-
- cerr << "Creating import thread\n";
pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
pthread_detach (import_status.thread);
- cerr << "into rec loop while thread runs\n";
-
- while (!(import_status.done || import_status.cancel)) {
+ while (!import_status.done && !import_status.cancel) {
gtk_main_iteration ();
}
- cerr << "back from rec loop while thread run, status.cancel = " << import_status.cancel
- << " done = " << import_status.done << " progress = " << import_status.progress << endl;
-
interthread_progress_window->hide ();
-
import_status.done = true;
interthread_progress_connection.disconnect ();
- /* import thread finished - see if we should build a new track */
-
- boost::shared_ptr<AudioRegion> r;
-
- if (import_status.cancel || import_status.sources.empty()) {
- cerr << "Cancelled ? " << import_status.cancel << " or no files\n";
- goto out;
+ if (!import_status.cancel && !import_status.sources.empty()) {
+ if (add_sources (import_status.paths,
+ import_status.sources,
+ import_status.pos,
+ import_status.mode,
+ import_status.target_regions,
+ import_status.target_tracks,
+ import_status.track, false) == 0) {
+ session->save_state ("");
+ }
+
+ /* update position from results */
+
+ pos = import_status.pos;
}
- if (add_sources (paths, import_status.sources, pos, mode, target_regions, target_tracks, track, false) == 0) {
- session->save_state ("");
- }
- out:
track_canvas->get_window()->set_cursor (*current_canvas_cursor);
return 0;
}
@@ -559,7 +517,7 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
int
Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
bool& check_sample_rate, ImportMode mode, nframes64_t& pos, int target_regions, int target_tracks,
- boost::shared_ptr<AudioTrack>& track)
+ boost::shared_ptr<AudioTrack> track)
{
boost::shared_ptr<AudioFileSource> source;
SourceList sources;
@@ -568,7 +526,7 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
int ret = 0;
track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
- ARDOUR_UI::instance()->flush_pending ();
+ gdk_flush ();
for (vector<Glib::ustring>::iterator p = paths.begin(); p != paths.end(); ++p) {
@@ -679,8 +637,6 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
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 ?
@@ -741,7 +697,7 @@ Editor::add_sources (vector<Glib::ustring> paths, SourceList& sources, nframes64
(RegionFactory::create (sources, 0, sources[0]->length(), region_name, 0,
Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External))));
- } else if (target_regions == -1) {
+ } else if (target_regions == -1 || target_regions > 1) {
/* take each source and create a region for each one */