diff --git a/session_utils/new_aaf_session.cc b/session_utils/new_aaf_session.cc new file mode 100644 index 0000000000..0d47327a72 --- /dev/null +++ b/session_utils/new_aaf_session.cc @@ -0,0 +1,1306 @@ +/* + * Copyright (C) 2023 Adrien Gesta-Fline + * Based on Robin Gareus session_utils files + * Based on Damien Zammit ptformat + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "ardour/audioengine.h" +#include "ardour/filename_extensions.h" +#include "ardour/session_directory.h" +#include "ardour/template_utils.h" + +#include "ardour/audio_track.h" +#include "ardour/audiofilesource.h" +#include "ardour/audioregion.h" +#include "ardour/import_status.h" +#include "ardour/playlist.h" +#include "ardour/region_factory.h" +#include "ardour/source_factory.h" + +#include "common.h" +#include "pbd/file_utils.h" + +#include "aaf/libaaf.h" +#include "aaf/utils.h" + +using namespace std; +using namespace ARDOUR; +using namespace SessionUtils; +using namespace Timecode; +using namespace PBD; + +#ifndef UTILNAME +#define UTILNAME "new_aaf_session" +#endif + +/* + * TODO: + * - Track level + * - Track pan + * - Track level automation + * - Track pan automation + * x Region level automation + * - Session timecode offset (so the very begining of the timeline starts at eg. 01:00:00:00) + * x Markers + * x Multichannel audio file import (AAFOperationDef_AudioChannelCombiner) + * - Multichannel region from multiple source audio files (1 file per channel) ? + * - Mono region from a specific channel of a multichannel file ? + * x Muted region + * - Video file import + */ + +#define PRINT_I(fmt, ...) \ + { \ + fprintf (stderr, "[\033[1;38;5;81mi\x1B[0m] \x1b[38;5;239m%s : %s() on line %i :\x1B[0m ", __FILE__, __func__, __LINE__); \ + fprintf (stderr, fmt, ##__VA_ARGS__); \ + } +#define PRINT_W(fmt, ...) \ + { \ + fprintf (stderr, "[\x1B[33mw\x1B[0m] \x1b[38;5;239m%s : %s() on line %i :\x1B[0m ", __FILE__, __func__, __LINE__); \ + fprintf (stderr, fmt, ##__VA_ARGS__); \ + } +#define PRINT_E(fmt, ...) \ + { \ + fprintf (stderr, "[\x1B[31me\x1B[0m] \x1b[38;5;239m%s : %s() on line %i :\x1B[0m ", __FILE__, __func__, __LINE__); \ + fprintf (stderr, fmt, ##__VA_ARGS__); \ + } + +static void +usage (); +static void +list_templates (); +static std::string +template_path_from_name (std::string const& name); +static Session* +create_new_session (string const& dir, string const& state, float samplerate, ARDOUR::SampleFormat bitdepth, int master_bus_chn, string const& template_path); +// static void set_session_video_from_aaf( Session *s, AAF_Iface *aafi ); +static std::shared_ptr +get_nth_audio_track (uint32_t nth, std::shared_ptr routes); +static bool +import_sndfile_as_region (Session* s, struct aafiAudioEssence* audioEssence, SrcQuality quality, timepos_t& pos, SourceList& sources, ImportStatus& status, vector>* regions /* boost::shared_ptr r*/); +static void +set_session_range (Session* s, AAF_Iface* aafi); +static std::shared_ptr +create_region (vector> source_regions, aafiAudioClip* aafAudioClip, SourceList& oneClipSources, aafPosition_t clipOffset, aafRational_t samplerate_r); +static void +set_region_gain (aafiAudioClip* aafAudioClip, std::shared_ptr region, Session* s); +static std::shared_ptr +prepare_audio_track (aafiAudioTrack* aafTrack, Session* s); +static void +set_region_fade (aafiAudioClip* aafAudioClip, std::shared_ptr region, aafRational_t* samplerate); +static void +set_session_timecode (Session* s, AAF_Iface* aafi); + +static void +usage () +{ + // help2man compatible format (standard GNU help-text) + printf (UTILNAME " - create a new session based on an AAF file from the commandline.\n\n"); + printf ("Usage: " UTILNAME " [ OPTIONS ] -p --aaf \n\n"); + printf ("Options:\n\n\ + -h, --help Display this help and exit.\n\ + -L, --list-templates List available Ardour templates and exit.\n\ +\n\ + -m, --master-channels Master-bus channel count (default 2).\n\ + -r, --sample-rate Sample rate of the new Ardour session (default is AAF).\n\ + -s, --sample-size <16|24|32> Audio bit depth of the new Ardour session (default is AAF).\n\ +\n\ + -t, --template