-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollidingTrack.sc
82 lines (68 loc) · 1.93 KB
/
CollidingTrack.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
/*
Colliding, a simple SuperCollider environment for learning and live coding
(c) Gerard Roma, 2013-2019
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
CollidingTrack{
var <>str, <>synth, <playing = false,compiled;
var parsed = false;
var spec, <>name, <vol;
var <>tab;
*new{^super.new.init}
init{
synth = NodeProxy.new;
synth.fadeTime_(0.2);
spec = \db.asSpec;
}
parse{|str|
str = str.compile;
^str;
}
playStr{|str|
synth.source = str;
synth.play;
if(playing.not){
playing=true;
}
}
play{|name|
synth = Synth(name,[\key, 60, \freq, 400, \amp, 0.5, \gate, 1]);
}
playNote{|name, note, velocity|
synth = Synth(name,[\key, note, \freq, note.midicps, \amp, velocity / 127.0, \gate, 1]);
^synth;
}
stop{
synth.free;
}
vol_{|val|
synth.set(\amp, spec.map(val).dbamp);
}
makeDefStr{|str, name, play|
var defStr;
var ampVal = spec.map(this.tab.volumeSlider.value).dbamp;
defStr = "SynthDef('" ++ name.asSymbol ++ "', {|key=60,freq=400,gate=0,amp=" ++ ampVal ++ "| ";
if(play){
defStr = defStr + str + " }).play(Server.internal); ";
}{
defStr = defStr + str +" }).send(Server.internal); ";
};
^defStr;
}
makeDef{|defStr, name, play = false|
var def = defStr.compile.value;
if(play){synth.free;synth = def};
this.name = name;
^def;
}
}