#Chantal Taylor
#Intro to Computing
#A. Misra
#November 25, 2008
#Assignment 6

#The song Memories of Green's score can be found at this url: http://csd.varlew.net/ct/ctsheet/1-05%20Memories%20of%20Green%201.jpg
#You may notice, that the suggested tempo is taken seriously in the calculations of the note lengths.
#Also, remember to call the "MemoriesofGreen()" function to hear the song! :) 
#Here are the note frequencies.
G = 196
Ab = 207
A = 220
Bb = 223
B = 247
C = 262
Cs = 277
D = 294
Eb = 311
E = 330
F = 349
Fs = 370
#here are the note value frequencies. H is for half note, q is for quarter, th is for eigth, xth is for sixtheenth, and the D denotes a half note.
q = .833333
h = 2.0 * q
th = q * .5
xth = th * .5
dq = q + th
dth = th + xth
#This is the song Memories of Green from the video game Chrono Trigger, which is easily the best rpg ever produced.  Ever.

#The instruments
s = Mandolin()
m = Mandolin()
r = SineWave()
j = SineWave()
#Here are the lists of notes for the song.  In the intro, all the note lengths are the same for right and left.
righthand1 = [4*G, 2*B, 2*C, 4*G,4*G, 2*B, 2*C, 4*G,4*G,2*B, 2*C, 4*G,4*G, 2*B, 2*C, 4*G,4*G, 2*B, 2*C, 4*G,4*G, 2*B, 2*C, 4*G,4*G,2*B, 2*C, 4*G, 2 * B]
lefthand1 = [.5 * G, .5 * E, A, .5 * E, .5 * G, .5 * E, A, .5 * E ]
righthand2 = [2 * E, 2 * Fs,4 * G, 2 * B,  2 * Fs,  2 * D, 2 * A, 2 * B, 2 * E, 4 * A, 4 * B, 4*B, 4 * A, 4 * Ab, 2 * E, 2 * B]
lefthand2 = [A, B, C, 2 *G, A, B, C, 2 *G,A, B, C, 2 *G,A, B, C, 2 *G,A, B, C, 2 *G,A, B, C, 2 *G,A, B, C, 2 *G,A, B, C, 2 *G, .5 * Fs, A, B, E, .5 * Fs, A, B, E,.5 * Fs, A, B, E,.5 * Fs, A, B, E,.5 * Fs, A, B, E,.5 * Fs, A, B, E,.5 * Fs, A, B, E,]
rightvalue1 = [dth, dth, q, th, th, h + q, th +  xth, xth, xth, xth, dth, dth, xth, xth, 4.5 * q, th]
righthand3 = [2 * E, 2 * Fs,4 * G, 2 * B,  2 * Fs,  2 * D, 2 * A, 2 * B, 2 * E, 4 * A, 4 * B, 4*B, 4 * A, 4 * Ab, 2 * E, 2 * E, 2 * Fs]
rightvalue3 = [dth, dth, q, th, th, h + q, th +  xth, xth, xth, xth, dth, dth, xth, xth, 4.5 * q, xth, xth]
righthand4 = [4*G, 4*A, 4*B, 4*C, 4*C, 4*D, 4*D, 4*Cs, 4*C, 4*B, 2*E, 2*D, 2*E, 4*G, 4*A, 2*Fs, 2*E, 2*Fs, 2*B]
lefthand4 = [.5*F, G, A, E,.5*F, G, A, E,.5*F, G, A, E,.5*F, G, A, E,.5*F, G, A, E,.5*F, G, A, E,.5*F, G, A, E,.5*F, G, A, E, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*E, .5*Fs, G, D, .5*C, A, B, E, .5*C,A,B,E,.5*F,B,C,2*G,.5*F,B,C,2*G, .5*E,A,D,Fs,  .5*E,A,D,Fs, .5*E,A,D,Fs, .5*E,A,D,Fs, .5*E,A,D,Fs, .5*E,A,D,Fs, .5*E,A,D,Fs, .5*E,A,D,Fs]
rightvalue4 = [h,h,h,dq,th,dth,dth,xth,xth,h+h+q,th,th,h,dq,th,xth,xth,th+h+h+h+th,th]
#Okay, here the song is divided into two parts, the intro and melody.  The intro has a right hand and a left hand (obvious references to a piano).
#The second part which is the song, has two hand parts as well.  However, the melody is not all just one set note value, and it sounds gross making it a bunch of
#sixteenth notes.  So, that is why there is a large obese function at the bottom of the coding.
#The instruments sound gross too.
def IntroRightplayIt(note):
    r.setFrequency(note)
    r.noteOn(1)
    wait(xth)
    r.noteOff(1)

def IntroLeftplayIt(note):
    m.setFrequency(note)
    m.noteOn(1)
    wait(q)
    m.noteOff(1)

def SongLeftplayIt(note):
    j.setFrequency(note)
    j.noteOn(1)
    wait(xth)
    j.noteOff(1)

def SongRightplayIt(note, value):
    s.setFrequency(note)
    s.noteOn(1)
    wait(value)
    s.noteOff(1)

def introright():
    r.connect()
    for n in righthand1:
        IntroRightplayIt(n)
    r.disconnect()

def introleft():
    m.connect()
    for z in lefthand1:
        IntroLeftplayIt(z)
    m.disconnect()
    
def songleft():
    j.connect()
    j.setGain(.5)
    for u in lefthand2:
        SongLeftplayIt(u)
    j.disconnect()
    
def songright():
    s.connect()
    s.setGain(.5)
    for x, i in zip(righthand2, rightvalue1):
        SongRightplayIt(x, i)
    s.disconnect()
    
def songright2():
    s.connect()
    s.setGain(.5)
    for x, i in zip(righthand3, rightvalue3):
        SongRightplayIt(x, i)
    s.disconnect()
    
def songleft4():
    j.connect()
    j.setGain(.5)
    for u in lefthand4:
        SongLeftplayIt(u)
    j.disconnect()
    
def songright4():
    s.connect()
    s.setGain(.5)
    for x, i, in zip(righthand4, rightvalue4):
        SongRightplay(x, i)
    s.disconnect()
#Okay, in hindsight, I like the way SongRightplayXXX sounds better than songright.  So.. we are going to stick with SongRightplayXXX, which is gross
        #coding, but at least it sounds betters.

def MemoriesofGreen():
    doTogether(introleft, introright)
    doTogether(songleft, songright)
    doTogether(songleft, songright2)
    doTogether(songleft4, songright4)






#I couldn't figure out how to implement two lists at the same time. -.- then I realized.. I really didn't have too because Chuck is primitive, but here
            # it sounds better, so I'll leave it in.





def SongRightplayXXX():
    s.setFrequency(2 * E)
    s.noteOn(1)
    wait(dth)
    s.noteOff(1)
    s.setFrequency(2 * Fs)
    s.noteOn(1)
    wait(dth)
    s.noteOff(1)
    s.setFrequency(4 * G)
    s.noteOn(1)
    wait(q)
    s.noteOff(1)
    s.setFrequency(2 * B)
    s.noteOn(1)
    wait(th)
    s.noteOff(1)
    s.setFrequency(2 * Fs)
    s.noteOn(1)
    wait(th)
    s.noteOff(1)
    s.setFrequency(2 * D)
    s.noteOn(1)
    wait(3 * q)
    s.noteOff(1)
    s.setFrequency(2 * A)
    s.noteOn(1)
    wait(th + xth)
    s.noteOff(1)
    s.setFrequency(2 * B)
    s.noteOn(1)
    wait(xth)
    s.noteOff(1)
    s.setFrequency(2 * E)
    s.noteOn(1)
    wait(xth)
    s.noteOff(1)
    s.setFrequency(4 * A)
    s.noteOn(1)
    wait(xth)
    s.noteOff(1)
    s.setFrequency(4 * B)
    s.noteOn(1)
    wait(dth)
    s.noteOff(1)
    s.setFrequency(4 * B)
    s.noteOn(1)
    wait(dth)
    s.noteOff(1)
    s.setFrequency(4 * A)
    s.noteOn(1)
    wait(xth)
    s.noteOff(1)
    s.setFrequency(4 * Ab)
    s.noteOn(1)
    wait(xth)
    s.noteOff(1)
    s.setFrequency(2 * E)
    s.noteOn(1)
    wait(5 * q)
    s.noteOff(1)

