11// 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
33
44// the grid in the upper left gives control of pitches from
55// the single most likely (cyan) to least likely (pink).
99
1010// model predictions are conditioned on performed timing and velocity.
1111
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+
1215(
1316~use_linn = true ; // use linnstrument
1417~gui = false ; // use keyboard GUI
@@ -33,7 +36,7 @@ Server.default.options.outDevice_("Built-in Output");
3336 {y==2 }{x*4 +16 }
3437 {y==3 }{x*8 +40 }
3538 {y==4 }{127 -x};
36- idx.postln;
39+ // idx.postln;
3740 ~midi_handle .(amp*127 , idx);
3841 }{
3942 case
@@ -85,13 +88,13 @@ SynthDef(\pluck, {
8588
8689// measure round-trip latency
8790(
88- OSCdef (\return , {
91+ OSCdef (\test , {
8992 arg msg, time, addr, recvPort;
9093 (Process .elapsedTime - t).postln;
9194}, '/prediction' , nil );
9295t = 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 );
9598)
9699
97100// set the delay for more precise timing
@@ -104,17 +107,16 @@ b.sendMsg("/predictor/predict",
104107// model chooses pitches
105108(
106109~gate = 1 ;
110+ ~instrument = 57 ;
107111
108112~model_reset = {
109- ~last_pitch = nil ;
113+ ~last_pitch = 60 ;
110114 ~last_dt = nil ;
111115 ~last_vel = nil ;
112116 t = Process .elapsedTime;
113- b.sendMsg("/predictor /reset" );
117+ b.sendMsg("/notochord /reset" );
114118 y!?{y.free};
115119 y = nil ;
116- b.sendMsg("/predictor/predict" , \pitch , 128 , \time , 0 , \vel , 0 );
117-
118120};
119121
120122~model_reset .();
@@ -128,7 +130,7 @@ MIDIdef.program(\switch, {
128130 {3 }{
129131 ~gate = 0 ;
130132 SystemClock .clear;
131- b.sendMsg("/predictor /reset" );
133+ b.sendMsg("/notochord /reset" );
132134 y.release;
133135 SystemClock .clear;
134136 };
@@ -151,13 +153,17 @@ MIDIdef.program(\switch, {
151153 // get a new prediction in light of last note,
152154 // fixing dt and vel to performed values so just pitch is predicted
153155 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 );
157161 }{
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 );
161167 };
162168
163169 ~last_dt = dt;
@@ -174,9 +180,10 @@ MIDIdef.program(\switch, {
174180// OSC return from python
175181OSCdef (\return , {
176182 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
180187
181188 // store the pitch and immediately set (unless there is no synth,
182189 // indicating this is the first note)
@@ -192,7 +199,4 @@ OSCdef(\return, {
192199
193200~model_reset .()
194201// 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