From f006f6f571149cd3feff9153b80364ccbf56b4e8 Mon Sep 17 00:00:00 2001 From: Mayssa Lakhal <mayssa.lakhal@etu.univ-lyon1.fr> Date: Fri, 13 Dec 2024 14:37:15 +0100 Subject: [PATCH] added upper octave C --- piano.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/piano.py b/piano.py index 594bb35..6ee9852 100644 --- a/piano.py +++ b/piano.py @@ -6,7 +6,7 @@ import pygame # tests avec pygame root_folder = os.path.dirname(os.path.relpath(__file__)) -print(f"Root folder: {root_folder}") +# print(f"Root folder: {root_folder}") # variables # default octave : 4 (right hand), 3 (left hand) @@ -14,23 +14,28 @@ print(f"Root folder: {root_folder}") right_octave = 4 left_octave = 3 -left_hand = ["w", "s", "x", "d", "c", "v", "g", "b", "h", "n", "j", ","] -right_hand = ["r", "(", "t", "-", "y", "u", "_", "i", "ç", "o", "à ", "p"] +left_hand = ["w", "s", "x", "d", "c", "v", "g", "b", "h", "n", "j", ",", ";"] +right_hand = ["r", "(", "t", "-", "y", "u", "_", "i", "ç", "o", "à ", "p", "^"] -notes = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"] +notes = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B", "C"] -right_notes = [notes[i] + str(right_octave) for i in range(12)] - -left_notes = [notes[i] + str(left_octave) for i in range(12)] +right_notes = [notes[i] + str(right_octave) for i in range(12)]+ [notes[0] + str(right_octave + 1)] +print(right_notes) +left_notes = [notes[i] + str(left_octave) for i in range(12)] + [notes[0] + str(left_octave + 1)] # functions pygame.mixer.init() def play_sound(note): - print(f"Playing sound: {note}") - sound = pygame.mixer.Sound(f"./assets/notes/{note}.wav") - sound.play() + audio_file = os.path.join(root_folder, f"./assets/notes/{note}.wav") + if os.path.isfile(audio_file): + print(f"Playing sound: {audio_file}") + sound = pygame.mixer.Sound(audio_file) + sound.play() + threading.Timer(2.0, sound.stop).start() + else: + print(f"File not found: {audio_file}") def press(key): -- GitLab