クラスの作成方法。
http://www.local-guru.net/blog/2009/01/17/modularizing-chuck-files


Blue Monday。一部変更したけど、ほぼ原型まま。
(2009/05/02修正: gainが5だったのを1に修正)

class DrumSet {
	// define hihat
	Shakers hhs => JCRev r;
	.025 => r.mix;
	Std.mtof(76) => hhs.freq;
	
	// define bass drum
	SinOsc s => ADSR bda;
	80 => s.freq;
	(0::ms, 10::ms, 0.0, 0::ms) => bda.set;
	
	// define snare drum
	Noise n => ADSR sna => Gain g => dac;
	1 => g.gain;
	(0::ms, 25::ms, 0.0, 0::ms) => sna.set;
	
	public void connect(UGen ugen) {
		r => ugen;
		bda => ugen;
		g => ugen;
	}
	
	public void hh() {
		1 => hhs.noteOn;
	}
	
	public void bd() {
		1 => bda.keyOn;
	}
	
	public void sn() {
		1 => sna.keyOn;
	}
}

class Bass {
	SawOsc sb => LPF filt => ADSR a => Gain g2;
	440 => filt.freq;
	0.3 => filt.Q;
	0.0 => g2.gain;
	(10::ms, 45::ms, 0.5, 40::ms) => a.set;
	
	public void connect(UGen u) {
		g2 => u;
	}
	
	public void bass(int tone) {
		Std.mtof(tone) =>  sb.freq;
		1 => g2.gain;
		1 => a.keyOn;
		125::ms => now;
		1 => a.keyOff;
	}
}

// this synchronizes to period
1::minute / 135 => dur DUR_4BEAT;
DUR_4BEAT * 4 => dur DUR_BAR;
DUR_4BEAT / 4 => dur DUR_16BEAT;
DUR_BAR - (now % DUR_BAR) => now;

DrumSet drm;
drm.connect(dac);

Bass bass;
bass.connect(dac);

[41, 41, 44, 46] @=> int bline[];
0 => int pos;

for (0 => int count; ; 1 +=> count) {	
	if (count != 0 && count % 8 == 0) { 1 + pos => pos; }
	
	if (count % 2 == 0) { drm.hh(); }
	if (count % 8 == 0) { drm.bd(); }
	if (count % 8 == 4) { drm.sn(); }
	
	if (count % 4 == 0) { spork ~ bass.bass(bline[pos % 4]); }
	if (count % 4 == 2) { spork ~ bass.bass(12 + bline[pos % 4]); }
	
	DUR_16BEAT => now;
}


せっかくなので作ったフィルイン。小節単位で同期されるので、適当なタイミングでaddすればよい。

// this synchronizes to period
1::minute / 135 => dur DUR_4BEAT;
DUR_4BEAT * 4 => dur DUR_BAR;
DUR_4BEAT / 4 => dur DUR_16BEAT;
DUR_BAR - (now % DUR_BAR) => now;

DrumSet drm;
drm.connect(dac);

[
1, 1, 1, 1, 1, 0, 1, 0,  
1, 1, 1, 1, 1, 0, 1, 1,  
1, 1, 1, 0, 1, 1, 1, 1, 
1, 0, 0, 0, 0, 0, 0, 0 
]
@=> int fillin[];

for (0 => int count; count < 32; 1 +=> count) {	
	if (fillin[count % 32]) {
		drm.sn();
	}
	DUR_16BEAT => now;
}

miniAudicleでクラスだけロードするのはどうしたら良いものか。。