diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2016-12-16 16:49:52 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-12-16 16:49:52 +0000 |
commit | cd64f17a9c5442befd32fc52317a44e4ed288b82 (patch) | |
tree | 40a69f654af6a4d5700459a522e9e976328bfde6 /gtk2_ardour/editor_audio_import.cc | |
parent | 73f8ffce6340d854334925c9b5b466f3fb8f9a04 (diff) |
initial attempt at importing SMF tempo maps during MIDI import.
Still with debug output
Diffstat (limited to 'gtk2_ardour/editor_audio_import.cc')
-rw-r--r-- | gtk2_ardour/editor_audio_import.cc | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index bec9946c2d..8e2e476d15 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -262,6 +262,48 @@ Editor::get_nth_selected_midi_track (int nth) const } void +Editor::import_smf_tempo_map (Evoral::SMF const & smf) +{ + if (!_session) { + return; + } + + const size_t num_tempos = smf.num_tempos (); + + if (num_tempos == 0) { + return; + } + + const framecnt_t sample_rate = _session->frame_rate (); + TempoMap new_map (sample_rate); + bool have_meter = false; + + for (size_t n = 0; n < num_tempos; ++n) { + + Evoral::SMF::Tempo* t = smf.nth_tempo (n); + assert (t); + + Tempo tempo (60 * (1000000 / t->microseconds_per_quarter_note), 4.0); + new_map.add_tempo (tempo, (t->time_pulses/smf.ppqn()) / 4.0, 0, TempoSection::Constant, MusicTime); + + Meter meter (t->numerator, t->denominator); + Timecode::BBT_Time bbt; /* 1|1|0 which is correct for the no-meter case */ + if (have_meter) { + bbt = new_map.bbt_at_beat ((t->time_pulses/smf.ppqn())); + } + new_map.add_meter (meter, t->time_pulses, bbt, MusicTime); + + cerr << "@ " << t->time_pulses/smf.ppqn() << " (" + << t->time_seconds << ") Add T " << tempo << " M " << meter << endl; + } + + cerr << "NEW MAP:\n"; + new_map.dump (cerr); + + _session->tempo_map() = new_map; +} + +void Editor::do_import (vector<string> paths, ImportDisposition disposition, ImportMode mode, @@ -276,6 +318,25 @@ Editor::do_import (vector<string> paths, int nth = 0; bool use_timestamp = (pos == -1); + if (smf_tempo_disposition == SMFTempoUse) { + /* Find the first MIDI file with a tempo map, and import it + before we do anything else. + */ + + for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) { + Evoral::SMF smf; + if (smf.open (*a)) { + continue; + } + if (smf.num_tempos() > 0) { + import_smf_tempo_map (smf); + smf.close (); + break; + } + smf.close (); + } + } + current_interthread_info = &import_status; import_status.current = 1; import_status.total = paths.size (); @@ -714,7 +775,7 @@ Editor::add_sources (vector<string> paths, if (use_timestamp && boost::dynamic_pointer_cast<AudioRegion>(r)) { boost::dynamic_pointer_cast<AudioRegion>(r)->special_set_position(sources[0]->natural_position()); - } + } regions.push_back (r); |