| 1 |
// um, by philipd |
| 2 |
// (what is it?) |
| 3 |
|
| 4 |
// base Player class |
| 5 |
class Player |
| 6 |
{ |
| 7 |
UGen @ base; |
| 8 |
fun void connect( UGen target ) |
| 9 |
{ |
| 10 |
base => target; |
| 11 |
} |
| 12 |
|
| 13 |
fun void noteOn ( float note, float vel ) {} |
| 14 |
fun void noteOff ( float vel ) {} |
| 15 |
} |
| 16 |
|
| 17 |
class Note |
| 18 |
{ |
| 19 |
float note; |
| 20 |
float vel; |
| 21 |
dur length; |
| 22 |
|
| 23 |
fun void set ( float nt, float vl, dur ln ) |
| 24 |
{ |
| 25 |
nt => note; |
| 26 |
vl => vel; |
| 27 |
ln => length; |
| 28 |
} |
| 29 |
|
| 30 |
fun void playOn ( Player p) |
| 31 |
{ |
| 32 |
if ( note > 0 ) |
| 33 |
{ |
| 34 |
p.noteOn( note , vel ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
fun void playOnAlt( Player p, float noff, float vmul ) |
| 39 |
{ |
| 40 |
p.noteOn( note+noff, vel*vmul ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
class MandPlayer extends Player |
| 46 |
{ |
| 47 |
Mandolin m @=> base; |
| 48 |
|
| 49 |
fun void noteOn ( float note, float vel ) |
| 50 |
{ |
| 51 |
Std.mtof ( note ) => m.freq; |
| 52 |
vel => m.pluck; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
class FlutePlayer extends Player |
| 57 |
{ |
| 58 |
PercFlut f @=> base; |
| 59 |
fun void noteOn ( float note, float vel ) |
| 60 |
{ |
| 61 |
Std.mtof ( note ) => f.freq; |
| 62 |
vel => f.noteOn; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
class ClarPlayer extends Player |
| 67 |
{ |
| 68 |
Clarinet c @=> base; |
| 69 |
fun void noteOn ( float note, float vel ) |
| 70 |
{ |
| 71 |
Std.mtof ( note ) => c.freq; |
| 72 |
vel => c.startBlowing; |
| 73 |
} |
| 74 |
fun void noteOff ( float vel ) |
| 75 |
{ |
| 76 |
vel => c.stopBlowing; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
// length of sequence |
| 81 |
12 => int seqn; |
| 82 |
// a sequence |
| 83 |
Note sequence[seqn]; |
| 84 |
// order |
| 85 |
int order[seqn]; |
| 86 |
// scale |
| 87 |
[0, 2, 4, 7, 9, 12, 14, 16, 19, 21] @=> int scale[]; |
| 88 |
// durations |
| 89 |
[0.25::second, 0.125::second, 0.125::second, 0.375::second] @=> dur times[]; |
| 90 |
|
| 91 |
// new sequence |
| 92 |
fun void newsequence() |
| 93 |
{ |
| 94 |
for( 0 => int i; i < seqn; i++ ) |
| 95 |
{ |
| 96 |
i => order[i]; |
| 97 |
55 + scale[Math.random2(0, scale.size() - 1)] => int note; |
| 98 |
times[Math.random2(0, times.size() - 1)] => dur mydur; |
| 99 |
Math.random2f( 0.75, 0.9 ) => float vel; |
| 100 |
sequence[i].set( note, vel, mydur ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
fun void swap( ) |
| 105 |
{ |
| 106 |
Math.random2(0,seqn-1) => int a; |
| 107 |
( a + Math.random2(1,seqn-1) ) % seqn => int b; |
| 108 |
order[a] => int tmp; |
| 109 |
order[b] => order[a]; |
| 110 |
tmp => order[a]; |
| 111 |
} |
| 112 |
|
| 113 |
// instantiate a mandolin player |
| 114 |
MandPlayer mand; |
| 115 |
// instantiate a clarinet player |
| 116 |
ClarPlayer clar; |
| 117 |
|
| 118 |
// effects |
| 119 |
Gain g => JCRev j => Echo e => dac; |
| 120 |
0.95 => j.gain; |
| 121 |
0.1 => j.mix; |
| 122 |
// set echo amount |
| 123 |
1.15::second => e.max; |
| 124 |
1.0::second => e.delay; |
| 125 |
0.3 => e.mix; |
| 126 |
|
| 127 |
// connect to effects |
| 128 |
mand.connect(g); |
| 129 |
// connect to effects |
| 130 |
clar.connect(g); |
| 131 |
|
| 132 |
// set gain |
| 133 |
0.6 => g.gain; |
| 134 |
|
| 135 |
// new sequence! |
| 136 |
newsequence(); |
| 137 |
|
| 138 |
// infinite time-loop |
| 139 |
while( true ) |
| 140 |
{ |
| 141 |
for( 0 => int j; j < seqn; j++ ) |
| 142 |
{ |
| 143 |
sequence[order[j]] @=> Note cur; |
| 144 |
cur.playOn ( mand ); |
| 145 |
cur.playOnAlt ( clar, 12 , 0.7 ); |
| 146 |
2.0 * cur.length => now; |
| 147 |
cur.playOnAlt( mand, 7, 0.33); |
| 148 |
cur.length => now; |
| 149 |
} |
| 150 |
|
| 151 |
for ( Math.random2(0,2) => int j ; j > 0 ; j-- ) |
| 152 |
swap(); |
| 153 |
|
| 154 |
if ( Math.random2(0, 10) > 8 ) |
| 155 |
newsequence(); |
| 156 |
} |