Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit 7367944

Browse files
linnstrument interface for autopitch
1 parent bba7a2b commit 7367944

1 file changed

Lines changed: 65 additions & 9 deletions

File tree

examples/notepredictor/autopitch.scd

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,63 @@
11
(
2-
~gui = false;
2+
~use_linn = true; // use linnstrument
3+
~gui = false; // use keyboard GUI
34
MIDIIn.connectAll;
45
b = NetAddr.new("127.0.0.1", 9999);
56
Server.default.options.inDevice_("Built-in Microph");
67
Server.default.options.outDevice_("Built-in Output");
78
// Server.default.options.inDevice_("mic-buds");
89
// Server.default.options.outDevice_("mic-buds");
9-
s.boot;
1010
~gui.if{
1111
k = MIDIKeyboard.new(bounds: Rect(0, 0, 500, 100), octaves:11, startnote:0)
1212
};
13+
~linn_reset = {
14+
~linn.allLightsOff;
15+
~linn.setNoteOnAction({arg x,y,degree,freq,amp;
16+
var idx;
17+
[x,y,amp].postln;
18+
(y<5).if{
19+
idx = case
20+
{y==0}{x}
21+
{y==1}{x*2+5}
22+
{y==2}{x*4+16}
23+
{y==3}{x*8+40}
24+
{y==4}{127-x};
25+
idx.postln;
26+
~midi_handle.(amp*127, idx);
27+
}{
28+
case
29+
{x==0}{
30+
\sample.postln;
31+
~midi_handle.(amp*127, nil);}
32+
{x==2}{
33+
\reset.postln;
34+
~model_reset.()
35+
}
36+
}
37+
});
38+
~linn.lightOn(0,0,4); //0
39+
4.do{arg x; ~linn.lightOn(x+1,0,3)}; //1-4
40+
5.do{arg x; ~linn.lightOn(x, 1, 10)}; //5-13
41+
5.do{arg x; ~linn.lightOn(x, 2, 2)}; //16-32
42+
5.do{arg x; ~linn.lightOn(x, 3, 9)}; //40-72
43+
~linn.lightOn(0,4,11); //127
44+
4.do{arg x; ~linn.lightOn(x+1,4,1)}; //126-123
45+
46+
~linn.lightOn(0, 6, 8); // sample
47+
~linn.lightOn(2, 6, 2); // reset
48+
49+
50+
};
51+
s.waitForBoot{
52+
~use_linn.if{
53+
~linn = IILinnstrument.new(nil);
54+
~linn_reset.();
55+
}
56+
};
1357
)
1458

59+
// ~linn_reset.()
60+
1561
(
1662
SynthDef(\pluck, {
1763
var vel = \vel.kr;
@@ -22,6 +68,8 @@ SynthDef(\pluck, {
2268
}).add
2369
)
2470

71+
// ~linn.setNoteOnAction({}); ~linn.setNoteOffAction({});
72+
2573

2674
// measure round-trip latency
2775
(
@@ -77,7 +125,7 @@ MIDIdef.program(\switch, {
77125

78126

79127
// MIDI from controller
80-
MIDIdef.noteOn(\input, {
128+
~midi_handle = {
81129
arg vel, pitch, chan, src;
82130
var t2 = Process.elapsedTime;
83131
var dt = t2-(t?t2); //time since last note
@@ -90,16 +138,26 @@ MIDIdef.noteOn(\input, {
90138

91139
// get a new prediction in light of last note,
92140
// fixing dt and vel to performed values so just pitch is predicted
93-
b.sendMsg("/predictor/predict",
94-
\pitch, ~last_pitch, \time, ~last_dt, \vel, ~last_vel,
95-
\index_pitch, pitch, \fix_time, dt, \fix_vel, vel);
141+
pitch.notNil.if{
142+
b.sendMsg("/predictor/predict",
143+
\pitch, ~last_pitch, \time, ~last_dt, \vel, ~last_vel,
144+
\index_pitch, pitch, \fix_time, dt, \fix_vel, vel);
145+
}{
146+
b.sendMsg("/predictor/predict",
147+
\pitch, ~last_pitch, \time, ~last_dt, \vel, ~last_vel,
148+
\fix_time, dt, \fix_vel, vel);
149+
};
96150

97151
~last_dt = dt;
98152
~last_vel = vel;
99153

100154
// mark time of current note
101155
t = t2;
102-
});
156+
};
157+
158+
~use_linn.not.if{
159+
MIDIdef.noteOn(\input, ~midi_handle);
160+
};
103161

104162
// OSC return from python
105163
OSCdef(\return, {
@@ -124,7 +182,5 @@ OSCdef(\return, {
124182
// send a note manually if you don't have a midi controller
125183
MIDIdef.all[\input].func.(64, 16) //velocity, "pitch"
126184

127-
"abc"+0
128-
129185
// load another model
130186
// b.sendMsg("/predictor/load", "/path/to/checkpoint");

0 commit comments

Comments
 (0)