-#define __STDC_FORMAT_MACROS 1
+/*
+ Copyright (C) 2010 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
#include <stdint.h>
#include <sstream>
#include <time.h>
#include "midi++/parser.h"
+#include "midi++/manager.h"
#include "midi_tracer.h"
#include "gui_thread.h"
using namespace MIDI;
using namespace Glib;
-MidiTracer::MidiTracer (const std::string& name, Parser& p)
- : ArdourDialog (string_compose (_("MIDI Trace %1"), name))
- , parser (p)
+MidiTracer::MidiTracer ()
+ : ArdourDialog (_("MIDI Tracer"))
+ , parser (0)
, line_count_adjustment (200, 1, 2000, 1, 10)
, line_count_spinner (line_count_adjustment)
, line_count_label (_("Store this many lines: "))
, autoscroll (true)
, show_hex (true)
, collect (true)
- , update_queued (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"))
{
+ get_vbox()->set_spacing (4);
+
+ Manager::instance()->PortsChanged.connect (_manager_connection, invalidator (*this), boost::bind (&MidiTracer::ports_changed, this), gui_context());
+
+ HBox* pbox = manage (new HBox);
+ pbox->pack_start (*manage (new Label (_("Port:"))), false, false);
+
+ _port_combo.signal_changed().connect (sigc::mem_fun (*this, &MidiTracer::port_changed));
+ pbox->pack_start (_port_combo);
+ pbox->show_all ();
+ get_vbox()->pack_start (*pbox, false, false);
+
scroller.add (text);
get_vbox()->set_border_width (12);
get_vbox()->pack_start (scroller, true, true);
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));
collect_button.show ();
autoscroll_button.show ();
- connect ();
+ ports_changed ();
+ port_changed ();
}
}
void
-MidiTracer::connect ()
+MidiTracer::ports_changed ()
+{
+ string const c = _port_combo.get_active_text ();
+ _port_combo.clear ();
+
+ Manager::PortList const & p = Manager::instance()->get_midi_ports ();
+ for (Manager::PortList::const_iterator i = p.begin(); i != p.end(); ++i) {
+ _port_combo.append_text ((*i)->name());
+ }
+
+ _port_combo.set_active_text (c);
+}
+
+void
+MidiTracer::port_changed ()
{
disconnect ();
- parser.any.connect_same_thread (connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3));
+
+ Port* p = Manager::instance()->port (_port_combo.get_active_text());
+
+ if (p) {
+ p->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3));
+ }
}
void
MidiTracer::disconnect ()
{
- connection.disconnect ();
+ _parser_connection.disconnect ();
}
void
s = strftime (buf, bufsize, "%H:%M:%S", &now);
bufsize -= s;
- s = snprintf (&buf[s], bufsize, ".%-9" PRId64, (int64_t) tv.tv_usec);
+ s += snprintf (&buf[s], bufsize, ".%06" PRId64, (int64_t) tv.tv_usec);
bufsize -= s;
switch ((eventType) msg[0]&0xf0) {
s += snprintf (&buf[s], bufsize, "%16s %02x\n", "Sysex", (int) msg[1]);
break;
}
- bufsize -= s;
+
+ } else if (len > 5 && msg[0] == 0xf0 && msg[1] == 0x7f && msg[3] == 0x06) {
+ /* MMC */
+ int cmd = msg[4];
+ if (cmd == 0x44 && msg[5] == 0x06 && msg[6] == 0x01) {
+ s += snprintf (
+ &buf[s], bufsize, " MMC locate to %02d:%02d:%02d:%02d.%02d\n",
+ msg[7], msg[8], msg[9], msg[10], msg[11]
+ );
+ } else {
+ std::string name;
+ if (cmd == 0x1) {
+ name = "STOP";
+ } else if (cmd == 0x3) {
+ name = "DEFERRED PLAY";
+ } else if (cmd == 0x6) {
+ name = "RECORD STROBE";
+ } else if (cmd == 0x7) {
+ name = "RECORD EXIT";
+ } else if (cmd == 0x8) {
+ name = "RECORD PAUSE";
+ }
+ if (!name.empty()) {
+ s += snprintf (&buf[s], bufsize, " MMC command %s\n", name.c_str());
+ } else {
+ s += snprintf (&buf[s], bufsize, " MMC command %02x\n", cmd);
+ }
+ }
+
+ } else if (len == 10 && msg[0] == 0xf0 && msg[1] == 0x7f && msg[9] == 0xf7) {
+
+ /* MTC full frame */
+ s += snprintf (
+ &buf[s], bufsize, " MTC full frame to %02d:%02d:%02d:%02d\n", msg[5] & 0x1f, msg[6], msg[7], msg[8]
+ );
+
} else {
- s += snprintf (&buf[s], bufsize, " %16s (%d) = [", "Sysex", (int) len);
+
+ /* other sys-ex */
+
+ s += snprintf (&buf[s], bufsize, "%16s (%d) = [", "Sysex", (int) len);
bufsize -= s;
-
- for (unsigned int i = 0; i < len && s < sizeof (buf)-3; ++i) {
+
+ 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");
}
fifo.write (&buf, 1);
- if (!update_queued) {
- gui_context()->call_slot (boost::bind (&MidiTracer::update, this));
- update_queued = true;
+ if (g_atomic_int_get (&_update_queued) == 0) {
+ gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this));
+ g_atomic_int_inc (&_update_queued);
}
}
MidiTracer::update ()
{
bool updated = false;
- update_queued = false;
+ g_atomic_int_dec_and_test (&_update_queued);
RefPtr<TextBuffer> buf (text.get_buffer());
MidiTracer::collect_toggle ()
{
if (collect_button.get_active ()) {
- connect ();
+ port_changed ();
} else {
disconnect ();
}