Thursday, May 31, 2012

C Major Scale - I Think (aka Julia's First Scale)

Click "Read More" to view the code for (I think it's) the C Major Scale (the first draft, because this code is too freakin' long), aka Julia's first scale :)




class Notes{
    
    //C notes
    16 => static int C0;
    33 => static int C1;
    65 => static int C2;
    131 => static int C3;
    262 => static int C4;
    523 => static int C5;
    1047 => static int C6;
    2093 => static int C7;
    4186 => static int C8;
    
    //C# notes
    17 => static int C0s;
    35 => static int C1s;
    69 => static int C2s;
    139 => static int C3s;
    277 => static int C4s;
    554 => static int C5s;
    1109 => static int C6s;
    2217 => static int C7s;
    4435 => static int C8s;
    
    //D notes
    18 => static int D0;
    37 => static int D1;
    73 => static int D2;
    147 => static int D3;
    294 => static int D4;
    587 => static int D5;
    1175 => static int D6;
    2349 => static int D7;
    4699 => static int D8;
    
    //D# notes
    19 => static int D0s;
    39 => static int D1s;
    78 => static int D2s;
    156 => static int D3s;
    311 => static int D4s;
    622 => static int D5s;
    1245 => static int D6s;
    2489 => static int D7s;
    4978 => static int D8s;
    
    //E notes
    21 => static int E0;
    41 => static int E1;
    82 => static int E2;
    165 => static int E3;
    330 => static int E4;
    659 => static int E5;
    1319 => static int E6;
    2637 => static int E7;
    5274 => static int E8;
    
    //F notes
    22 => static int F0;
    44 => static int F1;
    87 => static int F2;
    175 => static int F3;
    349 => static int F4;
    698 => static int F5;
    1397 => static int F6;
    2794 => static int F7;
    5588 => static int F8;
    
    //F# notes
    23 => static int F0s;
    46 => static int F1s;
    93 => static int F2s;
    185 => static int F3s;
    370 => static int F4s;
    740 => static int F5s;
    1480 => static int F6s;
    2960 => static int F7s;
    5920 => static int F8s;
    
    //G notes
    25 => static int G0;
    49 => static int G1;
    98 => static int G2;
    196 => static int G3;
    392 => static int G4;
    784 => static int G5;
    1568 => static int G6;
    3136 => static int G7;
    6272 => static int G8;
    
    //G# notes
    26 => static int G0s;
    52 => static int G1s;
    104 => static int G2s;
    208 => static int G3s;
    415 => static int G4s;
    831 => static int G5s;
    1661 => static int G6s;
    3322 => static int G7s;
    6645 => static int G8s;
    
    //A notes
    28 => static int A0;
    55 => static int A1;
    110 => static int A2;
    220 => static int A3;
    440 => static int A4;
    880 => static int A5;
    1760 => static int A6;
    3520 => static int A7;
    7040 => static int A8;
    
    //A# notes
    29 => static int A0s;
    58 => static int A1s;
    117 => static int A2s;
    233 => static int A3s;
    466 => static int A4s;
    932 => static int A5s;
    1864 => static int A6s;
    3729 => static int A7s;
    7459 => static int A8s;
    
    //B notes
    31 => static int B0;
    62 => static int B1;
    123 => static int B2;
    247 => static int B3;
    493 => static int B4;
    988 => static int B5;
    1976 => static int B6;
    3951 => static int B7;
    7902 => static int B8;
    
}

class Chords extends Notes {
    
    //C Major
    //SinOsc s0, SinOsc s1, SinOsc s2, SinOsc s3, SinOsc s4, SinOsc s5,
    //SinOsc s6, SinOsc s7, SinOsc s8
            //Notes.C4 => s0.freq;
        //Notes.E4 => s1.freq;
        //Notes.G4 => s2.freq;
        //Notes.C3 => s3.freq;
        //Notes.E3 => s4.freq;
        //Notes.G3 => s5.freq;
        //Notes.C5 => s6.freq;
        //Notes.E5 => s7.freq;
        //Notes.G5 => s8.freq;
        
        
    fun SinOsc[] DMin(SinOsc freqs[]) {
        
        Notes.D4 => freqs[0].freq;
        Notes.F4 => freqs[1].freq;
        Notes.A4 => freqs[2].freq;
        Notes.D3 => freqs[3].freq;
        Notes.F3 => freqs[4].freq;
        Notes.A3 => freqs[5].freq;
        Notes.D5 => freqs[6].freq;
        Notes.F5 => freqs[7].freq;
        Notes.A5 => freqs[8].freq;
        Notes.D2 => freqs[9].freq;
        Notes.F2 => freqs[10].freq;
        Notes.A2 => freqs[11].freq;
        Notes.D6 => freqs[12].freq;
        Notes.F6 => freqs[13].freq;
        Notes.A6 => freqs[26].freq;
        Notes.D1 => freqs[14].freq;
        Notes.F1 => freqs[15].freq;
        Notes.A1 => freqs[16].freq;
        Notes.D0 => freqs[17].freq;
        Notes.F0 => freqs[18].freq;
        Notes.A0 => freqs[19].freq;
        Notes.D7 => freqs[20].freq;
        Notes.F7 => freqs[21].freq;
        Notes.A7 => freqs[22].freq;
        Notes.D8 => freqs[23].freq;
        Notes.F8 => freqs[24].freq;
        Notes.A8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] CMaj(SinOsc freqs[]) {
        
        Notes.C4 => freqs[0].freq;
        Notes.G4 => freqs[1].freq;
        Notes.E4 => freqs[2].freq;
        Notes.C3 => freqs[3].freq;
        Notes.G3 => freqs[4].freq;
        Notes.E3 => freqs[5].freq;
        Notes.C5 => freqs[6].freq;
        Notes.G5 => freqs[7].freq;
        Notes.E5 => freqs[8].freq;
        Notes.C2 => freqs[9].freq;
        Notes.G2 => freqs[10].freq;
        Notes.E2 => freqs[11].freq;
        Notes.C6 => freqs[12].freq;
        Notes.G6 => freqs[13].freq;
        Notes.E6 => freqs[26].freq;
        Notes.E1 => freqs[14].freq;
        Notes.C1 => freqs[15].freq;
        Notes.G1 => freqs[16].freq;
        Notes.E0 => freqs[17].freq;
        Notes.C0 => freqs[18].freq;
        Notes.G0 => freqs[19].freq;
        Notes.C7 => freqs[20].freq;
        Notes.G7 => freqs[21].freq;
        Notes.E7 => freqs[22].freq;
        Notes.C8 => freqs[23].freq;
        Notes.G8 => freqs[24].freq;
        Notes.E8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] EMin(SinOsc freqs[]) {
        
        Notes.E4 => freqs[0].freq;
        Notes.G4 => freqs[1].freq;
        Notes.B4 => freqs[2].freq;
        Notes.E3 => freqs[3].freq;
        Notes.G3 => freqs[4].freq;
        Notes.B3 => freqs[5].freq;
        Notes.E5 => freqs[6].freq;
        Notes.G5 => freqs[7].freq;
        Notes.B5 => freqs[8].freq;
        Notes.E2 => freqs[9].freq;
        Notes.G2 => freqs[10].freq;
        Notes.B2 => freqs[11].freq;
        Notes.E6 => freqs[12].freq;
        Notes.G6 => freqs[13].freq;
        Notes.B6 => freqs[26].freq;
        Notes.E1 => freqs[14].freq;
        Notes.G1 => freqs[15].freq;
        Notes.B1 => freqs[16].freq;
        Notes.E0 => freqs[17].freq;
        Notes.G0 => freqs[18].freq;
        Notes.B0 => freqs[19].freq;
        Notes.E7 => freqs[20].freq;
        Notes.G7 => freqs[21].freq;
        Notes.B7 => freqs[22].freq;
        Notes.E8 => freqs[23].freq;
        Notes.G8 => freqs[24].freq;
        Notes.B8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] FMaj (SinOsc freqs[]) {
        
        Notes.C4 => freqs[0].freq;
        Notes.F4 => freqs[1].freq;
        Notes.A4 => freqs[2].freq;
        Notes.C3 => freqs[3].freq;
        Notes.F3 => freqs[4].freq;
        Notes.A3 => freqs[5].freq;
        Notes.C5 => freqs[6].freq;
        Notes.F5 => freqs[7].freq;
        Notes.A5 => freqs[8].freq;
        Notes.C2 => freqs[9].freq;
        Notes.F2 => freqs[10].freq;
        Notes.A2 => freqs[11].freq;
        Notes.C6 => freqs[12].freq;
        Notes.F6 => freqs[13].freq;
        Notes.A6 => freqs[26].freq;
        Notes.C1 => freqs[14].freq;
        Notes.F1 => freqs[15].freq;
        Notes.A1 => freqs[16].freq;
        Notes.C0 => freqs[17].freq;
        Notes.F0 => freqs[18].freq;
        Notes.A0 => freqs[19].freq;
        Notes.C7 => freqs[20].freq;
        Notes.F7 => freqs[21].freq;
        Notes.A7 => freqs[22].freq;
        Notes.C8 => freqs[23].freq;
        Notes.F8 => freqs[24].freq;
        Notes.A8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] GMaj(SinOsc freqs[]) {
        
        Notes.D4 => freqs[0].freq;
        Notes.G4 => freqs[1].freq;
        Notes.B4 => freqs[2].freq;
        Notes.D3 => freqs[3].freq;
        Notes.G3 => freqs[4].freq;
        Notes.B3 => freqs[5].freq;
        Notes.D5 => freqs[6].freq;
        Notes.G5 => freqs[7].freq;
        Notes.B5 => freqs[8].freq;
        Notes.D2 => freqs[9].freq;
        Notes.G2 => freqs[10].freq;
        Notes.B2 => freqs[11].freq;
        Notes.D6 => freqs[12].freq;
        Notes.G6 => freqs[13].freq;
        Notes.B6 => freqs[26].freq;
        Notes.D1 => freqs[14].freq;
        Notes.G1 => freqs[15].freq;
        Notes.B1 => freqs[16].freq;
        Notes.D0 => freqs[17].freq;
        Notes.G0 => freqs[18].freq;
        Notes.B0 => freqs[19].freq;
        Notes.D7 => freqs[20].freq;
        Notes.G7 => freqs[21].freq;
        Notes.B7 => freqs[22].freq;
        Notes.D8 => freqs[23].freq;
        Notes.G8 => freqs[24].freq;
        Notes.B8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] AMin (SinOsc freqs[]) {
        
        Notes.C4 => freqs[0].freq;
        Notes.E4 => freqs[1].freq;
        Notes.A4 => freqs[2].freq;
        Notes.C3 => freqs[3].freq;
        Notes.E3 => freqs[4].freq;
        Notes.A3 => freqs[5].freq;
        Notes.C5 => freqs[6].freq;
        Notes.E5 => freqs[7].freq;
        Notes.A5 => freqs[8].freq;
        Notes.C2 => freqs[9].freq;
        Notes.E2 => freqs[10].freq;
        Notes.A2 => freqs[11].freq;
        Notes.C6 => freqs[12].freq;
        Notes.E6 => freqs[13].freq;
        Notes.A6 => freqs[26].freq;
        Notes.C1 => freqs[14].freq;
        Notes.E1 => freqs[15].freq;
        Notes.A1 => freqs[16].freq;
        Notes.C0 => freqs[17].freq;
        Notes.E0 => freqs[18].freq;
        Notes.A0 => freqs[19].freq;
        Notes.C7 => freqs[20].freq;
        Notes.E7 => freqs[21].freq;
        Notes.A7 => freqs[22].freq;
        Notes.C8 => freqs[23].freq;
        Notes.E8 => freqs[24].freq;
        Notes.A8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] BMinDim(SinOsc freqs[]) {
        
        Notes.D4 => freqs[0].freq;
        Notes.F4 => freqs[1].freq;
        Notes.B4 => freqs[2].freq;
        Notes.D3 => freqs[3].freq;
        Notes.F3 => freqs[4].freq;
        Notes.B3 => freqs[5].freq;
        Notes.D5 => freqs[6].freq;
        Notes.F5 => freqs[7].freq;
        Notes.B5 => freqs[8].freq;
        Notes.D2 => freqs[9].freq;
        Notes.F2 => freqs[10].freq;
        Notes.B2 => freqs[11].freq;
        Notes.D6 => freqs[12].freq;
        Notes.F6 => freqs[13].freq;
        Notes.B6 => freqs[26].freq;
        Notes.D1 => freqs[14].freq;
        Notes.F1 => freqs[15].freq;
        Notes.B1 => freqs[16].freq;
        Notes.D0 => freqs[17].freq;
        Notes.F0 => freqs[18].freq;
        Notes.B0 => freqs[19].freq;
        Notes.D7 => freqs[20].freq;
        Notes.F7 => freqs[21].freq;
        Notes.B7 => freqs[22].freq;
        Notes.D8 => freqs[23].freq;
        Notes.F8 => freqs[24].freq;
        Notes.B8 => freqs[25].freq;
        
        return freqs;
    }
    
    fun SinOsc[] CMajPlus(SinOsc freqs[]) {
        
        Notes.C4 => freqs[0].freq;
        Notes.G4 => freqs[1].freq;
        Notes.E4 => freqs[2].freq;
        Notes.C3 => freqs[3].freq;
        Notes.G3 => freqs[4].freq;
        Notes.E3 => freqs[5].freq;
        Notes.C5 => freqs[6].freq;
        Notes.G5 => freqs[7].freq;
        Notes.E5 => freqs[8].freq;
        Notes.C2 => freqs[9].freq;
        Notes.G2 => freqs[10].freq;
        Notes.E2 => freqs[11].freq;
        Notes.C6 => freqs[12].freq;
        Notes.G6 => freqs[13].freq;
        Notes.E6 => freqs[26].freq;
        Notes.E1 => freqs[14].freq;
        Notes.C1 => freqs[15].freq;
        Notes.G1 => freqs[16].freq;
        8372 => freqs[17].freq;
        10548 => freqs[18].freq;
        12544 => freqs[19].freq;
        Notes.C7 => freqs[20].freq;
        Notes.G7 => freqs[21].freq;
        Notes.E7 => freqs[22].freq;
        Notes.C8 => freqs[23].freq;
        Notes.G8 => freqs[24].freq;
        Notes.E8 => freqs[25].freq;
        
        
        return freqs;
    }

}

//test code

SinOsc s0 => Gain g => dac;
SinOsc s1 => g;
SinOsc s2 => g;
SinOsc s3 => g;
SinOsc s4 => g;
SinOsc s5 => g;
SinOsc s6 => g;
SinOsc s7 => g;
SinOsc s8 => g;
SinOsc s9 => g;
SinOsc s10 => g;
SinOsc s11 => g;
SinOsc s12 => g;
SinOsc s13 => g;
SinOsc s14 => g;
SinOsc s15 => g;
SinOsc s16 => g;
SinOsc s17 => g;
SinOsc s18 => g;
SinOsc s19 => g;
SinOsc s20 => g;
SinOsc s21 => g;
SinOsc s22 => g;
SinOsc s23 => g;
SinOsc s24 => g;
SinOsc s25 => g;
SinOsc s26 => g;
        
.003 => g.gain;

[s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20,
s21, s22, s23, s24, s25, s26] @=> SinOsc freqs[];

Chords c;
//Chords d;

1::second => dur T;
now + T => time later0;
now + (2 * T) => time later1;
now + (3 * T) => time later2;
now + (4 * T) => time later3;
now + (5 * T) => time later4;
now + (6 * T) => time later5;
now + (7 * T) => time later6;
now + (8 * T) => time later7;
while(now <= later0) {
    c.CMaj(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later1) {
    c.DMin(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later2) {
    c.EMin(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later3) {
    c.FMaj(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later4) {
    c.GMaj(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later5) {
    c.AMin(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later6) {
    c.BMinDim(freqs) @=> freqs;
    200::ms=>now;
}
while(now <= later7) {
    c.CMajPlus(freqs) @=> freqs;
    200::ms=>now;
}

1 comment:

  1. Great job! This is gonna be very handy when we start compositions. I think you need to make the classes public,but I am not sure of the static you used when defining the notes. Does that hold any special significance? Can the code still work without it? I want to believe so, but I just wanna know why you decided to put it there.

    ReplyDelete