20 #include <sys/types.h>
45 #include "ardour/utils.h"
77 MessageDialog msg (
_(
"You can't import or embed an audiofile until you have a session loaded."));
85 sfbrowser->set_mode (mode_hint);
88 external_audio_dialog ();
95 uint32_t audio_track_cnt;
96 uint32_t midi_track_cnt;
99 MessageDialog msg (
_(
"You can't import or embed an audiofile until you have a session loaded."));
107 for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) {
126 if (sfbrowser == 0) {
129 sfbrowser->reset (audio_track_cnt, midi_track_cnt);
132 sfbrowser->show_all ();
142 typedef std::map<PBD::ID,boost::shared_ptr<ARDOUR::Source> >
SourceMap;
159 string wave_name (Glib::path_get_basename(path));
161 bool already_exists =
false;
165 already_exists =
true;
170 if (already_exists) {
172 if (all_or_nothing) {
175 message =
string_compose (
_(
"The session already contains a source file named %1. Do you want to import %1 as a new file, or skip it?"), wave_name);
177 message =
string_compose (
_(
"The session already contains a source file named %1. Do you want to import %2 as a new source, or skip it?"), wave_name, wave_name);
180 MessageDialog dialog(message,
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE,
true);
182 if (all_or_nothing) {
185 dialog.add_button(
"Import", 1);
186 dialog.add_button(
"Skip", 2);
188 dialog.add_button(
"Import", 1);
189 dialog.add_button(
"Cancel", 2);
196 function = dialog.run ();
208 TrackSelection::iterator x;
210 for (x = selection->tracks.begin(); nth > 0 && x != selection->tracks.end(); ++x) {
221 if (x == selection->tracks.end()) {
238 TrackSelection::iterator x;
240 for (x = selection->tracks.begin(); nth > 0 && x != selection->tracks.end(); ++x) {
251 if (x == selection->tracks.end()) {
273 vector<string> to_import;
275 bool use_timestamp = (pos == -1);
277 current_interthread_info = &import_status;
278 import_status.current = 1;
279 import_status.total = paths.size ();
280 import_status.all_done =
false;
286 if (disposition == Editing::ImportMergeFiles) {
293 for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
294 int check = check_whether_and_how_to_import(*a,
false);
305 ok = (import_sndfiles (paths, disposition, mode, quality, pos, 1, 1, track,
false, instrument) == 0);
310 bool replace =
false;
312 for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
314 const int check = check_whether_and_how_to_import (*a,
true);
321 fatal <<
"Updating existing sources should be disabled!" <<
endmsg;
328 fatal <<
"Illegal return " << check <<
" from check_whether_and_how_to_import()!" <<
endmsg;
340 switch (disposition) {
341 case Editing::ImportDistinctFiles:
344 to_import.push_back (*a);
346 if (mode == Editing::ImportToTrack) {
347 track = get_nth_selected_audio_track (nth++);
350 ok = (import_sndfiles (to_import, disposition, mode, quality, pos, 1, -1, track, replace, instrument) == 0);
353 case Editing::ImportDistinctChannels:
356 to_import.push_back (*a);
358 ok = (import_sndfiles (to_import, disposition, mode, quality, pos, -1, -1, track, replace, instrument) == 0);
361 case Editing::ImportSerializeFiles:
364 to_import.push_back (*a);
366 ok = (import_sndfiles (to_import, disposition, mode, quality, pos, 1, 1, track, replace, instrument) == 0);
369 case Editing::ImportMergeFiles:
380 import_status.all_done =
true;
387 bool check_sample_rate =
true;
389 vector<string> to_embed;
390 bool multi = paths.size() > 1;
392 bool use_timestamp = (pos == -1);
395 case Editing::ImportDistinctFiles:
396 for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
404 to_embed.push_back (*a);
406 if (mode == Editing::ImportToTrack) {
407 track = get_nth_selected_audio_track (nth++);
410 if (embed_sndfiles (to_embed, multi, check_sample_rate, import_as, mode, pos, 1, -1, track, instrument) < -1) {
416 case Editing::ImportDistinctChannels:
417 for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
425 to_embed.push_back (*a);
427 if (embed_sndfiles (to_embed, multi, check_sample_rate, import_as, mode, pos, -1, -1, track, instrument) < -1) {
433 case Editing::ImportMergeFiles:
434 if (embed_sndfiles (paths, multi, check_sample_rate, import_as, mode, pos, 1, 1, track, instrument) < -1) {
439 case Editing::ImportSerializeFiles:
440 for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
448 to_embed.push_back (*a);
450 if (embed_sndfiles (to_embed, multi, check_sample_rate, import_as, mode, pos, 1, 1, track, instrument) < -1) {
477 import_status.paths = paths;
478 import_status.done =
false;
479 import_status.cancel =
false;
480 import_status.freeze =
false;
481 import_status.quality = quality;
482 import_status.replace_existing_source = replace;
484 import_status.mode = mode;
485 import_status.pos = pos;
486 import_status.target_tracks = target_tracks;
487 import_status.target_regions = target_regions;
488 import_status.track = track;
489 import_status.replace = replace;
500 pthread_detach (import_status.thread);
502 while (!import_status.done && !import_status.cancel) {
503 gtk_main_iteration ();
506 import_status.done =
true;
510 if (!import_status.cancel && !import_status.sources.empty()) {
511 result = add_sources (
513 import_status.sources,
517 import_status.target_regions,
518 import_status.target_tracks,
519 track,
false, instrument
524 pos = import_status.pos;
527 import_status.sources.clear();
534 bool& check_sample_rate,
551 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
558 if (!AudioFileSource::get_soundfile_info (path, finfo, error_msg)) {
564 vector<string> choices;
567 choices.push_back (
_(
"Cancel entire import"));
568 choices.push_back (
_(
"Don't embed it"));
569 choices.push_back (
_(
"Embed all without questions"));
573 string_compose (
_(
"%1\nThis audiofile's sample rate doesn't match the session sample rate!"),
578 int resx = rate_choice.run ();
586 check_sample_rate =
false;
594 choices.push_back (
_(
"Cancel"));
595 choices.push_back (
_(
"Embed it anyway"));
599 string_compose (
_(
"%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
603 int resx = rate_choice.run ();
616 for (
int n = 0; n < finfo.
channels; ++n) {
627 SourceFactory::createExternal (DataType::AUDIO, *
_session,
629 (mode == ImportAsTapeTrack
637 sources.push_back(source);
645 gtk_main_iteration();
649 if (!sources.empty()) {
650 return add_sources (paths, sources, pos, disposition, mode, target_regions, target_tracks, track,
true, instrument);
668 vector<boost::shared_ptr<Region> >
regions;
670 uint32_t input_chan = 0;
671 uint32_t output_chan = 0;
673 vector<string> track_names;
675 use_timestamp = (pos == -1);
678 if (SMFSource::safe_midi_file_extension (paths.front())) {
682 if (target_regions == 1) {
690 while (RegionFactory::region_by_name (region_name)) {
705 if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) {
709 regions.push_back (r);
715 track_names.push_back (region_name);
717 }
else if (target_regions == -1 || target_regions > 1) {
722 SourceList::iterator x;
725 for (n = 0, x = sources.begin(); x != sources.end(); ++x, ++n) {
728 just_one.push_back (*x);
732 if (sources.size() > 1 && disposition == ImportDistinctChannels) {
743 region_name = (*x)->name();
746 if (sources.size() == 2) {
752 }
else if (sources.size() > 2) {
756 track_names.push_back (region_name);
762 region_name = (*x)->name();
765 if (SMFSource::safe_midi_file_extension (paths.front())) {
767 track_names.push_back (track_name);
794 if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) {
798 regions.push_back (r);
802 if (target_regions == 1) {
805 if (target_tracks == 1) {
806 input_chan = regions.size();
815 output_chan = input_chan;
827 assert (regions.size() == track_names.size());
844 }
else if (target_tracks == 1) {
848 pos = get_preferred_edit_position ();
853 pos = get_preferred_edit_position ();
857 pos = get_preferred_edit_position ();
861 finish_bringing_in_material (*r, input_chan, output_chan, pos, mode, track, track_names[n], instrument);
863 rlen = (*r)->length();
865 if (target_tracks != 1) {
868 if (!use_timestamp || !ar) {
870 pos += (*r)->length();
875 commit_reversible_command ();
879 for (SourceList::iterator x = sources.begin(); x != sources.end(); ++x) {
880 SourceFactory::setup_peakfile (*x,
true);
893 const string& new_track_name,
906 if (!existing_track) {
909 existing_track = get_nth_selected_audio_track (0);
911 existing_track = get_nth_selected_midi_track (0);
914 if (!existing_track) {
932 if (!existing_track) {
940 existing_track = at.front();
942 list<boost::shared_ptr<MidiTrack> > mt (
952 existing_track = mt.front();
955 if (!new_track_name.empty()) {
956 existing_track->
set_name (new_track_name);
970 case ImportAsTapeTrack:
994 SessionEvent::create_per_thread_pool (
"import events", 64);
void do_import(std::vector< std::string > paths, Editing::ImportDisposition disposition, Editing::ImportMode mode, ARDOUR::SrcQuality quality, framepos_t &pos, boost::shared_ptr< ARDOUR::PluginInfo > instrument=boost::shared_ptr< ARDOUR::PluginInfo >())
LIBPBD_API Transmitter fatal
void ripple(framepos_t at, framecnt_t distance, RegionList *exclude)
std::map< PBD::ID, boost::shared_ptr< ARDOUR::Source > > SourceMap
boost::shared_ptr< ARDOUR::MidiTrack > midi_track() const
bool is_midi_track() const
LIBARDOUR_API PBD::PropertyDescriptor< layer_t > layer
bool is_audio_track() const
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
LIBARDOUR_API PBD::PropertyDescriptor< std::string > name
int embed_sndfiles(std::vector< std::string > paths, bool multiple_files, bool &check_sample_rate, Editing::ImportDisposition disposition, Editing::ImportMode mode, framepos_t &pos, int target_regions, int target_tracks, boost::shared_ptr< ARDOUR::Track > &track, boost::shared_ptr< ARDOUR::PluginInfo > instrument=boost::shared_ptr< ARDOUR::PluginInfo >())
void add_command(Command *const cmd)
const SourceList & sources() const
LIBPBD_API Transmitter error
int import_sndfiles(std::vector< std::string > paths, Editing::ImportDisposition disposition, Editing::ImportMode mode, ARDOUR::SrcQuality quality, framepos_t &pos, int target_regions, int target_tracks, boost::shared_ptr< ARDOUR::Track > &track, bool replace, boost::shared_ptr< ARDOUR::PluginInfo > instrument=boost::shared_ptr< ARDOUR::PluginInfo >())
std::ostream & endmsg(std::ostream &ostr)
boost::shared_ptr< ARDOUR::MidiTrack > get_nth_selected_midi_track(int nth) const
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
framecnt_t frame_rate() const
static void * _import_thread(void *)
LIBARDOUR_API GQuark insert_file
static Handle create(Editor &editor, Gdk::Cursor *cursor)
boost::shared_ptr< AudioFileSource > audio_source_by_path_and_channel(const std::string &, uint16_t) const
void add_region(boost::shared_ptr< Region >, framepos_t position, float times=1, bool auto_partition=false)
LIBARDOUR_API RCConfiguration * Config
uint32_t count_sources_by_origin(const std::string &)
void session_import_dialog()
boost::shared_ptr< Route > master_out() const
boost::shared_ptr< Playlist > playlist()
void do_embed(std::vector< std::string > paths, Editing::ImportDisposition disposition, Editing::ImportMode mode, framepos_t &pos, boost::shared_ptr< ARDOUR::PluginInfo > instrument=boost::shared_ptr< ARDOUR::PluginInfo >())
LIBARDOUR_API PBD::PropertyDescriptor< bool > external
void add_external_audio_action(Editing::ImportMode)
const OwnedPropertyList & properties() const
ChanCount n_inputs() const
LIBARDOUR_API PBD::PropertyDescriptor< bool > regions
LIBARDOUR_API std::string bump_name_once(const std::string &s, char delimiter)
boost::shared_ptr< ARDOUR::AudioTrack > get_nth_selected_audio_track(int nth) const
LIBPBD_API Glib::ustring basename_nosuffix(Glib::ustring)
const std::string & path() const
int finish_bringing_in_material(boost::shared_ptr< ARDOUR::Region > region, uint32_t in_chans, uint32_t out_chans, framepos_t &pos, Editing::ImportMode mode, boost::shared_ptr< ARDOUR::Track > &existing_track, const std::string &new_track_name, boost::shared_ptr< ARDOUR::PluginInfo > instrument)
uint32_t n_channels() const
std::list< boost::shared_ptr< AudioTrack > > new_audio_track(int input_channels, int output_channels, TrackMode mode=Normal, RouteGroup *route_group=0, uint32_t how_many=1, std::string name_template="")
int add_sources(std::vector< std::string > paths, ARDOUR::SourceList &sources, framepos_t &pos, Editing::ImportDisposition disposition, Editing::ImportMode mode, int target_regions, int target_tracks, boost::shared_ptr< ARDOUR::Track > &track, bool add_channel_suffix, boost::shared_ptr< ARDOUR::PluginInfo > instrument=boost::shared_ptr< ARDOUR::PluginInfo >())
std::list< boost::shared_ptr< MidiTrack > > new_midi_track(const ChanCount &input, const ChanCount &output, boost::shared_ptr< PluginInfo > instrument=boost::shared_ptr< PluginInfo >(), TrackMode mode=Normal, RouteGroup *route_group=0, uint32_t how_many=1, std::string name_template="")
void import_files(ImportStatus &)
LIBPBD_API Glib::ustring short_path(const Glib::ustring &path, Glib::ustring::size_type target_characters)
framecnt_t length() const
int save_state(std::string snapshot_name, bool pending=false, bool switch_to_snapshot=false, bool template_only=false)
bool set_name(const std::string &str)
boost::shared_ptr< ARDOUR::AudioTrack > audio_track() const
int check_whether_and_how_to_import(std::string, bool all_or_nothing=true)
virtual framepos_t natural_position() const
LIBPBD_API int pthread_create_and_store(std::string name, pthread_t *thread, void *(*start_routine)(void *), void *arg)
std::vector< boost::shared_ptr< Source > > SourceList
LIBARDOUR_API std::string region_name_from_path(std::string path, bool strip_channels, bool add_channel_suffix=false, uint32_t total=0, uint32_t this_one=0)
bool add(PropertyBase *prop)
ARDOUR::Session * _session
LIBARDOUR_API PBD::PropertyDescriptor< bool > whole_file
std::string string_compose(const std::string &fmt, const T1 &o1)
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > length
void external_audio_dialog()