#include "ardour/tempo.h"
#ifdef HAVE_COREAUDIO
-#ifdef USE_COREAUDIO_FOR_FILE_IO
#include "ardour/caimportable.h"
#endif
-#endif
#include "i18n.h"
static boost::shared_ptr<ImportableSource>
open_importable_source (const string& path, nframes_t samplerate, ARDOUR::SrcQuality quality)
{
-#ifdef HAVE_COREAUDIO
-#ifdef USE_COREAUDIO_FOR_FILE_IO
-
- /* see if we can use CoreAudio to handle the IO */
-
- try {
- CAImportableSource* src = new CAImportableSource(path);
- boost::shared_ptr<CAImportableSource> source (src);
-
+ /* try libsndfile first, because it can get BWF info from .wav, which ExtAudioFile cannot.
+ We don't necessarily need that information in an ImportableSource, but it keeps the
+ logic the same as in SourceFactory::create()
+ */
+
+ try {
+ boost::shared_ptr<SndFileImportableSource> source(new SndFileImportableSource(path));
+
if (source->samplerate() == samplerate) {
return source;
}
-
+
/* rewrap as a resampled source */
-
+
return boost::shared_ptr<ImportableSource>(new ResampledImportableSource(source, samplerate, quality));
}
catch (...) {
- /* fall back to SndFile */
-#endif
-#endif
-
- try {
- boost::shared_ptr<SndFileImportableSource> source(new SndFileImportableSource(path));
-
- if (source->samplerate() == samplerate) {
- return source;
- }
-
- /* rewrap as a resampled source */
+#ifdef HAVE_COREAUDIO
- return boost::shared_ptr<ImportableSource>(new ResampledImportableSource(source, samplerate, quality));
+ /* libsndfile failed, see if we can use CoreAudio to handle the IO */
+
+ CAImportableSource* src = new CAImportableSource(path);
+ boost::shared_ptr<CAImportableSource> source (src);
+
+ if (source->samplerate() == samplerate) {
+ return source;
}
+
+ /* rewrap as a resampled source */
+
+ return boost::shared_ptr<ImportableSource>(new ResampledImportableSource(source, samplerate, quality));
- catch (...) {
- throw; // rethrow
- }
+#else
+ throw; // rethrow
+#endif
-#ifdef HAVE_COREAUDIO
-#ifdef USE_COREAUDIO_FOR_FILE_IO
}
-#endif
-#endif
}
static std::string
static bool
create_mono_sources_for_writing (const vector<string>& new_paths, Session& sess,
uint samplerate, vector<boost::shared_ptr<Source> >& newfiles,
- nframes64_t /*timeline_position*/)
+ framepos_t timeline_position)
{
for (vector<string>::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i)
{
}
newfiles.push_back(boost::dynamic_pointer_cast<Source>(source));
+
+ /* for audio files, reset the timeline position so that any BWF-ish
+ information in the original files we are importing from is maintained.
+ */
+
+ boost::shared_ptr<AudioFileSource> afs;
+ if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(source)) != 0) {
+ afs->set_timeline_position(timeline_position);
+ }
}
return true;
}
static void
write_midi_data_to_new_files (Evoral::SMF* source, ImportStatus& status,
- vector<boost::shared_ptr<Source> >& newfiles)
+ vector<boost::shared_ptr<Source> >& newfiles)
{
uint32_t buf_size = 4;
uint8_t* buf = (uint8_t*)malloc(buf_size);
uint64_t t = 0;
uint32_t delta_t = 0;
uint32_t size = 0;
+ bool first = true;
while (!status.cancel) {
size = buf_size;
if (ret == 0) { // Meta
continue;
}
+
+ if (first) {
+ smfs->mark_streaming_write_started ();
+ first = false;
+ }
smfs->append_event_unlocked_beats(Evoral::Event<double>(0,
(double)t / (double)source->ppqn(),
const double length_beats = ceil(t / (double)source->ppqn());
BeatsFramesConverter converter(smfs->session().tempo_map(), pos);
smfs->update_length(pos, converter.to(length_beats));
- smfs->end_write();
+ smfs->mark_streaming_write_completed ();
if (status.cancel) {
break;
get_best_session_directory_for_new_source (),
channels);
Sources newfiles;
- nframes64_t natural_position = source ? source->natural_position() : 0;
+ framepos_t natural_position = source ? source->natural_position() : 0;
if (status.replace_existing_source) {
fatal << "THIS IS NOT IMPLEMENTED YET, IT SHOULD NEVER GET CALLED!!! DYING!" << endmsg;
status.cancel = !map_existing_mono_sources (new_paths, *this, frame_rate(), newfiles, this);
} else {
- status.cancel = !create_mono_sources_for_writing (new_paths, *this, frame_rate(), newfiles, natural_position);
+ status.cancel = !create_mono_sources_for_writing (new_paths, *this, frame_rate(), newfiles, natural_position);
}
// copy on cancel/failure so that any files that were created will be removed below
for (Sources::iterator x = all_new_sources.begin(); x != all_new_sources.end(); ) {
if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(*x)) != 0) {
- afs->update_header(0, *now, xnow);
+ afs->update_header((*x)->natural_position(), *now, xnow);
afs->done_with_peakfile_writes ();
/* now that there is data there, requeue the file for analysis */