summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_source.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-02-16 02:51:16 +0000
committerDavid Robillard <d@drobilla.net>2009-02-16 02:51:16 +0000
commit3963d2b0b224e79fdf8e852e39fc3a765fa1431b (patch)
tree0c6c8a9d519d46437ffe9cb96f09ca337f33faff /libs/ardour/midi_source.cc
parentbeb3eea62bf217d0a7b2a86a96d5c375329df10a (diff)
Move all beats <-> frames time conversion into a single object that can be passed around.
This has 3 main benefits: - All conversion code is in one place (less duplication, potential bugs) - The conversion method can be passed to things that are ignorant of the actual time units involved, information required, etc. (In the future it would be nice to have user selectable tempo/frame time) - It should be relatively simple now to support tempo changes part-way through a MIDI region (at least architecturally speaking) git-svn-id: svn://localhost/ardour2/branches/3.0@4594 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_source.cc')
-rw-r--r--libs/ardour/midi_source.cc22
1 files changed, 14 insertions, 8 deletions
diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc
index 70abb99e56..ece0d9b104 100644
--- a/libs/ardour/midi_source.cc
+++ b/libs/ardour/midi_source.cc
@@ -52,16 +52,20 @@ sigc::signal<void,MidiSource *> MidiSource::MidiSourceCreated;
MidiSource::MidiSource (Session& s, string name)
: Source (s, name, DataType::MIDI)
, _timeline_position(0)
+ , _read_data_count(0)
+ , _write_data_count(0)
+ , _converter(s, _timeline_position)
, _writing (false)
, _last_read_end(0)
{
- _read_data_count = 0;
- _write_data_count = 0;
}
MidiSource::MidiSource (Session& s, const XMLNode& node)
: Source (s, node)
, _timeline_position(0)
+ , _read_data_count(0)
+ , _write_data_count(0)
+ , _converter(s, _timeline_position)
, _writing (false)
, _last_read_end(0)
{
@@ -110,12 +114,7 @@ MidiSource::midi_read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_
Glib::Mutex::Lock lm (_lock);
if (_model) {
- // FIXME: assumes tempo never changes after start
- const Tempo& tempo = _session.tempo_map().tempo_at(_timeline_position);
- const double frames_per_beat = tempo.frames_per_beat(
- _session.engine().frame_rate(),
- _session.tempo_map().meter_at(_timeline_position));
-#define BEATS_TO_FRAMES(t) (((t) * frames_per_beat) + stamp_offset - negative_stamp_offset)
+#define BEATS_TO_FRAMES(t) (_converter.to(t) + stamp_offset - negative_stamp_offset)
Evoral::Sequence<double>::const_iterator& i = _model_iter;
@@ -162,6 +161,13 @@ MidiSource::file_changed (string path)
}
void
+MidiSource::set_timeline_position (nframes_t when)
+{
+ _timeline_position = when;
+ _converter.set_origin(when);
+}
+
+void
MidiSource::mark_streaming_midi_write_started (NoteMode mode, nframes_t start_frame)
{
set_timeline_position(start_frame); // why do I have a feeling this can break somehow...