, autoscroll (true)
, show_hex (true)
, collect (true)
+ , update_queued (false)
+ , fifo (1024)
+ , buffer_pool ("miditracer", buffer_size, 1024) // 1024 256 byte buffers
, autoscroll_button (_("Auto-Scroll"))
, base_button (_("Decimal"))
, collect_button (_("Enabled"))
get_vbox()->pack_start (scroller, true, true);
text.show ();
+ text.set_name ("MidiTracerTextView");
scroller.show ();
scroller.set_size_request (400, 400);
line_count_box.show ();
get_action_area()->add (line_count_box);
- get_action_area()->add (base_button);
- get_action_area()->add(collect_button);
- get_action_area()->add (autoscroll_button);
+
+ HBox* bbox = manage (new HBox);
+ bbox->add (base_button);
+ bbox->add (collect_button);
+ bbox->add (autoscroll_button);
+ bbox->show ();
+
+ get_action_area()->add (*bbox);
base_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::base_toggle));
collect_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::collect_toggle));
connect ();
}
+
MidiTracer::~MidiTracer()
{
}
{
stringstream ss;
struct timeval tv;
- char buf[256];
+ char* buf;
struct tm now;
size_t bufsize;
size_t s;
gettimeofday (&tv, 0);
localtime_r (&tv.tv_sec, &now);
- s = strftime (buf, sizeof (buf), "%H:%M:%S", &now);
- bufsize = sizeof (buf) - s;
+ buf = (char *) buffer_pool.alloc ();
+ bufsize = buffer_size;
+
+ s = strftime (buf, bufsize, "%H:%M:%S", &now);
+ bufsize -= s;
s += snprintf (&buf[s], bufsize, ".%-9" PRId64, (int64_t) tv.tv_usec);
- bufsize = sizeof (buf) - s;
-
+ bufsize -= s;
+
switch ((eventType) msg[0]&0xf0) {
case off:
if (show_hex) {
case program:
if (show_hex) {
- s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "Program Change", (msg[0]&0xf)+1, (int) msg[1]);
+ s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "Program PropertyChange", (msg[0]&0xf)+1, (int) msg[1]);
} else {
- s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "Program Change", (msg[0]&0xf)+1, (int) msg[1]);
+ s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "Program PropertyChange", (msg[0]&0xf)+1, (int) msg[1]);
}
break;
s += snprintf (&buf[s], bufsize, "%16s %02x\n", "Sysex", (int) msg[1]);
break;
}
- bufsize = sizeof (buf) - s;
+
} else {
- s += snprintf (&buf[s], bufsize, " %16s (%d) = [", "Sysex", (int) len);
- bufsize = sizeof (buf) - s;
- for (unsigned int i = 0; i < len && s < sizeof (buf)-3; ++i) {
+ s += snprintf (&buf[s], bufsize, "%16s (%d) = [", "Sysex", (int) len);
+ bufsize -= s;
+
+ for (unsigned int i = 0; i < len && bufsize > 3; ++i) {
if (i > 0) {
s += snprintf (&buf[s], bufsize, " %02x", msg[i]);
} else {
s += snprintf (&buf[s], bufsize, "%02x", msg[i]);
}
- bufsize = sizeof (buf) - s;
+ bufsize -= s;
}
s += snprintf (&buf[s], bufsize, "]\n");
}
}
// If you want to append more to the line, uncomment this first
- // bufsize = sizeof (buf) - s;
+ // bufsize -= s;
+
+ fifo.write (&buf, 1);
- gui_context()->call_slot (boost::bind (&MidiTracer::add_string, this, string (buf)));
+ if (!update_queued) {
+ gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this));
+ update_queued = true;
+ }
}
void
-MidiTracer::add_string (std::string s)
+MidiTracer::update ()
{
+ bool updated = false;
+ update_queued = false;
+
RefPtr<TextBuffer> buf (text.get_buffer());
int excess = buf->get_line_count() - line_count_adjustment.get_value();
buf->erase (buf->begin(), buf->get_iter_at_line (excess));
}
- buf->insert (buf->end(), s);
+ char *str;
+
+ while (fifo.read (&str, 1)) {
+ buf->insert (buf->end(), string (str));
+ buffer_pool.release (str);
+ updated = true;
+ }
- if (autoscroll) {
+ if (updated && autoscroll) {
scroller.get_vadjustment()->set_value (scroller.get_vadjustment()->get_upper());
}
}