forked from danomatika/ofxPd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface_sketch.txt
191 lines (136 loc) · 4.29 KB
/
interface_sketch.txt
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
TYPES
// message primitives
Bang(string recvName)
Float(string recvName, float value)
Symbol(string recvName, string symbol)
// compound message
class List {
public:
unsigned int len(); // number of items
string types(); // OSC style type string ie "fssfffs"
// check type
bool isFloat(int index=-1)
bool isSymbol(int index=-1)
// get as type
float asFloat(int index=-1)
string asSymbol(int index=-1)
protected:
List(string dest, int length, t_atom *items)
addFloat(Float& f);
addSymbol(Symbol& s);
private:
string types;
unsigned int length;
t_atom *items;
};
// compound messages
StartList(string recvName)
StartMsg(string recvName, string symName)
// midi
Note(int pitch, int velocity, int channel=0)
ControlChange(int controller, int value, int channel=0)
ProgramChange(int program, int channel=0)
PitchBend(int value, int channel=0)
Aftertouch(int value, int channel=0)
PolyAftertouch(int pitch, int value, int channel=0)
// compound raw midi
StartMidi(int port=0)
StartSysex(int port=0)
StartSysexRealtime(int port=0)
// finish any compound message
Finish()
SENDING
// MESSAGES
// single messages
pd.sendBang("test");
pd.sendFloat("test", 100);
pd.sendSymbol("test", "symbol1");
pd << Bang("test") << Float("test", 100) << Symbol("test", "symbol1");
// compound messages
// send a list
//
// [ 100 292.99 c string (
// |
// [ s test (
//
pd.startList("test");
pd.addFloat(100);
pd.addFloat(292.99);
pd.addSymbol("c");
pd.addSymbol("string");
pd.finish();
pd << StartMessage("test") << 100 << 292.99 << 'c' << "string" << Finish();
// send a typed message
//
// [; pd dsp 1 (
//
pd.startMsg("pd", "dsp");
pd.addFloat(1);
pd.finish();
pd << StartMsg("pd", "dsp") << 1 << Finish();
// MIDI
// midi channels should be 1-16? ... same as patching
// note
pd.sendNote(60);
pd.sendNote(60, 100);
pd.sendNote(60, 100, 0);
pd << Note(60) << Note(60, 100) << Note(60, 100, 0);
// controls
pd << ControlChange(7, 100) << ControlChange(7, 100, 0); // 7 - Volume
pd << ProgamChange(40) << ProgramChange(40, 0); // 40 - Violin
pd << PitchBend(8000) << PitchBend(8000, 0); // value -8192 to 8192
pd << Aftertouch(100) << Aftertouch(100, 0);
pd << PolyAftertouch(60, 100) << PolyAftertouch(60, 100, 0);
// raw midi
// Noteon chan 0, Middle C, velocity
pd << StartMidi() << 0x90 << 0x3c << 0x40 << FinishBytes();
pd << StartSysex() << 0xF0 << 0x7D << 0xF7 << FinishBytes();
pd << StartSysexRealtime() << 0xF0 << 0x7D << 0xF7 << FinishBytes();
RECEIVING
public ofxPdListener {
public:
void printReceived(const std::string& message) {}
void bangReceived(string dest) {}
void floatReceived(string dest, float value) {}
void symbolReceived(string dest, string symbol) {}
void listReceived(string dest, const List& list) {}
void messageReceived(string dest, string msg, const List& list) {}
void noteReceived(int channel, int pitch, int velocity) {}
void controlChangeReceived(int channel, int controller, int val) {}
void programChangeReceived(int channel, int program) {}
void pitchbendReceived(int channel, int val) {}
void aftertouchReceived(int channel, int val) {}
void polyAftertouchReceived(int channel, int pitch, int val) {}
void midiByteReceived(int port, int byte) {}
void sysexReceived(int port, int byte) {}
void sysexRealtimeReceived(int port, int byte) {}
};
pd.addListener(listener); // add listener to global space
pd.addListener(listener, "source1");
pd.addSource("source1"); // add "test" source
pd.subscribe(listener, "source1"); // subscribe listener to "test",
// adds both if not already added,
// takes listener out of global space
pd.addSource("source2");
pd.subscribe(listener, "source2");
pd.unsubscribe(listener, "source2");
pd.unsubscribe(listener, "source1"); // unsubscribe listener to "test'
pd.unsubscribe(listener); // unsubscribes listener from all sources, global
pd.removeListener(listener); // removes listener from global space
ofxPdMsg msg;
msg.makeBang();
pd.sendMsg(msg); // bang, empty message
msg.makeFloat(float);
pd.sendMsg(msg); // float
msg.clear();
msg.
List list;
list << 100 << 292.99 << 'c' << "string";
pd.sendList("test", list);
pd.sendMsg("test", "pd", list);
pd.clear();
ofxPdBundle bundle;
bundle.add(msg);
ofxPdMidiMsg midi;
msp << StartMidi() << 0x90 << 0x3c << 0x40 << FinishBytes();
pd.sendMidi(midi);