// drum_beat_lab.ck // copyright 2007 Les Hall // This code is protected by the GNU General Public License // Evaluates test expressions for creating drum beat sequences // parameters 1 => int snare; // select which snare to play // 1: kijjaz's kjzSnare101 with simple repetetive playing // 2: kijjaz's kjzSnare102 with simple repetetive playing 2 => int n; // counting base 8 => float notes_per_second; // the timing // many thanks to kijjaz (kijjaz@yahoo.com) for the snare code examples, rock on kijjaz! // easy white noise snare class kjzSnare101 { // note: connect output to external sources to connect Noise s => Gain s_env => LPF s_f => Gain output; // white noise source Impulse i => Gain g => Gain g_fb => g => LPF g_f => s_env; 3 => s_env.op; // make s envelope a multiplier s_f.set(3000, 4); // set default drum filter g_fb.gain(1.0 - 1.0/3000); // set default drum decay g_f.set(200, 1); // set default drum attack fun void setFilter(float f, float Q) { s_f.set(f, Q); } fun void setDecay(float decay) { g_fb.gain(1.0 - 1.0 / decay); // decay unit: samples! } fun void setAttack(float attack) { g_f.freq(attack); // attack unit: Hz! } fun void hit(float velocity) { velocity => i.next; } } kjzSnare101 A; A.output => dac; // with some approvements from 101: snare ringing in the body class kjzSnare102 { // note: connect output to external sources to connect Noise s => Gain s_env => LPF s_f => Gain output; // white noise source Impulse i => Gain g => Gain g_fb => g => LPF g_f => s_env; s_env => DelayA ringing => Gain ringing_fb => ringing => LPF ringing_f => output; 3 => s_env.op; // make s envelope a multiplier s_f.set(3000, 4); // set default drum filter g_fb.gain(1.0 - 1.0/3000); // set default drum decay g_f.set(200, 1); // set default drum attack ringing.max(second); ringing.delay((1.0 / 440) :: second); // set default: base ringing frequency = 440Hz ringing_fb.gain(0.35); // set default ringing feedback ringing_f.set(1500, 1); // set default ringing LPF ringing_f.gain(0.6); // set default ringing vol fun void setFilter(float f, float Q) { s_f.set(f, Q); } fun void setDecay(float decay) { g_fb.gain(1.0 - 1.0 / decay); // decay unit: samples! } fun void setAttack(float attack) { g_f.freq(attack); // attack unit: Hz! } fun void hit(float velocity) { velocity => i.next; } fun void setRingingGain(float g) { g => ringing_f.gain; } fun void setRingingFreq(float f) { (1.0 / f)::second => ringing.delay; } fun void setRingingFeedback(float g) { g => ringing_fb.gain; } fun void setRingingFilter(float f, float Q) { ringing_f.set(f, Q); } } kjzSnare102 B; B.output => dac; // declare variables (n - 1) / 2.0 => float t; // calculate threshold // time loop for (0 => int j15; j15 < n; j15++) { for (0 => int j14; j14 < n; j14++) { for (0 => int j13; j13 < n; j13++) { for (0 => int j12; j12 < n; j12++) { for (0 => int j11; j11 < n; j11++) { for (0 => int j10; j10 < n; j10++) { for (0 => int j9; j9 < n; j9++) { for (0 => int j8; j8 < n; j8++) { for (0 => int j7; j7 < n; j7++) { for (0 => int j6; j6 < n; j6++) { for (0 => int j5; j5 < n; j5++) { for (0 => int j4; j4 < n; j4++) { for (0 => int j3; j3 < n; j3++) { for (0 => int j2; j2 < n; j2++) { // kjzSnare101 if (snare == 1) { if ((j6>=t)&&(j5>=t)&&(j4>=t) || (j3>=t)&&(j2>=t)) { << 1">>>; A.setDecay(10000); A.setFilter(5000, 5); A.hit(0.8); } else { << 0">>>; } } // kjzSnare102 if (snare == 2) { if ((j6>=t)&&(j5>=t)&&(j4>=t) || (j3>=t)&&(j2>=t)) { << 1">>>; B.setRingingFeedback(.995); B.setRingingFilter(500, 1); B.hit(0.8); } else { << 0">>>; } } for (0 => int j1; j1 < n; j1++) { for (0 => int j0; j0 < n; j0++) { // advance time 1::second / notes_per_second => now; } } } } } } } } } } } } } } } }