diff options
author | David Robillard <d@drobilla.net> | 2008-02-21 00:15:20 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-02-21 00:15:20 +0000 |
commit | 0d0bd81a75d23a9d2dd13312f30b7f21138e037a (patch) | |
tree | be0b987aca046bcde33a39b2a12f786d3846b785 | |
parent | 68bfed0a461635e3f5c05651f755dca6e22df5d9 (diff) |
Fix timing on MIDI import.
git-svn-id: svn://localhost/ardour2/branches/3.0@3093 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/sfdb_ui.cc | 5 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_model.h | 4 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_source.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/smf_source.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/types.h | 5 | ||||
-rw-r--r-- | libs/ardour/import.cc | 4 | ||||
-rw-r--r-- | libs/ardour/midi_model.cc | 6 | ||||
-rw-r--r-- | libs/ardour/smf_source.cc | 21 |
8 files changed, 31 insertions, 18 deletions
diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 13d3230437..0104daea7c 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -909,10 +909,7 @@ SoundFileOmega::check_info (const vector<ustring>& paths, bool& same_size, bool& } else if (SMFSource::safe_file_extension (*i)) { SMFReader reader(*i); if (reader.num_tracks() > 1) { - cout << *i << " MULTI CHANNEL" << endl; - multichannel = true; - } else { - cout << *i << " SINGLE CHANNEL" << endl; + multichannel = true; // "channel" == track here... } } else { err = true; diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index 61b39c9142..de31d0505e 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -48,6 +48,10 @@ typedef std::pair<boost::shared_ptr<const AutomationList>, std::pair<double,doub * note events (ie with a start time and a duration) rather than separate * note on and off events (controller data is not here since it's represented * as an AutomationList) + * + * FIXME: Currently this stores event time stamps in frames. This is almost + * certainly wrong, or at least wrong most of the time (if we add an option). + * This reeeeeeally needs fixing, but frame time runs deep in Ardour... */ class MidiModel : public boost::noncopyable, public Automatable { public: diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index 323fc8b5a1..5e41e3ff5b 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -58,7 +58,7 @@ class MidiSource : public Source virtual nframes_t midi_read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset) const; virtual nframes_t midi_write (MidiRingBuffer& src, nframes_t cnt); - virtual void append_event_unlocked(const MidiEvent& ev) = 0; + virtual void append_event_unlocked(EventTimeUnit unit, const MidiEvent& ev) = 0; virtual void mark_for_remove() = 0; virtual void mark_streaming_midi_write_started (NoteMode mode, nframes_t start_time); diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index 062e812643..937e08e44c 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -71,7 +71,7 @@ class SMFSource : public MidiSource { void set_allow_remove_if_empty (bool yn); void mark_for_remove(); - void append_event_unlocked(const MidiEvent& ev); + void append_event_unlocked(EventTimeUnit unit, const MidiEvent& ev); int flush_header (); int flush_footer (); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index efc2e35ecc..bfa0be17b6 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -132,6 +132,11 @@ namespace ARDOUR { Sustained, Percussive }; + + enum EventTimeUnit { + Frames, + Beats + }; struct BBT_Time { uint32_t bars; diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 60fb5eddb8..a0266521d4 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -290,10 +290,10 @@ write_midi_data_to_new_files (SMFReader* source, Session::import_status& status, break; t += delta_t; - ev.time() = t * (double)source->ppqn(); + ev.time() = (double)t / (double)source->ppqn(); ev.size() = size; - smfs->append_event_unlocked(ev); + smfs->append_event_unlocked(Beats, ev); if (status.progress < 0.99) status.progress += 0.01; } diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index 44416713f8..6bd351a6dc 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -660,7 +660,7 @@ MidiModel::write_to(boost::shared_ptr<MidiSource> source) const boost::shared_ptr<const Note> earliest_off = active_notes.top(); const MidiEvent& off_ev = earliest_off->off_event(); if (off_ev.time() <= (*n)->time()) { - source->append_event_unlocked(off_ev); + source->append_event_unlocked(Frames, off_ev); active_notes.pop(); } else { break; @@ -668,14 +668,14 @@ MidiModel::write_to(boost::shared_ptr<MidiSource> source) } // Write this note on - source->append_event_unlocked((*n)->on_event()); + source->append_event_unlocked(Frames, (*n)->on_event()); if ((*n)->duration() > 0) active_notes.push(*n); } // Write any trailing note offs while ( ! active_notes.empty() ) { - source->append_event_unlocked(active_notes.top()->off_event()); + source->append_event_unlocked(Frames, active_notes.top()->off_event()); active_notes.pop(); } diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 85cebf2b09..10713ef505 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -435,7 +435,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) time -= _timeline_position; const MidiEvent ev(time, size, buf); - append_event_unlocked(ev); + append_event_unlocked(Frames, ev); if (_model) _model->append(ev); @@ -454,7 +454,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) void -SMFSource::append_event_unlocked(const MidiEvent& ev) +SMFSource::append_event_unlocked(EventTimeUnit unit, const MidiEvent& ev) { /*printf("%s - append chan = %u, time = %lf, size = %u, data = ", _path.c_str(), (unsigned)ev.channel(), ev.time(), ev.size()); @@ -466,12 +466,19 @@ SMFSource::append_event_unlocked(const MidiEvent& ev) assert(ev.time() >= 0); assert(ev.time() >= _last_ev_time); - // FIXME: assumes tempo never changes after start - const double frames_per_beat = _session.tempo_map().tempo_at(_timeline_position).frames_per_beat( - _session.engine().frame_rate(), - _session.tempo_map().meter_at(_timeline_position)); + uint32_t delta_time = 0; - const uint32_t delta_time = (uint32_t)((ev.time() - _last_ev_time) / frames_per_beat * _ppqn); + if (unit == Frames) { + // FIXME: assumes tempo never changes after start + const double frames_per_beat = _session.tempo_map().tempo_at(_timeline_position).frames_per_beat( + _session.engine().frame_rate(), + _session.tempo_map().meter_at(_timeline_position)); + + delta_time = (uint32_t)((ev.time() - _last_ev_time) / frames_per_beat * _ppqn); + } else { + assert(unit == Beats); + delta_time = (uint32_t)((ev.time() - _last_ev_time) * _ppqn); + } const size_t stamp_size = write_var_len(delta_time); fwrite(ev.buffer(), 1, ev.size(), _fd); |