File: ctrl_sequencer.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (156 lines) | stat: -rw-r--r-- 2,927 bytes parent folder | download | duplicates (3)
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
// um, by philipd
// (what is it?)

// base Player class
class Player
{ 
    UGen @ base;
    fun void connect( UGen target )
    {
        base => target;
    }

    fun void noteOn ( float note, float vel ) {}
    fun void noteOff ( float vel ) {}
}

class Note
{ 
    float note;
    float vel;
    dur length;

    fun void set ( float nt, float vl, dur ln )
    { 
        nt => note;
        vl => vel;
        ln => length;
    }

    fun void playOn ( Player p)
    { 
        if ( note > 0 )
        { 
            p.noteOn( note , vel );
        }
    }

    fun void playOnAlt( Player p, float noff, float vmul )
    {
        p.noteOn( note+noff, vel*vmul );
    }
}


class MandPlayer extends Player
{
    Mandolin m @=> base;

    fun void noteOn ( float note, float vel )
    { 
        Std.mtof ( note ) => m.freq;
        vel => m.pluck;
    }
}

class FlutePlayer extends Player
{ 
    PercFlut f @=> base; 
    fun void noteOn ( float note, float vel )
    { 
        Std.mtof ( note ) => f.freq;
        vel => f.noteOn;
    }
}

class ClarPlayer extends Player
{
    Clarinet c @=> base;
    fun void noteOn ( float note, float vel )
    { 
        Std.mtof ( note ) => c.freq;
        vel => c.startBlowing;
    }
    fun void noteOff ( float vel )
    { 
        vel => c.stopBlowing;
    }
}

// length of sequence
12 => int seqn;
// a sequence
Note sequence[seqn];
// order
int order[seqn];
// scale
[0, 2, 4, 7, 9, 12, 14, 16, 19, 21] @=> int scale[];
// durations
[0.25::second, 0.125::second, 0.125::second,  0.375::second] @=> dur times[];

// new sequence
fun void newsequence()
{ 
    for( 0 => int i; i < seqn; i++ )
    {
        i => order[i];		
        55 + scale[Math.random2(0, scale.size() - 1)] => int note;
        times[Math.random2(0, times.size() - 1)] => dur mydur;
        Math.random2f( 0.75, 0.9 ) => float vel; 
        sequence[i].set( note, vel, mydur );
    }
}

fun void swap( )
{ 
    Math.random2(0,seqn-1) => int a;
    ( a + Math.random2(1,seqn-1) ) % seqn => int b;
    order[a] => int tmp;
    order[b] => order[a];
    tmp => order[a];
}

// instantiate a mandolin player
MandPlayer mand;
// instantiate a clarinet player
ClarPlayer clar;

// effects
Gain g => JCRev j => Echo e => dac;
0.95 => j.gain;
0.1 => j.mix;
// set echo amount
1.15::second => e.max;
1.0::second => e.delay;
0.3 => e.mix;

// connect to effects
mand.connect(g);
// connect to effects
clar.connect(g);

// set gain
0.6 => g.gain;

// new sequence!
newsequence();

// infinite time-loop
while( true )
{
    for( 0 => int j; j < seqn; j++ )
    { 
        sequence[order[j]] @=> Note cur;
        cur.playOn ( mand );
        cur.playOnAlt ( clar, 12 , 0.7 );
        2.0 * cur.length => now;
        cur.playOnAlt( mand, 7, 0.33);
        cur.length => now;
    }

    for ( Math.random2(0,2) => int j ; j > 0 ; j-- )
        swap();

    if ( Math.random2(0, 10) > 8 )
        newsequence();
}