«exhaustive MIDI debugger» by soundlake

on 21 Jul'21 16:58 in midi

Inspired by https://sccode.org/1-5co Written in 3.11.2.

All arguments are labeled. Source ID becomes more human-readable format; MIDIEndPoint.device and MIDIEndPoint.name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
MIDIClient.init;
MIDIIn.connectAll;
(
// List or comment out the message types to debug
~types = [
	"noteOn",
	"noteOff",
	"control",
	"touch",
	"polytouch",
	"bend",
	"program",
	"sysex",
	// System Common
	"smpte",
	"mtcQF",
	"songPosition",
	"songSelect",
	"tuneRequest",
	"midiClock",
	// System Realtime
	"sysrt",
	"tick",
	"start",
	"continue",
	"stop",
	"activeSense",
	"reset"
];

// Register sources
~sources = Dictionary.new;
MIDIClient.sources.do({ |mep|
	~sources.add(mep.uid -> mep.device.catArgs(", ", mep.name));
});

// Register the debugger
MIDIdef.freeAll;
~types.do({ |type|
	var key, func, msgType;

	key = (type + "Func").asSymbol;
	msgType = type.asSymbol;

	// Define the debugger funciton depend on the message type
	func = case
	{ [
		"noteOn",
		"noteOff",
		"control",
		"touch",
		"polytouch",
		"bend",
		"program",
	].includesEqual(type)} {{
		arg value, num, chan, srcID;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			"ch: 0x", chan.asHexString(2), ", ",
			"num: 0x", num.asHexString(2), ", ",
			"val: ", value
		).postln;
	}}
	{ type == "sysex" } {{
		arg data, srcID;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			", data: Int8Array", data.collect({ |n| "0x" ++ n.asHexString(2) })
		).postln;
	}}
	{ type == "smpte" } {{
		arg seconds, framerate, dropframe, srcID;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			"seconds: ", seconds, ", ",
			"framerate: ", framerate, ", ",
			"dropframe: ", dropframe
		).postln;
	}}
	{ type == "mtcQF" } {{
		arg data, srcID, pieceNumber;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			", pieceNumber: ", pieceNumber,
			", data: ", data
		).postln;
	}}
	{ type == "songPosition" } {{
		arg position, srcID;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			", position: ", position
		).postln;
	}}
	{ type == "songSelect" } {{
		arg song, srcID;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			", song: ", song
		).postln;
	}}
	{ [
		"tuneRequest",
		"midiClock",
		"tick",
		"start",
		"stop",
		"continue"
		"reset",
		"activeSense"
	].includesEqual(type) } {{
		arg srcID;
		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12)
		).postln;
	}}
	{ type == "sysrt" } {{
		arg data, srcID, index;
		var table;
		table = Dictionary.newFrom([
			1, "MIDI Time Code Quarter Frames",
			2, "Song Position",
			3, "Song Select",
			6, "Tune Request",
			8, "MIDI Clock",
			9, "Tick",
			10, "Start",
			11, "Continue",
			12, "Stop",
			14, "Active Sense",
			15, "Reset"
		]);

		~sources[srcID].catArgs(
			", ", (type ++ ",").padRight(12),
			", ", table[index]
		).postln;
	}}
	{ true } {{ arg ...args; args.postln }};

	MIDIdef.new(key, func, nil, nil, msgType);
})
)
raw 2909 chars (focus & ctrl+a+c to copy)
reception
comments
56228375 user 23 Jul'21 16:47

this is quite useful, but it has a typo on line 55

soundlake user 12 Aug'21 15:05

Thank you @56228375 the typo is fixed