2010-07-06 20:40:58 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2010-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2013 Michael Fisher <mfisher31@gmail.com>
|
|
|
|
* Copyright (C) 2014-2015 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-07-06 20:40:58 -04:00
|
|
|
|
2023-02-17 13:34:54 -05:00
|
|
|
#include <cstdint>
|
2010-01-06 16:56:23 -05:00
|
|
|
#include <sstream>
|
2023-02-17 13:34:54 -05:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2013-07-13 08:19:03 -04:00
|
|
|
#include "pbd/localtime_r.h"
|
2013-07-13 08:19:32 -04:00
|
|
|
#include "pbd/timersub.h"
|
2013-07-13 08:19:03 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
#include "midi++/parser.h"
|
2013-08-07 22:22:11 -04:00
|
|
|
|
|
|
|
#include "ardour/async_midi_port.h"
|
|
|
|
#include "ardour/midi_port.h"
|
|
|
|
#include "ardour/audioengine.h"
|
2021-06-23 15:22:01 -04:00
|
|
|
#include "ardour/transport_master_manager.h"
|
2010-01-06 16:56:23 -05:00
|
|
|
|
|
|
|
#include "midi_tracer.h"
|
|
|
|
#include "gui_thread.h"
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2010-01-06 16:56:23 -05:00
|
|
|
|
2021-06-23 15:22:01 -04:00
|
|
|
unsigned int MidiTracer::window_count = 0;
|
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace std;
|
|
|
|
using namespace MIDI;
|
|
|
|
using namespace Glib;
|
2022-12-30 21:09:24 -05:00
|
|
|
using namespace ARDOUR;
|
2010-01-06 16:56:23 -05:00
|
|
|
|
2010-07-06 20:40:58 -04:00
|
|
|
MidiTracer::MidiTracer ()
|
2011-11-18 19:56:35 -05:00
|
|
|
: ArdourWindow (_("MIDI Tracer"))
|
2010-01-06 16:56:23 -05:00
|
|
|
, line_count_adjustment (200, 1, 2000, 1, 10)
|
|
|
|
, line_count_spinner (line_count_adjustment)
|
2012-02-06 12:19:59 -05:00
|
|
|
, line_count_label (_("Line history: "))
|
2018-09-18 18:52:20 -04:00
|
|
|
, _last_receipt (0)
|
2010-01-06 16:56:23 -05:00
|
|
|
, autoscroll (true)
|
|
|
|
, show_hex (true)
|
2012-02-06 12:19:59 -05:00
|
|
|
, show_delta_time (false)
|
2010-01-31 22:33:52 -05:00
|
|
|
, fifo (1024)
|
|
|
|
, buffer_pool ("miditracer", buffer_size, 1024) // 1024 256 byte buffers
|
2010-01-06 16:56:23 -05:00
|
|
|
, autoscroll_button (_("Auto-Scroll"))
|
|
|
|
, base_button (_("Decimal"))
|
|
|
|
, collect_button (_("Enabled"))
|
2012-02-06 12:19:59 -05:00
|
|
|
, delta_time_button (_("Delta times"))
|
2010-01-06 16:56:23 -05:00
|
|
|
{
|
2023-02-17 02:31:31 -05:00
|
|
|
_update_queued.store (0);
|
2021-03-19 01:20:21 -04:00
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
std::string portname (string_compose(X_("x-MIDI-tracer-%1"), ++window_count));
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Port> port = AudioEngine::instance()->register_input_port (DataType::MIDI, portname, false, PortFlags (IsInput | Hidden | IsTerminal));
|
|
|
|
tracer_port = std::dynamic_pointer_cast<MidiPort> (port);
|
2022-12-30 21:09:24 -05:00
|
|
|
|
|
|
|
_midi_port_list = ListStore::create (_midi_port_cols);
|
|
|
|
_midi_port_combo.set_model (_midi_port_list);
|
|
|
|
_midi_port_combo.pack_start (_midi_port_cols.pretty_name);
|
|
|
|
|
|
|
|
AudioEngine::instance()->PortRegisteredOrUnregistered.connect
|
2013-08-07 22:22:11 -04:00
|
|
|
(_manager_connection, invalidator (*this), boost::bind (&MidiTracer::ports_changed, this), gui_context());
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
VBox* vbox = manage (new VBox);
|
|
|
|
vbox->set_spacing (4);
|
|
|
|
|
2010-07-06 20:40:58 -04:00
|
|
|
HBox* pbox = manage (new HBox);
|
2011-11-01 21:12:53 -04:00
|
|
|
pbox->set_spacing (6);
|
2010-07-06 20:40:58 -04:00
|
|
|
pbox->pack_start (*manage (new Label (_("Port:"))), false, false);
|
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
_midi_port_combo.signal_changed().connect (sigc::mem_fun (*this, &MidiTracer::port_changed));
|
|
|
|
pbox->pack_start (_midi_port_combo);
|
2010-07-06 20:40:58 -04:00
|
|
|
pbox->show_all ();
|
2011-11-18 19:56:35 -05:00
|
|
|
vbox->pack_start (*pbox, false, false);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
scroller.add (text);
|
2011-11-18 19:56:35 -05:00
|
|
|
vbox->set_border_width (12);
|
|
|
|
vbox->pack_start (scroller, true, true);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
text.show ();
|
2010-01-31 22:33:52 -05:00
|
|
|
text.set_name ("MidiTracerTextView");
|
2010-01-06 16:56:23 -05:00
|
|
|
scroller.show ();
|
|
|
|
scroller.set_size_request (400, 400);
|
|
|
|
|
|
|
|
collect_button.set_active (true);
|
|
|
|
base_button.set_active (false);
|
|
|
|
autoscroll_button.set_active (true);
|
|
|
|
|
|
|
|
line_count_box.set_spacing (6);
|
|
|
|
line_count_box.pack_start (line_count_label, false, false);
|
|
|
|
line_count_box.pack_start (line_count_spinner, false, false);
|
|
|
|
|
|
|
|
line_count_spinner.show ();
|
|
|
|
line_count_label.show ();
|
|
|
|
line_count_box.show ();
|
|
|
|
|
2010-03-14 21:41:01 -04:00
|
|
|
HBox* bbox = manage (new HBox);
|
2011-11-18 19:56:35 -05:00
|
|
|
bbox->add (line_count_box);
|
2012-02-06 12:19:59 -05:00
|
|
|
bbox->add (delta_time_button);
|
2010-03-14 21:41:01 -04:00
|
|
|
bbox->add (base_button);
|
|
|
|
bbox->add (collect_button);
|
|
|
|
bbox->add (autoscroll_button);
|
|
|
|
bbox->show ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
vbox->pack_start (*bbox, false, false);
|
|
|
|
|
|
|
|
add (*vbox);
|
2010-01-06 16:56:23 -05:00
|
|
|
|
|
|
|
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));
|
2012-02-06 12:19:59 -05:00
|
|
|
delta_time_button.signal_toggled().connect (sigc::mem_fun (*this, &MidiTracer::delta_toggle));
|
2010-01-06 16:56:23 -05:00
|
|
|
|
|
|
|
base_button.show ();
|
|
|
|
collect_button.show ();
|
|
|
|
autoscroll_button.show ();
|
|
|
|
|
2010-07-06 20:40:58 -04:00
|
|
|
ports_changed ();
|
|
|
|
port_changed ();
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiTracer::~MidiTracer()
|
|
|
|
{
|
2022-12-11 07:13:02 -05:00
|
|
|
disconnect ();
|
2022-12-30 21:09:24 -05:00
|
|
|
AudioEngine::instance ()->unregister_port (tracer_port);
|
2022-12-11 07:13:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTracer::on_show ()
|
|
|
|
{
|
|
|
|
ArdourWindow::on_show ();
|
|
|
|
collect_toggle ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTracer::on_hide ()
|
|
|
|
{
|
|
|
|
ArdourWindow::on_hide ();
|
|
|
|
disconnect ();
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-06 20:40:58 -04:00
|
|
|
MidiTracer::ports_changed ()
|
|
|
|
{
|
2022-12-30 21:09:24 -05:00
|
|
|
TreeModel::iterator r = _midi_port_combo.get_active ();
|
|
|
|
string cpn;
|
|
|
|
if (r) {
|
|
|
|
cpn = (*r)[_midi_port_cols.port_name];
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
_midi_port_list->clear ();
|
2013-08-07 22:22:11 -04:00
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
PortManager::PortList pl;
|
|
|
|
AudioEngine::instance()->get_ports (DataType::MIDI, pl);
|
|
|
|
|
|
|
|
std::vector<std::string> pp;
|
|
|
|
AudioEngine::instance ()->get_physical_inputs (DataType::MIDI, pp, MidiPortFlags (0), MidiPortFlags (MidiPortControl | MidiPortVirtual));
|
|
|
|
/* ideally we'd also list external (JACK) ports
|
|
|
|
* however there is no convenient API
|
|
|
|
* `PortManager::get_ports (const string& port_name_pattern, DataType type, PortFlags flags, vector<string>& s)`
|
|
|
|
* lists ALL ports and we'd need to filter any outputs (sinks), except our own sinks (which can be traced).
|
|
|
|
*/
|
|
|
|
|
|
|
|
size_t nth = 0;
|
|
|
|
size_t act = 0;
|
|
|
|
|
|
|
|
/* physical I/Os first */
|
|
|
|
for (auto const& pn : pp) {
|
|
|
|
if (!cpn.empty () && pn == cpn) {
|
|
|
|
act = nth;
|
|
|
|
}
|
|
|
|
++nth;
|
|
|
|
std::string ppn = AudioEngine::instance()->get_pretty_name_by_name (pn);
|
|
|
|
if (ppn.empty ()) {
|
|
|
|
ppn = pn.substr (pn.find (':') + 1);
|
|
|
|
}
|
|
|
|
TreeModel::Row row = *_midi_port_list->append ();
|
|
|
|
row[_midi_port_cols.pretty_name] = string_compose (_("HW: %1"), ppn);
|
|
|
|
row[_midi_port_cols.port_name] = pn;
|
2013-08-07 22:22:11 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
/* Ardour owned ports */
|
|
|
|
for (auto const& p : pl) {
|
|
|
|
if (p->flags() & Hidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::string const& pn = p->name ();
|
|
|
|
if (!cpn.empty () && pn == cpn) {
|
|
|
|
act = nth;
|
|
|
|
}
|
|
|
|
++nth;
|
|
|
|
std::string ppn = p->pretty_name (false);
|
|
|
|
if (ppn.empty ()) {
|
|
|
|
ppn = pn.substr (pn.find (':') + 1);
|
|
|
|
}
|
|
|
|
TreeModel::Row row = *_midi_port_list->append ();
|
|
|
|
row[_midi_port_cols.pretty_name] = ppn;
|
|
|
|
row[_midi_port_cols.port_name] = pn;
|
2010-07-06 20:40:58 -04:00
|
|
|
}
|
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
if (nth > 0) {
|
|
|
|
_midi_port_combo.set_active (act);
|
2013-08-07 22:22:11 -04:00
|
|
|
}
|
2010-07-06 20:40:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTracer::port_changed ()
|
2010-01-06 16:56:23 -05:00
|
|
|
{
|
2013-08-07 22:22:11 -04:00
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
disconnect ();
|
2010-07-06 20:40:58 -04:00
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
TreeModel::iterator r = _midi_port_combo.get_active ();
|
|
|
|
if (!r) {
|
2021-06-23 15:22:01 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
std::string const pn = (*r)[_midi_port_cols.port_name];
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Port> p = AudioEngine::instance()->get_port_by_name (pn);
|
2013-08-07 22:22:11 -04:00
|
|
|
|
|
|
|
if (!p) {
|
2022-12-30 21:09:24 -05:00
|
|
|
/* connect to external port */
|
|
|
|
if (0 == tracer_port->connect (pn)) {
|
2023-02-16 18:33:28 -05:00
|
|
|
_midi_parser = std::shared_ptr<MIDI::Parser> (new MIDI::Parser);
|
2022-12-30 21:09:24 -05:00
|
|
|
_midi_parser->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3, _4));
|
2023-06-03 16:26:08 -04:00
|
|
|
tracer_port->set_trace (_midi_parser);
|
2022-12-30 21:09:24 -05:00
|
|
|
} else {
|
|
|
|
std::cerr << "CANNOT TRACE PORT " << pn << "\n";
|
|
|
|
}
|
2013-08-07 22:22:11 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Fix typos in gtk2_ardour/ directory
Found via `codespell -q 3 -S *.po,./share/patchfiles,./libs -L ba,buss,busses,doubleclick,hsi,ontop,ro,seh,siz,sur,te,trough,ue`
2022-01-26 12:35:38 -05:00
|
|
|
/* The inheritance hierarchy makes this messy. AsyncMIDIPort has two
|
2013-08-13 13:24:05 -04:00
|
|
|
* available MIDI::Parsers what we could connect to, ::self_parser()
|
|
|
|
* (from ARDOUR::MidiPort) and ::parser() from MIDI::Port. One day,
|
|
|
|
* this mess will all go away ...
|
|
|
|
*/
|
|
|
|
|
Fix typos in gtk2_ardour/ directory
Found via `codespell -q 3 -S *.po,./share/patchfiles,./libs -L ba,buss,busses,doubleclick,hsi,ontop,ro,seh,siz,sur,te,trough,ue`
2022-01-26 12:35:38 -05:00
|
|
|
/* Some ports have a parser available (Transport Masters and ASYNC ports)
|
2021-06-22 23:21:37 -04:00
|
|
|
* and some do not. If the port has a parser already, just attach to it.
|
|
|
|
* If not use our local parser and tell the port that we need it to be called.
|
|
|
|
*/
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<AsyncMIDIPort> async = std::dynamic_pointer_cast<AsyncMIDIPort> (p);
|
2010-07-06 20:40:58 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
if (!async) {
|
2010-07-06 20:40:58 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiPort> mp = std::dynamic_pointer_cast<MidiPort> (p);
|
2013-08-13 13:24:05 -04:00
|
|
|
if (mp) {
|
2021-06-22 23:21:37 -04:00
|
|
|
if (mp->flags() & TransportMasterPort) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<TransportMaster> tm = TransportMasterManager::instance().master_by_port(std::dynamic_pointer_cast<ARDOUR::Port> (p));
|
|
|
|
std::shared_ptr<TransportMasterViaMIDI> tm_midi = std::dynamic_pointer_cast<TransportMasterViaMIDI> (tm);
|
2021-06-22 23:21:37 -04:00
|
|
|
if (tm_midi) {
|
|
|
|
tm_midi->transport_parser().any.connect_same_thread(_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3, _4));
|
|
|
|
}
|
2022-12-30 21:09:24 -05:00
|
|
|
} else {
|
2023-02-16 18:33:28 -05:00
|
|
|
_midi_parser = std::shared_ptr<MIDI::Parser> (new MIDI::Parser);
|
2022-12-30 21:09:24 -05:00
|
|
|
_midi_parser->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3, _4));
|
2023-06-03 16:26:08 -04:00
|
|
|
mp->set_trace (_midi_parser);
|
2021-06-22 23:21:37 -04:00
|
|
|
traced_port = mp;
|
|
|
|
}
|
2013-08-13 13:24:05 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-13 13:24:05 -04:00
|
|
|
} else {
|
2018-09-18 18:52:20 -04:00
|
|
|
async->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3, _4));
|
2010-07-06 20:40:58 -04:00
|
|
|
}
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTracer::disconnect ()
|
|
|
|
{
|
2010-07-06 20:40:58 -04:00
|
|
|
_parser_connection.disconnect ();
|
2015-02-10 19:48:28 -05:00
|
|
|
|
2022-12-30 21:09:24 -05:00
|
|
|
tracer_port->disconnect_all ();
|
2023-06-03 16:26:08 -04:00
|
|
|
tracer_port->set_trace (std::weak_ptr<MIDI::Parser>());
|
2022-12-30 21:09:24 -05:00
|
|
|
|
2015-02-10 19:48:28 -05:00
|
|
|
if (traced_port) {
|
2023-06-03 16:26:08 -04:00
|
|
|
traced_port->set_trace (std::weak_ptr<MIDI::Parser>());
|
2015-02-10 19:48:28 -05:00
|
|
|
traced_port.reset ();
|
|
|
|
}
|
2022-12-30 21:09:24 -05:00
|
|
|
_midi_parser.reset ();
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-05-01 23:46:31 -04:00
|
|
|
MidiTracer::tracer (Parser&, MIDI::byte* msg, size_t len, samplecnt_t now)
|
2010-01-06 16:56:23 -05:00
|
|
|
{
|
|
|
|
stringstream ss;
|
2010-01-31 22:33:52 -05:00
|
|
|
char* buf;
|
2010-01-06 16:56:23 -05:00
|
|
|
size_t bufsize;
|
|
|
|
size_t s;
|
|
|
|
|
2010-01-31 22:33:52 -05:00
|
|
|
buf = (char *) buffer_pool.alloc ();
|
|
|
|
bufsize = buffer_size;
|
|
|
|
|
2018-09-18 18:52:20 -04:00
|
|
|
if (_last_receipt != 0 && show_delta_time) {
|
2020-06-11 21:41:43 -04:00
|
|
|
s = snprintf (buf, bufsize, "+%12" PRId64, now - _last_receipt);
|
2012-02-06 12:19:59 -05:00
|
|
|
bufsize -= s;
|
|
|
|
} else {
|
2020-06-11 21:41:43 -04:00
|
|
|
s = snprintf (buf, bufsize, "%12" PRId64, now);
|
2012-02-06 12:19:59 -05:00
|
|
|
bufsize -= s;
|
|
|
|
}
|
|
|
|
|
2018-09-18 18:52:20 -04:00
|
|
|
_last_receipt = now;
|
2010-01-31 22:33:52 -05:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
switch ((eventType) msg[0]&0xf0) {
|
|
|
|
case off:
|
|
|
|
if (show_hex) {
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "NoteOff", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
|
|
|
} else {
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d %-3d\n", "NoteOff", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case on:
|
|
|
|
if (show_hex) {
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "NoteOn", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
|
|
|
} else {
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d %-3d\n", "NoteOn", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case polypress:
|
|
|
|
if (show_hex) {
|
2024-05-14 11:20:01 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "PolyPressure", (msg[0]&0xf)+1, (int) msg[1], msg[2]);
|
2010-01-06 16:56:23 -05:00
|
|
|
} else {
|
2024-05-14 11:20:01 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d %-3d\n", "PolyPressure", (msg[0]&0xf)+1, (int) msg[1], msg[2]);
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::controller:
|
|
|
|
if (show_hex) {
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "Controller", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
|
|
|
} else {
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %2d %-3d\n", "Controller", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case program:
|
|
|
|
if (show_hex) {
|
2010-05-15 19:57:41 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "Program Change", (msg[0]&0xf)+1, (int) msg[1]);
|
2010-01-06 16:56:23 -05:00
|
|
|
} else {
|
2010-05-15 19:57:41 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "Program Change", (msg[0]&0xf)+1, (int) msg[1]);
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case chanpress:
|
|
|
|
if (show_hex) {
|
2024-05-14 11:20:01 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x\n", "Channel Pressure", (msg[0]&0xf)+1, (int) msg[1]);
|
2010-01-06 16:56:23 -05:00
|
|
|
} else {
|
2024-05-14 11:20:01 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d\n", "Channel Pressure", (msg[0]&0xf)+1, (int) msg[1]);
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::pitchbend:
|
|
|
|
if (show_hex) {
|
2015-09-29 09:06:40 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %02x %02x\n", "Pitch Bend", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
2010-01-06 16:56:23 -05:00
|
|
|
} else {
|
2015-09-29 09:06:40 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s chn %2d %-3d %-3d\n", "Pitch Bend", (msg[0]&0xf)+1, (int) msg[1], (int) msg[2]);
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::sysex:
|
|
|
|
if (len == 1) {
|
|
|
|
switch (msg[0]) {
|
|
|
|
case 0xf8:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Clock");
|
|
|
|
break;
|
2023-02-23 17:34:22 -05:00
|
|
|
case 0xf9:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Tick");
|
|
|
|
break;
|
2010-01-06 16:56:23 -05:00
|
|
|
case 0xfa:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Start");
|
|
|
|
break;
|
|
|
|
case 0xfb:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Continue");
|
|
|
|
break;
|
|
|
|
case 0xfc:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Stop");
|
|
|
|
break;
|
|
|
|
case 0xfe:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Active Sense");
|
|
|
|
break;
|
|
|
|
case 0xff:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Reset");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s %02x\n", "Sysex", (int) msg[1]);
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
}
|
2010-02-02 12:47:05 -05:00
|
|
|
|
2010-07-07 19:49:29 -04:00
|
|
|
} 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]
|
|
|
|
);
|
2023-06-03 12:10:40 -04:00
|
|
|
} else if (cmd == 0x47 && msg[5] == 0x03) {
|
|
|
|
uint8_t sh = msg[6];
|
|
|
|
uint8_t sm = msg[7];
|
|
|
|
uint8_t sl = msg[8];
|
|
|
|
|
|
|
|
bool forward = sh & (1<<6) ? false : true;
|
|
|
|
size_t left_shift = sh & 0x38;
|
|
|
|
size_t integral = ((sh & 0x7) << left_shift) | (sm >> (7 - left_shift));
|
|
|
|
size_t fractional = ((sm << left_shift) << 7) | sl;
|
|
|
|
|
|
|
|
float shuttle_speed = integral + ((float)fractional / (1 << (14 - left_shift)));
|
|
|
|
|
|
|
|
s += snprintf (&buf[s], bufsize, " MMC Shuttle %s%f\n", forward ? "+" : "-", shuttle_speed);
|
2010-07-07 19:49:29 -04:00
|
|
|
} else {
|
|
|
|
std::string name;
|
2023-06-03 12:10:40 -04:00
|
|
|
switch (cmd) {
|
|
|
|
case 0x01:
|
|
|
|
name = "Stop";
|
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
name = "Play";
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
name = "Deferred Play";
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
name = "Fast Forward";
|
|
|
|
break;
|
|
|
|
case 0x05:
|
|
|
|
name = "Rewind";
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
name = "Record Strobe";
|
|
|
|
break;
|
|
|
|
case 0x07:
|
|
|
|
name = "Record Exit";
|
|
|
|
break;
|
|
|
|
case 0x08:
|
|
|
|
name = "Record Pause";
|
|
|
|
break;
|
|
|
|
case 0x09:
|
|
|
|
name = "Pause";
|
|
|
|
break;
|
|
|
|
case 0x0a:
|
|
|
|
name = "Eject";
|
|
|
|
break;
|
|
|
|
case 0x0b:
|
|
|
|
name = "Chase";
|
|
|
|
break;
|
|
|
|
case 0x40:
|
|
|
|
name = "Write (ARM Tracks)";
|
|
|
|
break;
|
|
|
|
case 0x0d:
|
|
|
|
name = "MMC Reset";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-07-07 19:49:29 -04:00
|
|
|
}
|
|
|
|
if (!name.empty()) {
|
|
|
|
s += snprintf (&buf[s], bufsize, " MMC command %s\n", name.c_str());
|
2010-01-06 16:56:23 -05:00
|
|
|
} else {
|
2010-07-07 19:49:29 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, " MMC command %02x\n", cmd);
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
2010-07-07 19:49:29 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-07 19:49:29 -04:00
|
|
|
} else if (len == 10 && msg[0] == 0xf0 && msg[1] == 0x7f && msg[9] == 0xf7) {
|
2010-06-29 09:46:18 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
/* MTC full sample */
|
2020-03-27 14:40:44 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, " MTC full sample to %02d:%02d:%02d:%02d\n", msg[5] & 0x1f, msg[6], msg[7], msg[8]);
|
2013-08-01 01:55:58 -04:00
|
|
|
} else if (len == 3 && msg[0] == MIDI::position) {
|
2010-07-07 19:49:29 -04:00
|
|
|
|
2013-08-01 01:55:58 -04:00
|
|
|
/* MIDI Song Position */
|
2013-08-02 19:23:36 -04:00
|
|
|
int midi_beats = (msg[2] << 7) | msg[1];
|
2013-08-01 01:55:58 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s %d\n", "Position", (int) midi_beats);
|
2020-03-27 14:37:44 -04:00
|
|
|
} else if (len == 2 && msg[0] == MIDI::mtc_quarter) {
|
|
|
|
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s %02x\n", "MTC Quarter", msg[1]);
|
|
|
|
|
2010-07-07 19:49:29 -04:00
|
|
|
} else {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-07 19:49:29 -04:00
|
|
|
/* other sys-ex */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2020-06-11 21:41:43 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "%16s (%" PRId64 ") = [", "Sysex", len);
|
2010-07-07 19:49:29 -04:00
|
|
|
bufsize -= s;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-07 19:49:29 -04:00
|
|
|
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]);
|
2010-06-29 09:46:18 -04:00
|
|
|
}
|
2010-07-07 19:49:29 -04:00
|
|
|
bufsize -= s;
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
2010-07-07 19:49:29 -04:00
|
|
|
s += snprintf (&buf[s], bufsize, "]\n");
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::song:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Song");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::tune:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Tune");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::eox:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "EOX");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::timing:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Timing");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::start:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Start");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::stop:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Stop");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case MIDI::contineu:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Continue");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
case active:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Active Sense");
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
default:
|
|
|
|
s += snprintf (&buf[s], bufsize, "%16s\n", "Unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you want to append more to the line, uncomment this first
|
2010-01-31 22:33:52 -05:00
|
|
|
// bufsize -= s;
|
|
|
|
|
2014-11-17 22:46:37 -05:00
|
|
|
assert(s <= buffer_size); // clang dead-assignment
|
|
|
|
|
2010-01-31 22:33:52 -05:00
|
|
|
fifo.write (&buf, 1);
|
2010-01-06 16:56:23 -05:00
|
|
|
|
2023-02-17 02:31:31 -05:00
|
|
|
int canderef (0);
|
|
|
|
if (_update_queued.compare_exchange_strong (canderef, 1)) {
|
2010-03-30 11:18:43 -04:00
|
|
|
gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this));
|
2010-01-31 22:33:52 -05:00
|
|
|
}
|
2010-01-06 16:56:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-31 22:33:52 -05:00
|
|
|
MidiTracer::update ()
|
2010-01-06 16:56:23 -05:00
|
|
|
{
|
2010-01-31 22:33:52 -05:00
|
|
|
bool updated = false;
|
2023-02-17 02:31:31 -05:00
|
|
|
_update_queued.store (0);
|
2010-01-31 22:33:52 -05:00
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
RefPtr<TextBuffer> buf (text.get_buffer());
|
|
|
|
|
|
|
|
int excess = buf->get_line_count() - line_count_adjustment.get_value();
|
|
|
|
|
|
|
|
if (excess > 0) {
|
|
|
|
buf->erase (buf->begin(), buf->get_iter_at_line (excess));
|
|
|
|
}
|
|
|
|
|
2010-01-31 22:33:52 -05:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
while (fifo.read (&str, 1)) {
|
|
|
|
buf->insert (buf->end(), string (str));
|
|
|
|
buffer_pool.release (str);
|
|
|
|
updated = true;
|
|
|
|
}
|
2010-01-06 16:56:23 -05:00
|
|
|
|
2010-01-31 22:33:52 -05:00
|
|
|
if (updated && autoscroll) {
|
2010-01-06 16:56:23 -05:00
|
|
|
scroller.get_vadjustment()->set_value (scroller.get_vadjustment()->get_upper());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTracer::base_toggle ()
|
|
|
|
{
|
|
|
|
show_hex = !base_button.get_active();
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:19:59 -05:00
|
|
|
void
|
|
|
|
MidiTracer::delta_toggle ()
|
|
|
|
{
|
|
|
|
show_delta_time = delta_time_button.get_active();
|
|
|
|
}
|
|
|
|
|
2010-01-06 16:56:23 -05:00
|
|
|
void
|
|
|
|
MidiTracer::collect_toggle ()
|
|
|
|
{
|
|
|
|
if (collect_button.get_active ()) {
|
2010-07-06 20:40:58 -04:00
|
|
|
port_changed ();
|
2010-01-06 16:56:23 -05:00
|
|
|
} else {
|
|
|
|
disconnect ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTracer::autoscroll_toggle ()
|
|
|
|
{
|
|
|
|
autoscroll = autoscroll_button.get_active ();
|
|
|
|
}
|