Debian Codegraph @

examples/class/dinky.ck

raw
1 // this class defines the Dinky instrument
2 // the variables defined at class level are member variables
3 //
4 // to test this:
5 // > chuck dinky.ck try.ck
6 //
7 // NOTE (2003): in a future version of chuck...
8 // this class will be able to extend UGen
9 // NOTE (2013): the above is now possible using Chugraphs,
10 // Chugens, or Chugins!
11 // NOTE (2023): finally updated this example using Chugraphs
12
13 // the Dinky class
14 public class Dinky extends Chugraph
15 {
16 // impulse to filter to dac
17 Impulse i => BiQuad f => Envelope e => outlet;
18 // set the filter's pole radius
19 .99 => f.prad;
20 // set equal gain zeros
21 1 => f.eqzs;
22 // set filter gain
23 .2 => f.gain;
24 // set the envelope
25 .004::second => e.duration;
26
27 public void radius( float rad )
28 { rad => f.prad; }
29
30 public void connect( UGen ugen )
31 { e => ugen; }
32
33 // t is for trigger
34 public void t( float freq )
35 {
36 // set the current sample/impulse
37 1.0 => i.next;
38 // set filter resonant frequency
39 freq => f.pfreq;
40 // open the envelope
41 e.keyOn();
42 }
43
44 // t is for trigger (using MIDI note numbers)
45 public void t( int note )
46 { t( Std.mtof( note ) ); }
47
48 // another lazy name: c (for close)
49 public void c() { e.keyOff(); }
50 }