示例#1
0
def start_program():

    print
    print "################################"
    print "##        EAR TRAINING        ##"
    print "################################"
    print

    #load/init, get config values
    conf = load_configuration('./configuration.conf')
    noteDelay = float(conf["noteDelay"])
    numberOfNotes = int(conf["numberOfNotes"])
    notesToTest = conf["noteSelection"].split(',')
    soundType = conf["playStyle"]

    #load notes to be played 
    note_sound = load_notes(soundType)

    #construct note set
    noteSet = set()
    [noteSet.add(note_sound[noteName]) for noteName in notesToTest]
    noteSetNames = ' '.join([x.note for x in sorted(list(noteSet))])

    #test user
    while True:

        #play n notes
        print "\nPLAYING NOTES..."
        randomNotes = n_random_notes(noteSet, numberOfNotes)
        randomNoteNames = [x.note for x in randomNotes]
        #[note.play_sound() for note in randomNotes]
        play_wavs_sequential([note.soundFile for note in randomNotes], noteDelay, True)

        #ask user for notes played
        userAnswer = raw_input("  Which notes were played?\n   Choose from %s\n   CHOICES: " % ' '.join(notesToTest))
        if "exit" in userAnswer:
            print "GOODBYE!"
            break
        userAnswer = userAnswer.strip().split(',')

        #test if correct
        testConditions = []
        if len(userAnswer) != len(randomNoteNames):
            give_cookie(False, randomNoteNames, userAnswer) 
        else:
            if any([notePlayed != noteGuessed for notePlayed, noteGuessed in zip(randomNoteNames, userAnswer)]):
                give_cookie(False, randomNoteNames, userAnswer) 
            else:
                give_cookie(True, randomNoteNames, userAnswer) 
示例#2
0
 def play_sound(self):
     play_wavs_sequential([self.soundFile], .5, True)