File: VSTPluginMIDIProxy.sc

package info (click to toggle)
pd-vstplugin 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,008 kB
  • sloc: cpp: 22,794; lisp: 2,860; makefile: 37; sh: 26
file content (170 lines) | stat: -rw-r--r-- 3,875 bytes parent folder | download
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// mimicks MIDIOut
VSTPluginMIDIProxy {
	var <>owner;
	// dummy variable for backwards compatibility with \midi Event type (use \vst_midi instead!)
	var <>uid;

	*new { arg theOwner;
		^super.new.owner_(theOwner);
	}

	// dummy setter/getter for compatibility with MIDIOut
	latency { ^0; }

	latency_ {
		"Calling 'latency' on VSTPluginMIDIProxy has no effect.\n"
		"If you want to schedule MIDI messages on the Server, use Server.bind or similar methods.".warn;
		^this;
	}

	write { arg len, hiStatus, loStatus, a=0, b=0, detune;
		owner.sendMidi(hiStatus bitOr: loStatus, a, b, detune);
	}

	writeMsg { arg len, hiStatus, loStatus, a=0, b=0, detune;
		^owner.sendMidiMsg(hiStatus bitOr: loStatus, a, b, detune);
	}

	noteOn { arg chan, note=60, veloc=64;
		this.write(3, 16r90, chan.asInteger, note.asInteger, veloc.asInteger, note.frac * 100);
	}

	noteOnMsg { arg chan, note=60, veloc=64;
		^this.writeMsg(3, 16r90, chan.asInteger, note.asInteger, veloc.asInteger, note.frac * 100);
	}

	noteOff { arg chan, note=60, veloc=64;
		this.write(3, 16r80, chan.asInteger, note.asInteger, veloc.asInteger, note.frac * 100);
	}

	noteOffMsg { arg chan, note=60, veloc=64;
		^this.writeMsg(3, 16r80, chan.asInteger, note.asInteger, veloc.asInteger, note.frac * 100);
	}

	polyTouch { arg chan, note=60, val=64;
		this.write(3, 16rA0, chan.asInteger, note.asInteger, val.asInteger);
	}

	polyTouchMsg { arg chan, note=60, val=64;
		^this.writeMsg(3, 16rA0, chan.asInteger, note.asInteger, val.asInteger);
	}

	control { arg chan, ctlNum=7, val=64;
		this.write(3, 16rB0, chan.asInteger, ctlNum.asInteger, val.asInteger);
	}

	controlMsg { arg chan, ctlNum=7, val=64;
		^this.writeMsg(3, 16rB0, chan.asInteger, ctlNum.asInteger, val.asInteger);
	}

	program { arg chan, num=1;
		this.write(2, 16rC0, chan.asInteger, num.asInteger);
	}

	programMsg { arg chan, num=1;
		^this.writeMsg(2, 16rC0, chan.asInteger, num.asInteger);
	}

	touch { arg chan, val=64;
		this.write(2, 16rD0, chan.asInteger, val.asInteger);
	}

	touchMsg { arg chan, val=64;
		^this.writeMsg(2, 16rD0, chan.asInteger, val.asInteger);
	}

	bend { arg chan, val=8192;
		val = val.asInteger;
		this.write(3, 16rE0, chan, val bitAnd: 127, val >> 7);
	}

	bendMsg { arg chan, val=8192;
		val = val.asInteger;
		^this.writeMsg(3, 16rE0, chan, val bitAnd: 127, val >> 7);
	}

	allNotesOff { arg chan;
		this.control(chan, 123, 0);
	}

	allNotesOffMsg { arg chan;
		^this.controlMsg(chan, 123, 0);
	}

	smpte	{ arg frames=0, seconds=0, minutes=0, hours=0, frameRate = 3;
		var packet;
		packet = [frames, seconds, minutes, hours]
			.asInteger
			.collect({ arg v, i; [(i * 2 << 4) | (v & 16rF), (i * 2 + 1 << 4) | (v >> 4) ] });
		packet = packet.flat;
		packet.put(7, packet.at(7) | ( frameRate << 1 ) );
		packet.do({ arg v; this.write(2, 16rF0, 16r01, v); });
	}

	// smpteMsg not practicable
	songPtr { arg songPtr;
		songPtr = songPtr.asInteger;
		this.write(4, 16rF0, 16r02, songPtr & 16r7f, songPtr >> 7 & 16r7f);
	}

	songPtrMsg { arg songPtr;
		songPtr = songPtr.asInteger;
		^this.writeMsg(4, 16rF0, 16r02, songPtr & 16r7f, songPtr >> 7 & 16r7f);
	}

	songSelect { arg song;
		this.write(3, 16rF0, 16r03, song.asInteger);
	}

	songSelectMsg { arg song;
		^this.writeMsg(3, 16rF0, 16r03, song.asInteger);
	}

	midiClock {
		this.write(1, 16rF0, 16r08);
	}

	midiClockMsg {
		^this.writeMsg(1, 16rF0, 16r08);
	}

	start {
		this.write(1, 16rF0, 16r0A);
	}

	startMsg {
		^this.writeMsg(1, 16rF0, 16r0A);
	}

	continue {
		this.write(1, 16rF0, 16r0B);
	}

	continueMsg {
		^this.writeMsg(1, 16rF0, 16r0B);
	}

	stop {
		this.write(1, 16rF0, 16r0C);
	}

	stopMsg {
		^this.writeMsg(1, 16rF0, 16r0C);
	}

	reset {
		this.write(1, 16rF0, 16r0F);
	}

	resetMsg {
		^this.writeMsg(1, 16rF0, 16r0F);
	}

	sysex { arg packet;
		owner.sendSysex(packet);
	}

	sysexMsg { arg packet;
		^owner.sendSysexMsg(packet);
	}
}