13
0

pt import: Fix progress bar to span the whole import

This commit is contained in:
Damien Zammit 2021-01-09 16:09:25 +11:00
parent ea8b855b4a
commit 5d0de7e037
3 changed files with 12 additions and 9 deletions

View File

@ -110,8 +110,8 @@ Editor::external_pt_dialog ()
MessageDialog msg (_("PT import cancelled")); MessageDialog msg (_("PT import cancelled"));
msg.run (); msg.run ();
} else { } else {
_session->import_pt_rest (import_ptf);
import_pt_status.progress = 1.0; import_pt_status.progress = 1.0;
_session->import_pt_rest (import_ptf);
MessageDialog msg (_("PT import complete!")); MessageDialog msg (_("PT import complete!"));
msg.run (); msg.run ();
} }

View File

@ -1278,7 +1278,7 @@ public:
void import_pt_sources (PTFFormat& ptf, ImportStatus& status); void import_pt_sources (PTFFormat& ptf, ImportStatus& status);
void import_pt_rest (PTFFormat& ptf); void import_pt_rest (PTFFormat& ptf);
bool import_sndfile_as_region (std::string path, SrcQuality quality, samplepos_t& pos, SourceList& sources, ImportStatus& status); bool import_sndfile_as_region (std::string path, SrcQuality quality, samplepos_t& pos, SourceList& sources, ImportStatus& status, uint32_t current, uint32_t total);
struct ptflookup { struct ptflookup {
uint16_t index1; uint16_t index1;

View File

@ -68,13 +68,13 @@ struct midipair {
}; };
bool bool
Session::import_sndfile_as_region (string path, SrcQuality quality, samplepos_t& pos, SourceList& sources, ImportStatus& status) Session::import_sndfile_as_region (string path, SrcQuality quality, samplepos_t& pos, SourceList& sources, ImportStatus& status, uint32_t current, uint32_t total)
{ {
/* Import the source */ /* Import the source */
status.paths.clear(); status.paths.clear();
status.paths.push_back(path); status.paths.push_back(path);
status.current = 1; status.current = current;
status.total = 1; status.total = total;
status.freeze = false; status.freeze = false;
status.quality = quality; status.quality = quality;
status.replace_existing_source = false; status.replace_existing_source = false;
@ -83,16 +83,17 @@ Session::import_sndfile_as_region (string path, SrcQuality quality, samplepos_t&
status.cancel = false; status.cancel = false;
import_files(status); import_files(status);
status.progress = 1.0;
sources.clear(); sources.clear();
/* FIXME: There is no way to tell if cancel button was pressed /* FIXME: There is no way to tell if cancel button was pressed
* or if the file failed to import, just that one of these occurred. * or if the file failed to import, just that one of these occurred.
* We want status.cancel to reflect the user's choice only * We want status.cancel to reflect the user's choice only
*/ */
if (status.cancel && status.current > 1) { if (status.cancel && status.current > current) {
/* Succeeded to import file, assume user hit cancel */ /* Succeeded to import file, assume user hit cancel */
return false; return false;
} else if (status.cancel && status.current == 1) { } else if (status.cancel && status.current == current) {
/* Failed to import file, assume user did not hit cancel */ /* Failed to import file, assume user did not hit cancel */
status.cancel = false; status.cancel = false;
return false; return false;
@ -187,6 +188,7 @@ Session::import_pt_sources (PTFFormat& ptf, ImportStatus& status)
vector<struct ptflookup> ptfregpair; vector<struct ptflookup> ptfregpair;
vector<PTFFormat::wav_t>::const_iterator w; vector<PTFFormat::wav_t>::const_iterator w;
uint32_t wth = 0;
SourceList just_one_src; SourceList just_one_src;
@ -199,20 +201,21 @@ Session::import_pt_sources (PTFFormat& ptf, ImportStatus& status)
for (w = ptf.audiofiles ().begin (); w != ptf.audiofiles ().end () && !status.cancel; ++w) { for (w = ptf.audiofiles ().begin (); w != ptf.audiofiles ().end () && !status.cancel; ++w) {
struct ptflookup p; struct ptflookup p;
wth++;
ok = false; ok = false;
/* Try audio file */ /* Try audio file */
fullpath = Glib::build_filename (Glib::path_get_dirname (ptf.path ()), "Audio Files"); fullpath = Glib::build_filename (Glib::path_get_dirname (ptf.path ()), "Audio Files");
fullpath = Glib::build_filename (fullpath, w->filename); fullpath = Glib::build_filename (fullpath, w->filename);
if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS)) { if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS)) {
just_one_src.clear(); just_one_src.clear();
ok = import_sndfile_as_region (fullpath, SrcBest, pos, just_one_src, status); ok = import_sndfile_as_region (fullpath, SrcBest, pos, just_one_src, status, wth, ptf.audiofiles ().size ());
} else { } else {
/* Try fade file */ /* Try fade file */
fullpath = Glib::build_filename (Glib::path_get_dirname (ptf.path ()), "Fade Files"); fullpath = Glib::build_filename (Glib::path_get_dirname (ptf.path ()), "Fade Files");
fullpath = Glib::build_filename (fullpath, w->filename); fullpath = Glib::build_filename (fullpath, w->filename);
if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS)) { if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS)) {
just_one_src.clear(); just_one_src.clear();
ok = import_sndfile_as_region (fullpath, SrcBest, pos, just_one_src, status); ok = import_sndfile_as_region (fullpath, SrcBest, pos, just_one_src, status, wth, ptf.audiofiles ().size ());
} else { } else {
onefailed = true; onefailed = true;