1
1
// in this example the Linnstrument displays an interface to perform pitches
2
- // by their likelihood under the Notochord model instead of by MIDI number
2
+ // by their likelihood under the NotePredictor model instead of by MIDI number
3
3
4
4
// the grid in the upper left gives control of pitches from
5
5
// the single most likely (cyan) to least likely (pink).
9
9
10
10
// model predictions are conditioned on performed timing and velocity.
11
11
12
+ // TODO: this example is based an older, monophonic version of notochord without noteoffs
13
+ // it is hacked to work similarly wit Notochord v3, but could use an update
14
+
12
15
(
13
16
~use_linn = true ; // use linnstrument
14
17
~gui = false ; // use keyboard GUI
@@ -33,7 +36,7 @@ Server.default.options.outDevice_("Built-in Output");
33
36
{y==2 }{x*4 +16 }
34
37
{y==3 }{x*8 +40 }
35
38
{y==4 }{127 -x};
36
- idx.postln;
39
+ // idx.postln;
37
40
~midi_handle .(amp*127 , idx);
38
41
}{
39
42
case
@@ -85,13 +88,13 @@ SynthDef(\pluck, {
85
88
86
89
// measure round-trip latency
87
90
(
88
- OSCdef (\return , {
91
+ OSCdef (\test , {
89
92
arg msg, time, addr, recvPort;
90
93
(Process .elapsedTime - t).postln;
91
94
}, '/prediction' , nil );
92
95
t = Process .elapsedTime;
93
- b.sendMsg("/predictor /predict" ,
94
- \pitch , 60 +12 .rand, \time , 0 , \vel , 0 , \fix_time , 0 , \fix_vel , 0 );
96
+ b.sendMsg("/notochord /predict" ,
97
+ \inst , 257 , \ pitch , 60 +12 .rand, \time , 0 , \vel , 0 , \fix_time , 0 , \fix_vel , 0 );
95
98
)
96
99
97
100
// set the delay for more precise timing
@@ -104,17 +107,16 @@ b.sendMsg("/predictor/predict",
104
107
// model chooses pitches
105
108
(
106
109
~gate = 1 ;
110
+ ~instrument = 57 ;
107
111
108
112
~model_reset = {
109
- ~last_pitch = nil ;
113
+ ~last_pitch = 60 ;
110
114
~last_dt = nil ;
111
115
~last_vel = nil ;
112
116
t = Process .elapsedTime;
113
- b.sendMsg("/predictor /reset" );
117
+ b.sendMsg("/notochord /reset" );
114
118
y!?{y.free};
115
119
y = nil ;
116
- b.sendMsg("/predictor/predict" , \pitch , 128 , \time , 0 , \vel , 0 );
117
-
118
120
};
119
121
120
122
~model_reset .();
@@ -128,7 +130,7 @@ MIDIdef.program(\switch, {
128
130
{3 }{
129
131
~gate = 0 ;
130
132
SystemClock .clear;
131
- b.sendMsg("/predictor /reset" );
133
+ b.sendMsg("/notochord /reset" );
132
134
y.release;
133
135
SystemClock .clear;
134
136
};
@@ -151,13 +153,17 @@ MIDIdef.program(\switch, {
151
153
// get a new prediction in light of last note,
152
154
// fixing dt and vel to performed values so just pitch is predicted
153
155
pitch.notNil.if{
154
- b.sendMsg("/predictor/predict" ,
155
- \pitch , ~last_pitch , \time , ~last_dt , \vel , ~last_vel ,
156
- \index_pitch , pitch, \fix_time , dt, \fix_vel , vel);
156
+ b.sendMsg("/notochord/feed" ,
157
+ \inst , ~instrument , \pitch , ~last_pitch , \time , ~delay , \vel , ~last_vel );
158
+ b.sendMsg("/notochord/predict" ,
159
+ \inst , ~instrument , \pitch , ~last_pitch , \time , ~last_dt , \vel , 0 ,
160
+ \index_pitch , pitch, \fix_time , dt, \fix_vel , vel, \fix_instrument , ~instrument );
157
161
}{
158
- b.sendMsg("/predictor/predict" ,
159
- \pitch , ~last_pitch , \time , ~last_dt , \vel , ~last_vel ,
160
- \fix_time , dt, \fix_vel , vel);
162
+ b.sendMsg("/notochord/feed" ,
163
+ \inst , ~instrument , \pitch , ~last_pitch , \time , ~delay , \vel , ~last_vel );
164
+ b.sendMsg("/notochord/predict" ,
165
+ \inst , ~instrument , \pitch , ~last_pitch , \time , ~last_dt , \vel , 0 ,
166
+ \fix_time , dt, \fix_vel , vel, \fix_instrument , ~instrument );
161
167
};
162
168
163
169
~last_dt = dt;
@@ -174,9 +180,10 @@ MIDIdef.program(\switch, {
174
180
// OSC return from python
175
181
OSCdef (\return , {
176
182
arg msg, time, addr, recvPort;
177
- var pitch = msg[1 ]; // MIDI number of predicted note
178
- var dt = msg[2 ]; // time to predicted note
179
- var vel = msg[3 ]; // velocity 0-127
183
+ var inst = msg[1 ]; // MIDI number of predicted note
184
+ var pitch = msg[2 ]; // MIDI number of predicted note
185
+ var dt = msg[3 ]; // time to predicted note
186
+ var vel = msg[4 ]; // velocity 0-127
180
187
181
188
// store the pitch and immediately set (unless there is no synth,
182
189
// indicating this is the first note)
@@ -192,7 +199,4 @@ OSCdef(\return, {
192
199
193
200
~model_reset .()
194
201
// send a note manually if you don't have a midi controller
195
- MIDIdef .all[\input ].func.(64 , 16 ) //velocity, "pitch"
196
-
197
- // load another model
198
- // b.sendMsg("/predictor/load", "/path/to/checkpoint");
202
+ MIDIdef .all[\input ].func.(64 , 16 ) //velocity, "pitch"
0 commit comments