«KickandBass» by Scott L Simon

on 05 Jan'19 06:16 in guipatternssynth

Another small GUI performance module. Builds on a 303 from the helpfiles with a few changes.

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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//evaluate this block first 1.  You need to add a path to a kick here...
(
~b=Bus.audio(s,2);



 ~path="";
~buff=Buffer.read(s,~path);

)

//tests....
~path.value;

~buff.play;
~buff.plot;
~buff.value;
~buff.numFrames;

//evaluate this block 2.  Synths....
(
SynthDef(\PlayBufz, {| out = 0, bufnum = 0, amp = 1 |
    Out.ar(out,
        PlayBuf.ar(2, ~buff, BufRateScale.kr(1), doneAction: Done.freeSelf)*amp
    )
}).add;





SynthDef(\bass, { |out, freq = 440, gate = 1, amp = 0.4, slideTime = 0.17, ffreq = 1100, width = 0.15,
        detune = 1.005, preamp = 4, freqHi|
    var    sig,
        env = Env.adsr(0.01, 0.3, 0.4, 0.1);
    freq = Lag.kr(freq, slideTime);
    sig = Mix(VarSaw.ar([freq, freq * detune], 0, width, preamp)).distort * amp
        * EnvGen.kr(env, gate, doneAction: Done.freeSelf);
	sig = Resonz.ar(sig, VarLag.kr(ffreq,0.3));
	//freqHi = Linlin.ar(ffreq,20,2000,200,20000).poll;
    Out.ar(out, sig ! 2)
}).add;
)



//evaluate this block 3.
(
~ffreq= 200;
~amp = 1;

x = Pmono(\bass,
        \midinote, Prand([36, 39, 36, 42], 4),
        \dur, Pseq([0.75,0.75], 4),
        \amp, 0.3, \detune, 1.005,
		\ffreq, Pfunc({~ffreq})
    );

t = Pmono(\bass,
        \midinote, Prand([36, 42, 41, 33], 4),
        \dur, Pseq([0.25, 0.25, 0.25, 0.75], 4),
        \amp, 0.3, \detune, 1.003,
	\ffreq, Pfunc({~ffreq}*1.6)
    );

z = Pbind(
        \instrument, \PlayBufz,

        \dur, Pseq([0.75,0.75], inf),
	\amp, Pfunc({~amp})
);

TempoClock.default.tempo = 128/60;

)

//evaluate this last 4.  GUI.

(
var bb,cc, dd, text, pt, r, u, mx=0, my=0;
~amp = 1;
TempoClock.default.tempo = 128/60;



w = Window.new("buttontest",Rect(100,100,450,350));
w.view.background = Color(0.8,0.0,01);

u = UserView(w, Rect(300, 200,100, 100));
u.background = Color.black;
u.animate = true;
pt = Point();
r = Rect();

//w.view.decorator = FlowLayout(w.view.bounds);

bb = Button(w, Rect(60, 20, 40, 30))
        .states_([
            ["on", Color.black, Color.red],
            ["off", Color.white, Color.black]

        ])
        .action_({ arg zz;

	zz.value.postln;
	if(zz.value == 1){c = Ppar([z,Prand([t,x],inf)],inf).play;};
	if(zz.value == 0){c.stop};
        });

g=EZSlider(w,Rect(10,80,390,20),"Freq",ControlSpec(20,2000,\exp,0.001,200),{|ez| ~ffreq = ez.value;ez.value.postln},numberWidth: 60);



text = StaticText.new(w,Rect(100,200,200,200)).string_("kick on / off = kik\ncutoff = freq\nspeed = norm");
text.font = Font("Monaco", 13);
cc = Button(w, Rect(200, 20, 40, 30))
        .states_([
            ["kik", Color.green, Color.red],
            ["off", Color.blue, Color.white]

        ])
        .action_({ arg zz;
	if(zz.value == 0){~amp = 1};
	if(zz.value == 1){~amp = 0};
        });


dd = Button(w, Rect(60, 140, 40, 30))
        .states_([
            ["norm", Color.black, Color.green],
            ["slo", Color.black, Color.green],
	["slo2", Color.black, Color.green]

        ])
        .action_({ arg zz;
	if(zz.value == 0){TempoClock.default.tempo = 128/60;};
	if(zz.value == 1){TempoClock.default.tempo = 110/60;};
	if(zz.value == 2){TempoClock.default.tempo = 60/60;};
        });



u.drawFunc = {
    Pen.fillColor = Color.red;

    Pen.color = Color.white;
    pt.x=mx;
    pt.y=my;
    100.do{|i|
        Pen.moveTo(pt);
        pt.x = sin(u.frame*0.1.neg+i)*(5*i)+mx; //use .frame to drive animation
        pt.y = cos(u.frame*0.4+i)*(5*i)+my;
        r.left=pt.x;
        r.top=pt.y;
		r.width=sin(u.frame*0.1);
        r.height=i;
        Pen.lineTo(pt);
        Pen.fillStroke;
        Pen.addOval(r);
        Pen.fillStroke;
    };
};
w.front;
)
raw 3765 chars (focus & ctrl+a+c to copy)
reception
comments