def new_question_progression(): if st.NEWQUESTION: if st.COUNT: print("score: {} / {} = {:.2%}".format(st.SCORE, st.COUNT, st.SCORE / st.COUNT)) st.COUNT += 1 # Find random chord progression prog_length = random.choice(st.PROG_LENGTHS) prog, prog_strums = random_progression(prog_length, st.NUMERALS, st.CHORD_LENGTHS) # store question info st.CURRENT_Q_INFO = {'prog': prog, 'prog_strums': prog_strums} else: prog = st.CURRENT_Q_INFO['prog'] prog_strums = st.CURRENT_Q_INFO['prog_strums'] # Play chord/progression play_progression(prog_strums, st.KEY) # Request user's answer ans = input("Enter your answer using root note names " "or numbers 1-7 seperated by spaces: ").strip() if ans in menu_commands: menu_commands[ans].action() else: eval_progression(ans, prog, prog_strums)
def new_question_single_chord(): # Choose new chord+octave/Progression # Single chord mode if st.NEWQUESTION: if st.COUNT: print("score: {} / {} = {:.2%}".format(st.SCORE, st.COUNT, st.SCORE / st.COUNT)) st.COUNT += 1 # Pick random chord/octave numeral, chord, Ioctave = random_chord() # store question info st.CURRENT_Q_INFO = { 'numeral': numeral, 'chord': chord, 'Ioctave': Ioctave } else: numeral = st.CURRENT_Q_INFO['numeral'] chord = st.CURRENT_Q_INFO['chord'] Ioctave = st.CURRENT_Q_INFO['Ioctave'] # Play chord play_progression([numeral], st.KEY, Ioctave=Ioctave) # Request user's answer ans = getch("Enter 1-7 or root of chord: ").strip() if ans in menu_commands: menu_commands[ans].action() else: if isvalidnote(ans): if eval_single_chord(ans, numeral, chord[0].name): st.SCORE += 1 print("Yes!", chordname(chord, numeral)) if st.RESOLVE_WHEN_CORRECT: resolve_with_chords(numeral, key=st.KEY, Ioctave=Ioctave, numerals=st.NUMERALS, bpm=st.BPM * 2) play_wait() else: print("No!", chordname(chord, numeral)) if st.RESOLVE_WHEN_INCORRECT: resolve_with_chords(numeral, key=st.KEY, Ioctave=Ioctave, numerals=st.NUMERALS, bpm=st.BPM * 2) play_wait() else: print("User input not understood. Please try again.") return
def intro(play_cadence=True): print("\n" + "~" * 20 + "\n") # List menu_commands print("Note: At any time enter") for mc in menu_commands.values(): print(mc.input_description, "to", mc.description) print("\n" + "-" * 10 + "\n") # Display key if st.KEY == st.KEY.lower(): print("KEY:", st.KEY.upper(), "min") else: print("KEY:", st.KEY, "Maj") print("-" * 10) # Play cadence if play_cadence: play_progression(st.CADENCE, st.KEY, Iup=st.I) play_wait() # time.sleep(st.DELAY) # time.sleep(st.DELAY) return
def playfcn(): play_progression([numeral], st.KEY, Ioctave=Ioctave) play_wait() fluidsynth.play_Note(tone)
def new_question_chord_tone(): if st.NEWQUESTION: if st.COUNT: print("score: {} / {} = {:.2%}".format(st.SCORE, st.COUNT, st.SCORE / st.COUNT)) st.COUNT += 1 # Pick random chord/octave numeral, chord, Ioctave = random_chord() # Pick a random tone in the chord tone = random.choice(chord) # store question info st.CURRENT_Q_INFO = { 'numeral': numeral, 'chord': chord, 'Ioctave': Ioctave, 'tone': tone } else: numeral = st.CURRENT_Q_INFO['numeral'] chord = st.CURRENT_Q_INFO['chord'] Ioctave = st.CURRENT_Q_INFO['Ioctave'] tone = st.CURRENT_Q_INFO['tone'] # Play chord, then tone def playfcn(): play_progression([numeral], st.KEY, Ioctave=Ioctave) play_wait() fluidsynth.play_Note(tone) p = Process(target=playfcn()) p.start() # Request user's answer mes = ("Which tone did you hear?\n" "Enter {}, or {}: ".format( ", ".join([str(t) for t in st.TONES[:-1]]), st.TONES[-1])) ans = getch(mes).strip() p.terminate() if ans in menu_commands: menu_commands[ans].action() else: try: ans = int(ans) except: print("User input not understood. Please try again.") st.NEWQUESTION = False if ans in st.TONES: tone_idx = [n for n in chord].index(tone) correct_ans = st.TONES[tone_idx] if ans == correct_ans: st.SCORE += 1 print("Yes! The {} tone of".format(correct_ans), chordname(chord, numeral)) if st.ARPEGGIATE_WHEN_CORRECT: resolve_chord_tone(chord, tone, Ioctave) play_wait() st.NEWQUESTION = True else: print("No! The {} tone of".format(correct_ans), chordname(chord, numeral)) if st.ARPEGGIATE_WHEN_INCORRECT: resolve_chord_tone(chord, tone, Ioctave) play_wait() st.NEWQUESTION = True # secret option elif ans in [8, 9, 0]: tone_idx = [8, 9, 0].index(ans) for num in st.NUMERALS: tmp = progressions.to_chords([num], st.KEY)[0] num_chord = NoteContainer(tmp) play_progression([num], st.KEY, Ioctave=Ioctave) play_wait() fluidsynth.play_Note(num_chord[tone_idx]) play_wait() play_wait() st.NEWQUESTION = False else: print("User input not understood. Please try again.") st.NEWQUESTION = False return
def play_cadence(): play_progression(st.CADENCE, st.KEY, Iup=st.I, bpm=st.BPM) play_wait()