-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayloop.ck
80 lines (64 loc) · 1.83 KB
/
playloop.ck
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
"loop" => string loopname;
0 => int device;
if( me.args()>0 ) {
me.arg(0) => Std.atoi => device;
me.arg(1) => loopname;
}
FileRead.readString(loopname+"_instr","error") @=> string instrumentName;
MidiInstrument instrument;
if(instrumentName.lower()=="organ") {
new Organ @=> instrument;
} else if(instrumentName.lower()=="synth") {
new Synth @=> instrument;
} else if(instrumentName.lower()=="sax"){
new Saxophone @=> instrument;
}
else {
<<< "### NO INSTRUMENT SELECTED FOR LOOPER ",loopname,", ABORTING!! ###" >>>;
me.exit();
}
LoopRecorder lRec;
1 => int mute;
int measuresToRecord;
int measuresToPlay;
0 @=> int currentMeasure;
Looper loop;
instrument.setup();
instrument.setupMidi(device);
spork ~ instrument.startInstrument();
//<<< "before synchronize" >>>;
loop.synchronize();
//<<< "after synchronize" >>>;
Std.system("rm "+FileRead.pathWrapper.path+"/live/"+loopname+"_rec");
fun void instantHandler() {
while(true) {
FileRead.readInt(loopname+"_arm",1) @=> instrument.armed;
FileRead.readInt(loopname+"_vol",50)/100.0 => float volume;
volume => instrument.getGain().gain;
lRec.saveme.voiceGain(0,volume*2);
FileRead.readInt(loopname+"_rec",0) @=> measuresToRecord;
if(measuresToRecord>0) {
<<< "=== WILL RECORD NEXT ",measuresToRecord,"MEASURES ON ",loopname," ===" >>>;
1 @=> mute;
measuresToRecord @=> measuresToPlay;
lRec.recordFromGain(instrument.getGain(),measuresToRecord);
Std.system("rm "+FileRead.pathWrapper.path+"/live/"+loopname+"_rec");
}
100::ms => now;
}
}
spork ~ instantHandler();
while(true) {
if(!mute) {
<<< "% LOOPER ",loopname," NEW MEASURE ",currentMeasure >>>;
if(currentMeasure % measuresToPlay == 0) {
lRec.saveme.play(1);
lRec.saveme.playPos(0::ms);
}
currentMeasure++;
}
loop.advance(1);
if(lRec.finishedRecording==0 && lRec.measuresleft==0) {
0=>mute;
}
}