X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fmidi_tracer.cc;h=eb107979213ae71f40abe29e886611108c9fd7c5;hb=d584e962fff33f875574ef2b8301c6d7027a630d;hp=a92c5a57e349548f19a41264dee340faa8bc366c;hpb=23e7cf10191270d70357ccf0ed9294f020c7b7ab;p=ardour.git diff --git a/gtk2_ardour/midi_tracer.cc b/gtk2_ardour/midi_tracer.cc index a92c5a57e3..eb10797921 100644 --- a/gtk2_ardour/midi_tracer.cc +++ b/gtk2_ardour/midi_tracer.cc @@ -1,21 +1,24 @@ /* - 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. - -*/ + * Copyright (C) 2010-2011 Carl Hetherington + * Copyright (C) 2010-2018 Paul Davis + * Copyright (C) 2011 David Robillard + * Copyright (C) 2013 Michael Fisher + * Copyright (C) 2014-2015 Robin Gareus + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ #include @@ -34,7 +37,7 @@ #include "midi_tracer.h" #include "gui_thread.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace Gtk; using namespace std; @@ -43,13 +46,12 @@ using namespace Glib; MidiTracer::MidiTracer () : ArdourWindow (_("MIDI Tracer")) - , parser (0) , line_count_adjustment (200, 1, 2000, 1, 10) , line_count_spinner (line_count_adjustment) , line_count_label (_("Line history: ")) + , _last_receipt (0) , autoscroll (true) , show_hex (true) - , collect (true) , show_delta_time (false) , _update_queued (0) , fifo (1024) @@ -59,12 +61,9 @@ MidiTracer::MidiTracer () , collect_button (_("Enabled")) , delta_time_button (_("Delta times")) { - ARDOUR::AudioEngine::instance()->PortRegisteredOrUnregistered.connect + ARDOUR::AudioEngine::instance()->PortRegisteredOrUnregistered.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); @@ -123,7 +122,6 @@ MidiTracer::MidiTracer () port_changed (); } - MidiTracer::~MidiTracer() { } @@ -133,7 +131,7 @@ MidiTracer::ports_changed () { string const c = _port_combo.get_active_text (); _port_combo.clear (); - + ARDOUR::PortManager::PortList pl; ARDOUR::AudioEngine::instance()->get_ports (ARDOUR::DataType::MIDI, pl); @@ -180,11 +178,13 @@ MidiTracer::port_changed () boost::shared_ptr mp = boost::dynamic_pointer_cast (p); if (mp) { - mp->self_parser().any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3)); + my_parser.any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3, _4)); + mp->set_trace (&my_parser); + traced_port = mp; } - + } else { - async->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3)); + async->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3, _4)); } } @@ -192,37 +192,35 @@ void MidiTracer::disconnect () { _parser_connection.disconnect (); + + if (traced_port) { + traced_port->set_trace (0); + traced_port.reset (); + } } void -MidiTracer::tracer (Parser&, byte* msg, size_t len) +MidiTracer::tracer (Parser&, byte* msg, size_t len, samplecnt_t now) { stringstream ss; - struct timeval tv; char* buf; - struct tm now; size_t bufsize; size_t s; - gettimeofday (&tv, 0); + std::cerr << "tracer msg " << len << " bytes, first = " << hex << (int) msg[0] << dec << std::endl; buf = (char *) buffer_pool.alloc (); bufsize = buffer_size; - 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); + if (_last_receipt != 0 && show_delta_time) { + s = snprintf (buf, bufsize, "+%12ld", now - _last_receipt); bufsize -= s; } else { - localtime_r ((const time_t*)&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); + s = snprintf (buf, bufsize, "%12ld", now); bufsize -= s; } - _last_receipt = tv; + _last_receipt = now; switch ((eventType) msg[0]&0xf0) { case off: @@ -275,9 +273,9 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len) case MIDI::pitchbend: if (show_hex) { - s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "Pitch Bend", (msg[0]&0xf)+1, (int) msg[1]); + s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "Pitch Bend", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]); } else { - s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "Pitch Bend", (msg[0]&0xf)+1, (int) msg[1]); + s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d %-3d\n", "Pitch Bend", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]); } break; @@ -337,9 +335,9 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len) } else if (len == 10 && msg[0] == 0xf0 && msg[1] == 0x7f && msg[9] == 0xf7) { - /* MTC full frame */ + /* MTC full sample */ s += snprintf ( - &buf[s], bufsize, " MTC full frame to %02d:%02d:%02d:%02d\n", msg[5] & 0x1f, msg[6], msg[7], msg[8] + &buf[s], bufsize, " MTC full sample to %02d:%02d:%02d:%02d\n", msg[5] & 0x1f, msg[6], msg[7], msg[8] ); } else if (len == 3 && msg[0] == MIDI::position) { @@ -405,6 +403,8 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len) // If you want to append more to the line, uncomment this first // bufsize -= s; + assert(s <= buffer_size); // clang dead-assignment + fifo.write (&buf, 1); if (g_atomic_int_get (const_cast (&_update_queued)) == 0) {