Support fancy controls for some AU units.
[ardour.git] / libs / ardour / import.cc
index 1303c85511bf9bb93aebab7a63f1787e0925f9e2..2b3f1058792b60b8fcb18fe41851cfcf40cf59d6 100644 (file)
@@ -234,6 +234,9 @@ write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status,
        const framecnt_t nframes = ResampledImportableSource::blocksize;
        boost::shared_ptr<AudioFileSource> afs;
        uint32_t channels = source->channels();
+       if (channels == 0) {
+               return;
+       }
 
        boost::scoped_array<float> data(new float[nframes * channels]);
        vector<boost::shared_array<Sample> > channel_data;
@@ -351,7 +354,9 @@ write_midi_data_to_new_files (Evoral::SMF* source, ImportStatus& status,
 
                        boost::shared_ptr<SMFSource> smfs = boost::dynamic_pointer_cast<SMFSource> (*s);
 
-                       smfs->drop_model ();
+                       Glib::Threads::Mutex::Lock source_lock(smfs->mutex());
+
+                       smfs->drop_model (source_lock);
                        source->seek_to_track (i);
 
                        uint64_t t       = 0;
@@ -381,15 +386,17 @@ write_midi_data_to_new_files (Evoral::SMF* source, ImportStatus& status,
                                }
 
                                if (first) {
-                                       smfs->mark_streaming_write_started ();
+                                       smfs->mark_streaming_write_started (source_lock);
                                        first = false;
                                }
 
-                               smfs->append_event_unlocked_beats(
-                                       Evoral::Event<double>(0,
-                                                             (double)t / (double)source->ppqn(),
-                                                             size,
-                                                             buf));
+                               smfs->append_event_beats(
+                                       source_lock,
+                                       Evoral::Event<Evoral::MusicalTime>(
+                                               0,
+                                               Evoral::MusicalTime::ticks_at_rate(t, source->ppqn()),
+                                               size,
+                                               buf));
 
                                if (status.progress < 0.99) {
                                        status.progress += 0.01;
@@ -400,11 +407,11 @@ write_midi_data_to_new_files (Evoral::SMF* source, ImportStatus& status,
 
                                /* we wrote something */
 
-                               const framepos_t pos = 0;
-                               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->mark_streaming_write_completed ();
+                               const framepos_t          pos = 0;
+                               const Evoral::MusicalTime length_beats = Evoral::MusicalTime::ticks_at_rate(t, source->ppqn());
+                               BeatsFramesConverter      converter(smfs->session().tempo_map(), pos);
+                               smfs->update_length(pos + converter.to(length_beats.round_up_to_beat()));
+                               smfs->mark_streaming_write_completed (source_lock);
 
                                if (status.cancel) {
                                        break;