Update AAF import UI

This commit is contained in:
agfline 2024-04-17 23:57:12 +02:00 committed by Robin Gareus
parent 41587d3c06
commit 8ea3a14cd6
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -50,25 +50,37 @@ using namespace ARDOUR;
static void static void
aaf_debug_callback (struct aafLog* log, void* ctxdata, int libid, int type, const char* srcfile, const char* srcfunc, int lineno, const char* msg, void* user) aaf_debug_callback (struct aafLog* log, void* ctxdata, int libid, int type, const char* srcfile, const char* srcfunc, int lineno, const char* msg, void* user)
{ {
const char *eol = ""; const char* eol = "";
if ( libid != LOG_SRC_ID_TRACE && libid != LOG_SRC_ID_DUMP ) { if (libid != LOG_SRC_ID_TRACE && libid != LOG_SRC_ID_DUMP) {
switch ( type ) { switch (type) {
case VERB_SUCCESS: PBD::info << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc); break; case VERB_SUCCESS:
case VERB_ERROR: PBD::error << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc); break; PBD::info << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc);
case VERB_WARNING: PBD::warning << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc); break; break;
case VERB_ERROR:
PBD::error << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc);
break;
case VERB_WARNING:
PBD::warning << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc);
break;
// case VERB_DEBUG: PBD::debug << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc); break; // case VERB_DEBUG: PBD::debug << string_compose ("[libaaf] %1:%2 in %3(): ", srcfile, lineno, srcfunc); break;
} }
} }
if ( libid != LOG_SRC_ID_DUMP ) { if (libid != LOG_SRC_ID_DUMP) {
eol = "\n"; eol = "\n";
} }
switch ( type ) { switch (type) {
case VERB_SUCCESS: PBD::info << msg << eol; break; case VERB_SUCCESS:
case VERB_ERROR: PBD::error << msg << eol; break; PBD::info << msg << eol;
case VERB_WARNING: PBD::warning << msg << eol; break; break;
case VERB_ERROR:
PBD::error << msg << eol;
break;
case VERB_WARNING:
PBD::warning << msg << eol;
break;
// case VERB_DEBUG: PBD::debug << msg << eol; break; // case VERB_DEBUG: PBD::debug << msg << eol; break;
} }
@ -121,8 +133,15 @@ prepare_audio_track (aafiAudioTrack* aafTrack, Session* s)
} }
static bool static bool
import_sndfile_as_region (Session* s, struct aafiAudioEssencePointer* aafAudioEssencePtrList, SrcQuality quality, timepos_t& pos, SourceList& sources, ImportStatus& status, vector<std::shared_ptr<Region>>& regions) import_sndfile_as_region (Session* s, struct aafiAudioEssencePointer* aafAudioEssencePtrList, SrcQuality quality, timepos_t& pos, SourceList** oneClipSources, ImportStatus& status, vector<std::shared_ptr<Region>>& regions)
{ {
SourceList* sources = NULL;
if (aafAudioEssencePtrList->user) {
sources = (SourceList*)aafAudioEssencePtrList->user;
} else {
sources = new SourceList;
/* Import the source */ /* Import the source */
status.clear (); status.clear ();
@ -138,9 +157,10 @@ import_sndfile_as_region (Session* s, struct aafiAudioEssencePointer* aafAudioEs
int channelCount = 0; int channelCount = 0;
aafiAudioEssencePointer *aafAudioEssencePtr = NULL; aafiAudioEssencePointer* aafAudioEssencePtr = NULL;
AAFI_foreachEssencePointer (aafAudioEssencePtrList, aafAudioEssencePtr) { AAFI_foreachEssencePointer (aafAudioEssencePtrList, aafAudioEssencePtr)
if ( aafAudioEssencePtr->essenceFile->usable_file_path ) {
if (aafAudioEssencePtr->essenceFile->usable_file_path)
status.paths.push_back (aafAudioEssencePtr->essenceFile->usable_file_path); status.paths.push_back (aafAudioEssencePtr->essenceFile->usable_file_path);
else else
status.paths.push_back (aafAudioEssencePtr->essenceFile->original_file_path); status.paths.push_back (aafAudioEssencePtr->essenceFile->original_file_path);
@ -152,7 +172,7 @@ import_sndfile_as_region (Session* s, struct aafiAudioEssencePointer* aafAudioEs
s->import_files (status); s->import_files (status);
status.progress = 1.0; 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.
@ -168,37 +188,41 @@ import_sndfile_as_region (Session* s, struct aafiAudioEssencePointer* aafAudioEs
} }
for (int i = 0; i < channelCount; i++) { for (int i = 0; i < channelCount; i++) {
sources.push_back (status.sources.at (i)); sources->push_back (status.sources.at (i));
} }
/* build peakfiles */ /* build peakfiles */
for (SourceList::iterator x = sources.begin (); x != sources.end (); ++x) { for (SourceList::iterator x = sources->begin (); x != sources->end (); ++x) {
SourceFactory::setup_peakfile (*x, true); SourceFactory::setup_peakfile (*x, true);
} }
aafAudioEssencePtrList->user = sources;
}
*oneClipSources = sources;
/* Put the source on a region */ /* Put the source on a region */
std::shared_ptr<Region> region; std::shared_ptr<Region> region;
string region_name; string region_name;
/* take all the sources we have and package them up as a region */ /* take all the sources we have and package them up as a region */
region_name = region_name_from_path (status.paths.front (), (sources.size () > 1), false); region_name = region_name_from_path (status.paths.front (), (sources->size () > 1), false);
/* we checked in import_sndfiles() that there were not too many */ /* we checked in import_sndfiles() that there were not too many */
while (RegionFactory::region_by_name (region_name)) { while (RegionFactory::region_by_name (region_name)) {
region_name = bump_name_once (region_name, '.'); region_name = bump_name_once (region_name, '.');
} }
PropertyList proplist; PropertyList proplist;
proplist.add (ARDOUR::Properties::start, 0); proplist.add (ARDOUR::Properties::start, 0);
proplist.add (ARDOUR::Properties::length, timecnt_t (sources[0]->length (), pos)); proplist.add (ARDOUR::Properties::length, timecnt_t ((*sources)[0]->length (), pos));
proplist.add (ARDOUR::Properties::name, aafAudioEssencePtrList->essenceFile->unique_name); proplist.add (ARDOUR::Properties::name, aafAudioEssencePtrList->essenceFile->unique_name);
proplist.add (ARDOUR::Properties::layer, 0); proplist.add (ARDOUR::Properties::layer, 0);
proplist.add (ARDOUR::Properties::whole_file, true); proplist.add (ARDOUR::Properties::whole_file, true);
proplist.add (ARDOUR::Properties::external, true); proplist.add (ARDOUR::Properties::external, true);
region = RegionFactory::create (sources, proplist); region = RegionFactory::create (*sources, proplist);
regions.push_back (region); regions.push_back (region);
return true; return true;
} }
@ -302,14 +326,14 @@ set_region_fade (aafiAudioClip* aafAudioClip, std::shared_ptr<Region> region, aa
samplecnt_t fade_len; samplecnt_t fade_len;
if (fadein != NULL) { if (fadein != NULL) {
fade_shape = aaf_fade_interpol_to_ardour_fade_shape ((aafiInterpolation_e) (fadein->flags & AAFI_INTERPOL_MASK)); fade_shape = aaf_fade_interpol_to_ardour_fade_shape ((aafiInterpolation_e)(fadein->flags & AAFI_INTERPOL_MASK));
fade_len = aafi_convertUnit (fadein->len, aafAudioClip->track->edit_rate, samplerate); fade_len = aafi_convertUnit (fadein->len, aafAudioClip->track->edit_rate, samplerate);
std::dynamic_pointer_cast<AudioRegion> (region)->set_fade_in (fade_shape, fade_len); std::dynamic_pointer_cast<AudioRegion> (region)->set_fade_in (fade_shape, fade_len);
} }
if (fadeout != NULL) { if (fadeout != NULL) {
fade_shape = aaf_fade_interpol_to_ardour_fade_shape ((aafiInterpolation_e) (fadeout->flags & AAFI_INTERPOL_MASK)); fade_shape = aaf_fade_interpol_to_ardour_fade_shape ((aafiInterpolation_e)(fadeout->flags & AAFI_INTERPOL_MASK));
fade_len = aafi_convertUnit (fadeout->len, aafAudioClip->track->edit_rate, samplerate); fade_len = aafi_convertUnit (fadeout->len, aafAudioClip->track->edit_rate, samplerate);
std::dynamic_pointer_cast<AudioRegion> (region)->set_fade_out (fade_shape, fade_len); std::dynamic_pointer_cast<AudioRegion> (region)->set_fade_out (fade_shape, fade_len);
@ -437,7 +461,6 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
aafi_set_debug (aafi, VERB_DEBUG, 0, NULL, &aaf_debug_callback, this); aafi_set_debug (aafi, VERB_DEBUG, 0, NULL, &aaf_debug_callback, this);
if (aafi_load_file (aafi, aaf.c_str ())) { if (aafi_load_file (aafi, aaf.c_str ())) {
error << "AAF: Could not load AAF file." << endmsg; error << "AAF: Could not load AAF file." << endmsg;
aafi_release (&aafi); aafi_release (&aafi);
@ -446,7 +469,7 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
/* extract or set session name */ /* extract or set session name */
if (aafi->compositionName && aafi->compositionName[0] != 0x00) { if (aafi->compositionName && aafi->compositionName[0] != 0x00) {
string compositionName = string(aafi->compositionName); string compositionName = string (aafi->compositionName);
snapshot = laaf_util_clean_filename (&compositionName[0]); snapshot = laaf_util_clean_filename (&compositionName[0]);
} else { } else {
snapshot = basename_nosuffix (aaf); snapshot = basename_nosuffix (aaf);
@ -456,7 +479,7 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
path = Glib::build_filename (target_dir, snapshot); path = Glib::build_filename (target_dir, snapshot);
if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) { if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
error << string_compose (_("AAF: Destination '%1' already exists."), path) << endmsg; error << string_compose (_ ("AAF: Destination '%1' already exists."), path) << endmsg;
snapshot = ""; // XXX? snapshot = ""; // XXX?
path = ""; path = "";
aafi_release (&aafi); aafi_release (&aafi);
@ -468,7 +491,7 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
char* td = g_dir_make_tmp ("aaf-cache-XXXXXX", &err); char* td = g_dir_make_tmp ("aaf-cache-XXXXXX", &err);
if (!td) { if (!td) {
error << string_compose (_("AAF: Could not prepare media cache: %1"), err->message) << endmsg; error << string_compose (_ ("AAF: Could not prepare media cache: %1"), err->message) << endmsg;
aafi_release (&aafi); aafi_release (&aafi);
return -1; return -1;
} }
@ -487,16 +510,16 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
samplerate_r.denominator = 1; samplerate_r.denominator = 1;
std::string restore_backend; std::string restore_backend;
if (!AudioEngine::instance()->running ()) { if (!AudioEngine::instance ()->running ()) {
AudioEngine* e = AudioEngine::instance(); AudioEngine* e = AudioEngine::instance ();
restore_backend = e->current_backend_name (); restore_backend = e->current_backend_name ();
e->set_backend ("None (Dummy)", "", ""); e->set_backend ("None (Dummy)", "", "");
e->start (); e->start ();
PluginManager::instance ().refresh (true); PluginManager::instance ().refresh (true);
attach_to_engine (); attach_to_engine ();
} }
if (!AudioEngine::instance()->running ()) { if (!AudioEngine::instance ()->running ()) {
PBD::error << _("AAF: Could not start [dummy] engine for AAF import .") << endmsg; PBD::error << _ ("AAF: Could not start [dummy] engine for AAF import .") << endmsg;
return -1; return -1;
} }
@ -506,10 +529,10 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
aafi_release (&aafi); aafi_release (&aafi);
PBD::remove_directory (media_cache_path); PBD::remove_directory (media_cache_path);
if (!restore_backend.empty ()) { if (!restore_backend.empty ()) {
AudioEngine::instance()->stop (); AudioEngine::instance ()->stop ();
AudioEngine::instance()->set_backend (restore_backend, "", ""); AudioEngine::instance ()->set_backend (restore_backend, "", "");
} }
error << _("AAF: Could not create new session for AAF import .") << endmsg; error << _ ("AAF: Could not create new session for AAF import .") << endmsg;
return -1; return -1;
} }
@ -547,7 +570,7 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
/* Import Sources */ /* Import Sources */
SourceList oneClipSources; SourceList* oneClipSources;
ARDOUR::ImportStatus import_status; ARDOUR::ImportStatus import_status;
vector<std::shared_ptr<Region>> source_regions; vector<std::shared_ptr<Region>> source_regions;
timepos_t pos = timepos_t::max (Temporal::AudioTime); timepos_t pos = timepos_t::max (Temporal::AudioTime);
@ -555,7 +578,7 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
aafiAudioTrack* aafAudioTrack = NULL; aafiAudioTrack* aafAudioTrack = NULL;
aafiTimelineItem* aafAudioItem = NULL; aafiTimelineItem* aafAudioItem = NULL;
aafiAudioClip* aafAudioClip = NULL; aafiAudioClip* aafAudioClip = NULL;
aafiAudioEssencePointer *aafAudioEssencePtr = NULL; aafiAudioEssencePointer* aafAudioEssencePtr = NULL;
aafPosition_t sessionStart = aafi_convertUnit (aafi->compositionStart, aafi->compositionStart_editRate, &samplerate_r); aafPosition_t sessionStart = aafi_convertUnit (aafi->compositionStart, aafi->compositionStart_editRate, &samplerate_r);
@ -572,19 +595,19 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
} }
if (aafAudioClip->essencePointerList == NULL) { if (aafAudioClip->essencePointerList == NULL) {
error << _("AAF: Clip has no essence.") << endmsg; error << _ ("AAF: Clip has no essence.") << endmsg;
continue; continue;
} }
int essenceError = 0; int essenceError = 0;
char *essenceName = aafAudioClip->essencePointerList->essenceFile->name; char* essenceName = aafAudioClip->essencePointerList->essenceFile->name;
AAFI_foreachEssencePointer (aafAudioClip->essencePointerList, aafAudioEssencePtr) {
AAFI_foreachEssencePointer (aafAudioClip->essencePointerList, aafAudioEssencePtr)
{
struct aafiAudioEssenceFile* audioEssenceFile = aafAudioEssencePtr->essenceFile; struct aafiAudioEssenceFile* audioEssenceFile = aafAudioEssencePtr->essenceFile;
if (!audioEssenceFile) { if (!audioEssenceFile) {
PBD::error << string_compose (_("AAF: Could not create new region for clip '%1': Missing audio essence"), audioEssenceFile->unique_name) << endmsg; PBD::error << string_compose (_ ("AAF: Could not create new region for clip '%1': Missing audio essence"), audioEssenceFile->unique_name) << endmsg;
essenceError++; essenceError++;
continue; continue;
} }
@ -607,27 +630,27 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
continue; continue;
} }
if (!import_sndfile_as_region (_session, aafAudioClip->essencePointerList, SrcBest, pos, oneClipSources, import_status, source_regions)) { if (!import_sndfile_as_region (_session, aafAudioClip->essencePointerList, SrcBest, pos, &oneClipSources, import_status, source_regions)) {
PBD::error << string_compose ("AAF: Could not import '%1' to session.", essenceName) << endmsg; PBD::error << string_compose ("AAF: Could not import '%1' to session.", essenceName) << endmsg;
continue; continue;
} } else {
else { AAFI_foreachEssencePointer (aafAudioClip->essencePointerList, aafAudioEssencePtr)
AAFI_foreachEssencePointer (aafAudioClip->essencePointerList, aafAudioEssencePtr) { {
if (aafAudioEssencePtr->essenceFile->is_embedded) { if (aafAudioEssencePtr->essenceFile->is_embedded) {
g_unlink (aafAudioEssencePtr->essenceFile->usable_file_path); g_unlink (aafAudioEssencePtr->essenceFile->usable_file_path);
} }
} }
} }
if (oneClipSources.size () == 0) { if (!oneClipSources || oneClipSources->size () == 0) {
error << string_compose (_("AAF: Could not create new region for clip '%1': Region has no source"), essenceName) << endmsg; error << string_compose (_ ("AAF: Could not create new region for clip '%1': Region has no source"), essenceName) << endmsg;
continue; continue;
} }
std::shared_ptr<Region> region = create_region (source_regions, aafAudioClip, oneClipSources, sessionStart, samplerate_r); std::shared_ptr<Region> region = create_region (source_regions, aafAudioClip, *oneClipSources, sessionStart, samplerate_r);
if (!region) { if (!region) {
error << string_compose (_("AAF: Could not create new region for clip '%1'"), essenceName) << endmsg; error << string_compose (_ ("AAF: Could not create new region for clip '%1'"), essenceName) << endmsg;
continue; continue;
} }
@ -643,11 +666,12 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
} }
} }
oneClipSources.clear (); // oneClipSources.clear ();
aafiMarker* marker = NULL; aafiMarker* marker = NULL;
AAFI_foreachMarker (aafi, marker) { AAFI_foreachMarker (aafi, marker)
{
aafPosition_t markerStart = sessionStart + aafi_convertUnit (marker->start, marker->edit_rate, &samplerate_r); aafPosition_t markerStart = sessionStart + aafi_convertUnit (marker->start, marker->edit_rate, &samplerate_r);
aafPosition_t markerEnd = sessionStart + aafi_convertUnit ((marker->start + marker->length), marker->edit_rate, &samplerate_r); aafPosition_t markerEnd = sessionStart + aafi_convertUnit ((marker->start + marker->length), marker->edit_rate, &samplerate_r);
@ -691,8 +715,8 @@ ARDOUR_UI::new_session_from_aaf (string const& aaf, string const& target_dir, st
aafi_release (&aafi); aafi_release (&aafi);
if (!restore_backend.empty ()) { if (!restore_backend.empty ()) {
AudioEngine::instance()->stop (); AudioEngine::instance ()->stop ();
AudioEngine::instance()->set_backend (restore_backend, "", ""); AudioEngine::instance ()->set_backend (restore_backend, "", "");
} }
return 0; return 0;
} }