diff data/midi/MIDIInput.cpp @ 567:e6d35670e1df

* Somewhat better MIDI-based time instant timing
author Chris Cannam
date Wed, 25 Feb 2009 11:15:22 +0000
parents e2281de2361c
children 9773aadbae0c
line wrap: on
line diff
--- a/data/midi/MIDIInput.cpp	Tue Feb 24 17:53:01 2009 +0000
+++ b/data/midi/MIDIInput.cpp	Wed Feb 25 11:15:22 2009 +0000
@@ -17,8 +17,9 @@
 
 #include "rtmidi/RtMidi.h"
 
-MIDIInput::MIDIInput(QString name) :
+MIDIInput::MIDIInput(QString name, FrameTimer *timer) :
     m_rtmidi(),
+    m_frameTimer(timer),
     m_buffer(1023)
 {
     try {
@@ -48,10 +49,13 @@
 MIDIInput::callback(double timestamp, std::vector<unsigned char> *message)
 {
     std::cerr << "MIDIInput::callback(" << timestamp << ")" << std::endl;
-    unsigned long deltaTime = 0;
-    if (timestamp > 0) deltaTime = (unsigned long)(timestamp * 100000); //!!! for now!
+    // In my experience so far, the timings passed to this function
+    // are not reliable enough to use.  We request instead an audio
+    // frame time from whatever FrameTimer we have been given, and use
+    // that as the event time.
     if (!message || message->empty()) return;
-    MIDIEvent ev(deltaTime,
+    unsigned long t = m_frameTimer->getFrame();
+    MIDIEvent ev(t,
                  (*message)[0],
                  message->size() > 1 ? (*message)[1] : 0,
                  message->size() > 2 ? (*message)[2] : 0);