// guitar_riff_lab2.ck // copyright 2007 Les Hall // This code is protected by the GNU General Public License // Evaluates test expressions for creating riffs and sequences // parameters 3 => int riff; // select which riff to play // 1: lead guitar with ORed 2-bit ANDing, has a familiar, powerful sound // 2: bass guitar with ORed progressive ANDing, just a basic bass riff // 3: lead guitar with ORed progressive ANDing, has an "east-meets-west" sound 2 => int n; // counting base 10 => float base_freq; // all freqencies are multiplied by this 8 => float notes_per_second; // the timing // many thanks to kijjaz for the mandolin-based Stratocaster guitar sound with overdrive: // Mandolin as the electric guitar test: by kijjaz (kijjaz@yahoo.com) // feel free to use, modify, publish Mandolin str[3]; // create mandolin strings SinOsc overdrive => NRev rev => dac; // create overdrive to reverb to dac overdrive.sync(1); // make overdrive do Sine waveshaping rev.mix(0.02); // set reverb mix rev.gain(0.6); // set master gain // connect strings, set string damping for(int i; i < 3; i++) { str[i] => overdrive; .9 => str[i].stringDamping; } // declare variables float freq; // the frequency multiplier of the next note of the instrument // calculate threshold (n - 1) / 2.0 => float t; // 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++) { for (0 => int j1; j1 < n; j1++) { // bass guitar if (riff == 2) { if ((j6>=t)&&(j5>=t)&&(j4>=t) || (j3>=t)&&(j2>=t) || (j1>=t)) { (16 + 1*j6 + 2*j5 + 4*j4 + 8*j3 + 16*j2) / 8.0 * base_freq => freq; << 1", freq>>>; for (0 => int i; i < 3; i++) { freq * (0.5*i+1) => str[i].freq; } for (0 => int i; i < 3; i++) { 0.8 => str[i].pluck; } } else { << 0", freq>>>; } } for (0 => int j0; j0 < n; j0++) { // lead guitar if (riff == 1) { if ((j15>=t)&&(j14>=t) || (j13>=t)&&(j12>=t) || (j11>=t)&&(j10>=t) || (j9>=t)&&(j8>=t) || (j7>=t)&&(j6>=t) || (j5>=t)&&(j4>=t) || (j3>=t)&&(j2>=t) || (j1>=t)&&(j0>=t)) { (j15 + j14 + j13 + j12 + j11 + j10 + j9 + j8 + j7 + j6 + j5 + j4 + j3 + j2 + j1 + j0 + 1) * 8 * base_freq => freq; << 1", freq>>>; for (0 => int i; i < 3; i++) { freq * (0.5*i+1) => str[i].freq; } for (0 => int i; i < 3; i++) { 0.8 => str[i].pluck; } } else { << 0", freq>>>; } } // lead guitar if (riff == 3) { if ((j14>=t)&&(j13>=t)&&(j12>=t)&&(j11>=t)&&(j10>=t) || (j9>=t)&&(j8>=t)&&(j7>=t)&&(j6>=t) || (j5>=t)&&(j4>=t)&&(j3>t) || (j2>=t)&&(j1>=t) || (j0>=t)) { (j15 + j14 + j13 + j12 + j11 + j10 + j9 + j8 + j7 + j6 + j5 + j4 + j3 + j2 + j1 + j0 + 1) * 8 * base_freq => freq; << 1", freq>>>; for (0 => int i; i < 3; i++) { freq * (0.5*i+1) => str[i].freq; } for (0 => int i; i < 3; i++) { 0.8 => str[i].pluck; } } else { << 0", freq>>>; } } // advance time 1::second / notes_per_second => now; } } } } } } } } } } } } } } } }