add delta-time option to MIDI tracer window. note that its not incredibly accurate or useful right now, because timestamps come from the system clock and are taken when the data is read/written to the port buffer, not its actual timestamp within the buffer

git-svn-id: svn://localhost/ardour2/branches/3.0@11458 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2012-02-06 17:19:59 +00:00
parent 009c7a9e44
commit 5252c77d94
2 changed files with 33 additions and 7 deletions

View File

@ -40,19 +40,24 @@ MidiTracer::MidiTracer ()
, parser (0)
, line_count_adjustment (200, 1, 2000, 1, 10)
, line_count_spinner (line_count_adjustment)
, line_count_label (_("Store this many lines: "))
, line_count_label (_("Line history: "))
, autoscroll (true)
, show_hex (true)
, collect (true)
, show_delta_time (false)
, _update_queued (0)
, fifo (1024)
, buffer_pool ("miditracer", buffer_size, 1024) // 1024 256 byte buffers
, autoscroll_button (_("Auto-Scroll"))
, base_button (_("Decimal"))
, collect_button (_("Enabled"))
, delta_time_button (_("Delta times"))
{
Manager::instance()->PortsChanged.connect (_manager_connection, invalidator (*this), boost::bind (&MidiTracer::ports_changed, this), gui_context());
_last_receipt.tv_sec = 0;
_last_receipt.tv_usec = 0;
VBox* vbox = manage (new VBox);
vbox->set_spacing (4);
@ -88,6 +93,7 @@ MidiTracer::MidiTracer ()
HBox* bbox = manage (new HBox);
bbox->add (line_count_box);
bbox->add (delta_time_button);
bbox->add (base_button);
bbox->add (collect_button);
bbox->add (autoscroll_button);
@ -100,6 +106,7 @@ MidiTracer::MidiTracer ()
base_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::base_toggle));
collect_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::collect_toggle));
autoscroll_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::autoscroll_toggle));
delta_time_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::delta_toggle));
base_button.show ();
collect_button.show ();
@ -157,15 +164,24 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len)
size_t s;
gettimeofday (&tv, 0);
localtime_r (&tv.tv_sec, &now);
buf = (char *) buffer_pool.alloc ();
bufsize = buffer_size;
s = strftime (buf, bufsize, "%H:%M:%S", &now);
bufsize -= s;
s += snprintf (&buf[s], bufsize, ".%06" PRId64, (int64_t) tv.tv_usec);
bufsize -= s;
if (_last_receipt.tv_sec != 0 && show_delta_time) {
struct timeval delta;
timersub (&tv, &_last_receipt, &delta);
s = snprintf (buf, bufsize, "+%02" PRId64 ":%06" PRId64, (int64_t) delta.tv_sec, (int64_t) delta.tv_usec);
bufsize -= s;
} else {
localtime_r (&tv.tv_sec, &now);
s = strftime (buf, bufsize, "%H:%M:%S", &now);
bufsize -= s;
s += snprintf (&buf[s], bufsize, ".%06" PRId64, (int64_t) tv.tv_usec);
bufsize -= s;
}
_last_receipt = tv;
switch ((eventType) msg[0]&0xf0) {
case off:
@ -385,6 +401,12 @@ MidiTracer::base_toggle ()
show_hex = !base_button.get_active();
}
void
MidiTracer::delta_toggle ()
{
show_delta_time = delta_time_button.get_active();
}
void
MidiTracer::collect_toggle ()
{

View File

@ -34,10 +34,12 @@ class MidiTracer : public ArdourWindow
Gtk::SpinButton line_count_spinner;
Gtk::Label line_count_label;
Gtk::HBox line_count_box;
struct timeval _last_receipt;
bool autoscroll;
bool show_hex;
bool collect;
bool show_delta_time;
/** Incremented when an update is requested, decremented when one is handled; hence
* equal to 0 when an update is not queued. May temporarily be negative if a
@ -55,11 +57,13 @@ class MidiTracer : public ArdourWindow
Gtk::CheckButton autoscroll_button;
Gtk::CheckButton base_button;
Gtk::CheckButton collect_button;
Gtk::CheckButton delta_time_button;
Gtk::ComboBoxText _port_combo;
void base_toggle ();
void autoscroll_toggle ();
void collect_toggle ();
void delta_toggle ();
void port_changed ();
void ports_changed ();