mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 08:14:58 +01:00
add a raw CoreMidi data debug mode
This commit is contained in:
parent
b687ed9339
commit
2d098c346a
1 changed files with 54 additions and 6 deletions
|
|
@ -24,28 +24,71 @@
|
||||||
|
|
||||||
using namespace ARDOUR;
|
using namespace ARDOUR;
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
static int _debug_mode = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void notifyProc (const MIDINotification *message, void *refCon) {
|
static void notifyProc (const MIDINotification *message, void *refCon) {
|
||||||
CoreMidiIo *self = static_cast<CoreMidiIo*>(refCon);
|
CoreMidiIo *self = static_cast<CoreMidiIo*>(refCon);
|
||||||
self->notify_proc(message);
|
self->notify_proc(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
static void print_packet (const MIDIPacket *p) {
|
||||||
|
fprintf (stderr, "CoreMIDI: Packet %d bytes [ ", p->length);
|
||||||
|
for (int bb = 0; bb < p->length; ++bb) {
|
||||||
|
fprintf (stderr, "%02x ", ((uint8_t*)p->data)[bb]);
|
||||||
|
}
|
||||||
|
fprintf (stderr, "]\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dump_packet_list (const UInt32 numPackets, MIDIPacket const *p) {
|
||||||
|
for (UInt32 i = 0; i < numPackets; ++i) {
|
||||||
|
print_packet (p);
|
||||||
|
p = MIDIPacketNext (p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void midiInputCallback(const MIDIPacketList *list, void *procRef, void *srcRef) {
|
static void midiInputCallback(const MIDIPacketList *list, void *procRef, void *srcRef) {
|
||||||
CoreMidiIo *self = static_cast<CoreMidiIo*> (procRef);
|
CoreMidiIo *self = static_cast<CoreMidiIo*> (procRef);
|
||||||
if (!self || !self->enabled()) {
|
if (!self || !self->enabled()) {
|
||||||
// skip while freewheeling
|
// skip while freewheeling
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (_debug_mode & 2) {
|
||||||
|
fprintf (stderr, "Ignored Midi Packet while freewheeling:\n");
|
||||||
|
dump_packet_list (list->numPackets, &list->packet[0]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RingBuffer<uint8_t> * rb = static_cast<RingBuffer < uint8_t > *> (srcRef);
|
RingBuffer<uint8_t> * rb = static_cast<RingBuffer < uint8_t > *> (srcRef);
|
||||||
if (!rb) return;
|
if (!rb) {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (_debug_mode & 4) {
|
||||||
|
fprintf (stderr, "Ignored Midi Packet - no ringbuffer:\n");
|
||||||
|
dump_packet_list (list->numPackets, &list->packet[0]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
MIDIPacket const *p = &list->packet[0];
|
MIDIPacket const *p = &list->packet[0];
|
||||||
for (UInt32 i = 0; i < list->numPackets; ++i) {
|
for (UInt32 i = 0; i < list->numPackets; ++i) {
|
||||||
uint32_t len = ((p->length + 3)&~3) + sizeof(MIDITimeStamp) + sizeof(UInt16);
|
uint32_t len = ((p->length + 3)&~3) + sizeof(MIDITimeStamp) + sizeof(UInt16);
|
||||||
if (rb->write_space() < sizeof(uint32_t) + len) {
|
#ifndef NDEBUG
|
||||||
fprintf(stderr, "CoreMIDI: dropped MIDI event\n");
|
if (_debug_mode & 1) {
|
||||||
continue;
|
print_packet (p);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
if (rb->write_space() > sizeof(uint32_t) + len) {
|
||||||
rb->write ((uint8_t*)&len, sizeof(uint32_t));
|
rb->write ((uint8_t*)&len, sizeof(uint32_t));
|
||||||
rb->write ((uint8_t*)p, len);
|
rb->write ((uint8_t*)p, len);
|
||||||
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
else {
|
||||||
|
fprintf (stderr, "CoreMIDI: dropped MIDI event\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
p = MIDIPacketNext (p);
|
p = MIDIPacketNext (p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +131,11 @@ CoreMidiIo::CoreMidiIo()
|
||||||
, _changed_arg (0)
|
, _changed_arg (0)
|
||||||
{
|
{
|
||||||
pthread_mutex_init (&_discovery_lock, 0);
|
pthread_mutex_init (&_discovery_lock, 0);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
const char *p = getenv ("COREMIDIDEBUG");
|
||||||
|
if (p && *p) _debug_mode = atoi (p);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreMidiIo::~CoreMidiIo()
|
CoreMidiIo::~CoreMidiIo()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue