-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGranulizer.sc
130 lines (115 loc) · 4.03 KB
/
Granulizer.sc
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
Granulizer : Object {
var <> deviceName;
var <> deviceIndex;
var <> knobs;
var <> knobOffset;
var <> notes;
var <> synth;
var <> gainIndex;
var <> posIndex;
var <> rateIndex;
var <> durIndex;
var <> panIndex;
var <> bufferOffset;
var <> buffers;
var <> buffer;
var <> synth;
classvar <> knobMap;
*initClass{
Granulizer.knobMap = ['gain','pos','posJitter','rate','dur','pan','panJitter','reverb'];
}
init{
Server.default.waitForBoot({
this.deviceName = "MIDIEndPoint(\"Launchkey Mini\", \"Launchkey Mini MIDI 1\")";
this.deviceIndex;
this.knobOffset = 21;
this.notes = [60];
this.synth;
this.gainIndex = 0;
this.posIndex = 1;
this.rateIndex = 2;
this.durIndex = 3;
this.panIndex = 4;
this.bufferOffset = 36;
this.buffers=0!8;
this.buffer =0;
// fml
this.buffers[0] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/1.wav", channels:[0]);
this.buffers[1] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/2.wav", channels:[0]);
this.buffers[2] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/3.wav", channels:[0]);
this.buffers[3] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/4.wav", channels:[0]);
this.buffers[4] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/5.wav", channels:[0]);
this.buffers[5] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/6.wav", channels:[0]);
this.buffers[6] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/7.wav", channels:[0]);
this.buffers[7] = Buffer.readChannel(Server.default, Platform.userAppSupportDir++"/Extensions/Granulizer/samples/8.wav", channels:[0]);
"Sample buffers loaded.".postln;
this.synthDef();
"SynthDef loaded.".postln;
});
}
*new{
^super.new.init();
}
midi {
var f;
MIDIClient.init();
MIDIClient.sources.do{
|i,index|
if(i.asString==this.deviceName,{this.deviceIndex=index});
};
f = {
MIDIIn.connect(inport:this.deviceIndex,device:MIDIClient.sources.at(this.deviceIndex));
MIDIdef(\granulizer_cc,{
|val,nm,chan,src|
var knob = Granulizer.knobMap[nm-this.knobOffset];
var value = val/127;
[knob, value, nm, chan, src].postln;
this.synth.set(knob, value);
},msgType:\control).permanent_(true);
MIDIdef(\granulizer_note_noteOn,{
|val,nm,chan,src|
[val,nm,chan,src].postln;
this.synth.set(\freq, nm.midicps);
},msgType:\noteOn,chan:8).permanent_(true);
MIDIdef(\granulizer_note_noteOff,{
|val,nm,chan,src|
[val,nm,chan,src].postln;
},msgType:\noteOff, chan:8).permanent_(true);
MIDIdef(\granulizer_buffer_choose_noteOn,{
|val,nm,chan,src|
[val,nm,chan,src].postln;
this.buffer=nm-this.bufferOffset;
this.synth.set('bufnum', this.buffers[this.buffer]);
},msgType:\noteOn, chan:9).permanent_(true);
"Granulizer MidiDefs added.".postln;
};
f.value();
}
start {
this.synth = Synth.new(\granulizer,[bufnum:this.buffers[this.buffer]]);
}
synthDef {
SynthDef(\granulizer,{
|gain=0.2,pos=0, posJitter=0,rate=1,dur=0.5, pan=0.5, panJitter=0, reverb=0, bufnum, freq=261|
var audio = TGrains.ar(
2,
trigger:Impulse.kr(rate*rate*32),
bufnum:bufnum,
rate:(freq.cpsmidi-60).midiratio,
centerPos:((pos)+WhiteNoise.kr(mul:posJitter*posJitter*posJitter).range(-1,1))*BufDur.kr(bufnum),
dur: dur*dur*2,
pan: ((2*pan)-1) + ((WhiteNoise.kr(mul:panJitter).range(0,1)*2)-1)
)*gain;
// var rv = FreeVerb.ar(audio,mix:0,room:0.9,mul:reverb)+audio;
Out.ar(0, audio);
}).add;
}
play {
this.synth = {
var audio = TGrains.ar(1, trigger:Impulse.kr(this.knobs[this.durIndex]), bufnum:this.buffers[this.buffer], rate:(this.note-60).midiratio,centerPos:0,dur:this.knobs[this.durIndex], pan:this.knobs[this.panIndex]);
Out.ar(0, audio);
};
this.synth.play;
^this.synth;
}
}