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)