Compare commits
1 Commits
main
...
Arduino_de
| Author | SHA1 | Date |
|---|---|---|
|
|
9fa8fbf58e |
|
|
@ -1,86 +0,0 @@
|
||||||
import serial
|
|
||||||
import time
|
|
||||||
import pygame
|
|
||||||
from pydub import AudioSegment
|
|
||||||
import serial.tools.list_ports
|
|
||||||
|
|
||||||
# Define the paths
|
|
||||||
#Short notes
|
|
||||||
NOTES_PATH = "Player\\notes\\mp3-master\\"
|
|
||||||
#Long notes
|
|
||||||
#NOTES_PATH = r"C:\Users\Balthazar\Shared\ECAM\Advance Robotique\Project\Player\notes\high-quality-master\renamed\\"
|
|
||||||
SERIAL_PORT = "COM5"
|
|
||||||
BAUD_RATE = 115200
|
|
||||||
|
|
||||||
# New Features
|
|
||||||
wait_note_finish = False
|
|
||||||
keyboard_input = False
|
|
||||||
check_com3 = True
|
|
||||||
|
|
||||||
pygame.mixer.init()
|
|
||||||
|
|
||||||
notes = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
|
|
||||||
|
|
||||||
def play_note_with_pygame(note):
|
|
||||||
try:
|
|
||||||
pygame_sound = pygame.mixer.Sound(f"{NOTES_PATH}{note}.mp3")
|
|
||||||
pygame_sound.play()
|
|
||||||
if wait_note_finish:
|
|
||||||
while pygame.mixer.get_busy():
|
|
||||||
pygame.time.Clock().tick(10)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error playing {note}: {e}")
|
|
||||||
|
|
||||||
# Check if COM port is connected
|
|
||||||
if check_com3:
|
|
||||||
ports = list(serial.tools.list_ports.comports())
|
|
||||||
com3_found = any(port.device == SERIAL_PORT for port in ports)
|
|
||||||
if not com3_found:
|
|
||||||
print(f"{SERIAL_PORT} not found. Switching to keyboard input mode.")
|
|
||||||
keyboard_input = True
|
|
||||||
|
|
||||||
try:
|
|
||||||
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
|
|
||||||
time.sleep(2)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error opening {SERIAL_PORT}: {e}")
|
|
||||||
keyboard_input = True
|
|
||||||
|
|
||||||
print("Listening for Arduino input...")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
# Keyboard input fallback
|
|
||||||
if keyboard_input:
|
|
||||||
user_input = input("Enter octave; note (e.g., 4; C) or 'q' to quit: ")
|
|
||||||
if user_input == 'q':
|
|
||||||
break
|
|
||||||
try:
|
|
||||||
octave_str, note_part = user_input.split(";")
|
|
||||||
octave = int(octave_str.strip())
|
|
||||||
note = note_part.strip().split()[0] # Get only the first note
|
|
||||||
if note in notes:
|
|
||||||
play_note_with_pygame(f"{note}{octave}")
|
|
||||||
except:
|
|
||||||
print("Invalid input format.")
|
|
||||||
|
|
||||||
# Arduino input
|
|
||||||
data = ser.readline().decode('utf-8', errors='ignore').strip()
|
|
||||||
if data:
|
|
||||||
print("data: " + data)
|
|
||||||
try:
|
|
||||||
octave_str, note_part = data.split(";")
|
|
||||||
octave = int(octave_str.strip())
|
|
||||||
note = note_part.strip().split()[0] # Only one note expected
|
|
||||||
if note in notes:
|
|
||||||
play_note_with_pygame(f"{note}{octave}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Invalid format or error parsing data: {e}")
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Exiting...")
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {e}")
|
|
||||||
|
|
||||||
ser.close()
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
import serial
|
|
||||||
import time
|
|
||||||
import pygame
|
|
||||||
from pydub import AudioSegment
|
|
||||||
import serial.tools.list_ports
|
|
||||||
|
|
||||||
# Define the paths
|
|
||||||
#Short notes
|
|
||||||
NOTES_PATH = "Player\\notes\\mp3-master\\"
|
|
||||||
#Long notes
|
|
||||||
#NOTES_PATH = r"C:\Users\Balthazar\Shared\ECAM\Advance Robotique\Project\Player\notes\high-quality-master\renamed\\"
|
|
||||||
SERIAL_PORT = "COM5" #"COM3"
|
|
||||||
BAUD_RATE = 115200
|
|
||||||
|
|
||||||
# New Features
|
|
||||||
wait_note_finish = False # Set to False to play without waiting for the note to finish
|
|
||||||
keyboard_input = False # Set to False to disable keyboard note input
|
|
||||||
check_com3 = True # Set to False to skip COM3 check
|
|
||||||
|
|
||||||
pygame.mixer.init()
|
|
||||||
|
|
||||||
octave = 4
|
|
||||||
|
|
||||||
notes = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
|
|
||||||
|
|
||||||
|
|
||||||
def play_note_with_pygame(note):
|
|
||||||
try:
|
|
||||||
pygame_sound = pygame.mixer.Sound(f"{NOTES_PATH}{note}.mp3")
|
|
||||||
pygame_sound.play()
|
|
||||||
if wait_note_finish:
|
|
||||||
while pygame.mixer.get_busy(): # Wait until sound is finished
|
|
||||||
pygame.time.Clock().tick(10)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error playing {note}: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
# Check if COM3 is connected
|
|
||||||
if check_com3:
|
|
||||||
ports = list(serial.tools.list_ports.comports())
|
|
||||||
com3_found = any(port.device == SERIAL_PORT for port in ports)
|
|
||||||
if not com3_found:
|
|
||||||
print(f"{SERIAL_PORT} not found. Switching to keyboard input mode.")
|
|
||||||
keyboard_input = True
|
|
||||||
|
|
||||||
try:
|
|
||||||
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
|
|
||||||
time.sleep(2)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error opening {SERIAL_PORT}: {e}")
|
|
||||||
keyboard_input = True
|
|
||||||
|
|
||||||
print("Listening for Arduino input...")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
# Keyboard input for playing notes
|
|
||||||
if keyboard_input:
|
|
||||||
user_input = input("Enter note (C, Db, D, ... B) or 'q' to quit: ")
|
|
||||||
if user_input == 'q':
|
|
||||||
break
|
|
||||||
if user_input in notes:
|
|
||||||
play_note_with_pygame(f"{user_input}{octave}")
|
|
||||||
|
|
||||||
# Arduino input for playing notes
|
|
||||||
data = ser.readline().decode('utf-8', errors='ignore').strip()
|
|
||||||
if data:
|
|
||||||
print("data : " + data)
|
|
||||||
note = data
|
|
||||||
if note in notes:
|
|
||||||
play_note_with_pygame(f"{note}{octave}")
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Exiting...")
|
|
||||||
break
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {e}")
|
|
||||||
|
|
||||||
ser.close()
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,37 +0,0 @@
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
# Set your input and output folder paths here
|
|
||||||
input_folder = r"C:\Users\Balthazar\Shared\ECAM\Advance Robotique\Project\Player\notes\high-quality-master\base"
|
|
||||||
output_folder = r"C:\Users\Balthazar\Shared\ECAM\Advance Robotique\Project\Player\notes\high-quality-master\renamed"
|
|
||||||
|
|
||||||
# Mapping of 88 piano key numbers to note names
|
|
||||||
note_names = [
|
|
||||||
'A0', 'Bb0', 'B0',
|
|
||||||
'C1', 'Db1', 'D1', 'Eb1', 'E1', 'F1', 'Gb1', 'G1', 'Ab1', 'A1', 'Bb1', 'B1',
|
|
||||||
'C2', 'Db2', 'D2', 'Eb2', 'E2', 'F2', 'Gb2', 'G2', 'Ab2', 'A2', 'Bb2', 'B2',
|
|
||||||
'C3', 'Db3', 'D3', 'Eb3', 'E3', 'F3', 'Gb3', 'G3', 'Ab3', 'A3', 'Bb3', 'B3',
|
|
||||||
'C4', 'Db4', 'D4', 'Eb4', 'E4', 'F4', 'Gb4', 'G4', 'Ab4', 'A4', 'Bb4', 'B4',
|
|
||||||
'C5', 'Db5', 'D5', 'Eb5', 'E5', 'F5', 'Gb5', 'G5', 'Ab5', 'A5', 'Bb5', 'B5',
|
|
||||||
'C6', 'Db6', 'D6', 'Eb6', 'E6', 'F6', 'Gb6', 'G6', 'Ab6', 'A6', 'Bb6', 'B6',
|
|
||||||
'C7', 'Db7', 'D7', 'Eb7', 'E7', 'F7', 'Gb7', 'G7', 'Ab7', 'A7', 'Bb7', 'B7',
|
|
||||||
'C8'
|
|
||||||
]
|
|
||||||
|
|
||||||
def rename_from_numbers(input_folder, output_folder):
|
|
||||||
os.makedirs(output_folder, exist_ok=True)
|
|
||||||
|
|
||||||
for i in range(1, 89):
|
|
||||||
old_name = os.path.join(input_folder, f"{i}.mp3")
|
|
||||||
new_name = os.path.join(output_folder, f"{note_names[i - 1]}.mp3")
|
|
||||||
|
|
||||||
if os.path.exists(old_name):
|
|
||||||
if os.path.exists(new_name):
|
|
||||||
print(f"Warning: {new_name} already exists. Overwriting.")
|
|
||||||
shutil.copy2(old_name, new_name)
|
|
||||||
print(f"Copied {i}.mp3 → {note_names[i - 1]}.mp3")
|
|
||||||
else:
|
|
||||||
print(f"Missing: {i}.mp3")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
rename_from_numbers(input_folder, output_folder)
|
|
||||||
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue