«radio tunner and harmonica» by grirgz

on 04 Feb'15 00:06 in

Maybe I should not post code which come directly from the SC documentation, but It's been years that I read this doc, I never listened to the code example of the SelectXFocus man page, and now I nearly fell off my chair, these gems are hidden in examples, this is awesome ! I can play for hours with this harmonica =) I like this playability with mouse. I've added a variation a the end using MouseButton to blow

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
// radio tuner
// (jrh) (cc 2006)
(
{
    var a, n, mx, my, mwrap;
    n = 8;
    mx = MouseX.kr(0, 1, 0, 0.1);
    my = MouseY.kr;
    mwrap = { |pmin, pmax, min, max| sin(mx * ExpRand(pmin, pmax)) + 1 * 0.5 * ExpRand(min, max) };
    a = {
        var freq, fmul, phase;
        freq = mwrap.(10, 40, 200, 5000) + ExpRand(200, 3000);
        fmul = LFNoise0.kr(ExpRand(0.1, 8)).round(1/6).exprange(1, Rand(1, 1.2));
        phase = LFNoise2.ar(mwrap.(1, 20, 10, 1000), Rand(2, 5));
        SinOsc.ar(freq * fmul, phase)
    } ! n;
    a = a.add(
        SinOsc.ar(LFDNoise0.kr(11, SetResetFF.kr(*Dust.kr([1, 2] * 0.3))).range(0, 700) + 220)
    );
    SelectXFocus.ar(mx * n, a, my * n) * 0.2 + OnePole.ar(PinkNoise.ar(0.5 ! 2), 0.4)
    * Line.kr(0, 1, 3);
}.play;
)


// jimmy played harmonica in the pub where I was born
// (hh) (jrh) (cc 2006)
(
{
    var blas, zieh, mx, my, trig, which, amp, u, schnauf;
    var del = 9, det = 0.1;
    schnauf = 0.3;
    mx = MouseX.kr;
    my = MouseY.kr(0.1, 2, 1);

    blas = [0, 12, 24] +.x [60, 64, 67] ++ [60+36];
    zieh = [62, 67, 71,   74, 77, 81, 83,   86, 89, 93];

    trig = Dust.kr(1);
    which = ToggleFF.kr(TDelay.kr(trig, schnauf));
    amp = EnvGen.kr(Env([1, 0, 1], [schnauf, schnauf]), trig);
    blas = Select.kr(which, [blas, zieh]);
    u = SelectXFocus.ar(
        mx * blas.size,
        blas.collect {|f|
            Pulse.ar((Rand(-0.04, 0.09) + f).midicps * 0.5, 0.48 + LFNoise1.kr(0.06, 0.1), 0.2)
        },
        my
    ) * Slope.kr(mx + my).abs.lag2(2) * amp;
    u = Pan2.ar(OnePole.ar(u, -0.3), mx * 2 - 1);
    DelayL.ar(BPF.ar(u * 2, 1500, 0.3), del + det, LFNoise2.kr(0.2, det, del)) + u
}.play;
);


// using MouseButton

(
{
    var blas, zieh, mx, my, trig, which, amp, u, schnauf;
    var del = 9, det = 0.1;
	var trig2;
	var sig;
    schnauf = 0.3;
    mx = MouseX.kr;
    my = MouseY.kr(0.1, 2, 1);

    blas = [0, 12, 24] +.x [60, 64, 67] ++ [60+36];
    zieh = [62, 67, 71,   74, 77, 81, 83,   86, 89, 93];

    trig = Dust.kr(1);
	which = MouseButton.kr(1,0,0.1);
	trig = Changed.kr(which, 0.0005);
	
    amp = EnvGen.kr(Env([1,1, 1.5, 0.8,0], [0.5, 0.5,0.5,0.5]), trig);
    blas = Select.kr(which.round(1), [blas, zieh]);
    u = SelectXFocus.ar(
        mx * blas.size,
        blas.collect {|f|
            Pulse.ar((Rand(-0.04, 0.09) + f).midicps * 0.5, 0.48 + LFNoise1.kr(0.06, 0.1), 0.2)
        },
        my
    ) * Slope.kr(mx + my).abs.lag2(2) * amp;
    u = Pan2.ar(OnePole.ar(u, -0.3), mx * 2 - 1);
    sig = DelayL.ar(BPF.ar(u * 2, 1500, 0.3), del + det, LFNoise2.kr(0.2, det, del)) + u;
}.play;
);
raw 2691 chars (focus & ctrl+a+c to copy)
reception
comments
lightrate user 21 Mar'17 13:02

line 73: Changed.kr(button) should be Changed.kr(witch)

56228375 user 30 Mar'17 20:32

correction on the correction: line73: Changed.kr(button, 0.0005) should be Changed.kr(which, 0.0005) (i.e. which instead of witch)

julian.rohrhuber user 04 May'17 21:24

yes, I added these eastereggs to improve the documentation. We should have more of such things, maybe even copy good short programs from sccode to the help system.

grirgz user 03 Jun'17 03:20

thanks for the correction! i've edited it. @julian yes my dream is to have so much code example that it create a base culture for every newcomer to grow even further into wonderful things! sccode is a very good start!