1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| # -*- coding: utf-8 -*-
import os
import numpy as np
import logging
import pandas as pd
from music21 import converter, note, chord
logging.basicConfig(
level=logging.INFO, # niveau d'information
format="%(levelname)s:%(message)s" # forme du message
)
logging.info("Le script est lancé")
# === Paramètres ===
DOSSIER = r"E:\2_M_E_S__P_R_O_J_E_T_S\IA_Cycle\musique\partit_XML"
fichier_sortie = 'partition_condensee.xlsx'
FICHIER = "Cy24_I_IA_25.xml"
NB_MESURES = 20 # nombre de mesures à analyser
SYMBOLE_NOTE = "£" # ce qui apparaît si la mesure contient une note/accord
#(Jai aussi ajouté les barres obliques inverses `\` manquantes, car `E:2_M_E_S__P_R_O_J_E_T_S...` est invalide comme chemin Windows il faut `E:\2_M_E_S__P_R_O_J_E_T_S
`.)*
# === Chargement de la partition ===
chemin = os.path.join(DOSSIER, FICHIER)
score = converter.parse(chemin)
# === Préparation du tableau "portées x mesures" ===
tableau = []
for p_index, part in enumerate(score.parts, start=1):
ligne = []
for num_mesure in range(1, NB_MESURES + 1):
m = part.measures(num_mesure, num_mesure)
if m is None:
ligne.append("")
else:
contient_note = any(
isinstance(el, (note.Note, chord.Chord))
for el in m.recurse().notes
)
ligne.append(SYMBOLE_NOTE if contient_note else "")
tableau.append(ligne)
print(type(tableau))
print(np.shape(tableau))
print(tableau[:2]) # aperçu des 2 premiers éléments
# === Construction DataFrame ===
df = pd.DataFrame(
tableau,
index=[f"Portée {i+1}" for i in range(len(score.parts))],
columns=[f"Mesure {j+1}" for j in range(NB_MESURES)]
)
# === Export vers Excel ===
#print(f"Le dossier de sortie est : {import os
logging(f"✅ Fichier Excel généré : {fichier_sortie}")
logging("Le script est lancé")
#```
import os
DOSSIER = r"E:\2_M_E_S__P_R_O_J_E_T_S\IA_Cycle\musique\partit_XML"
fichier_sortie = "partition_condensee.xlsx"
# chemin_complet = os.path.join(DOSSIER, fichier_sortie)
chemin_complet = os.path.join(DOSSIER, fichier_sortie)
print("Chemin attendu :", chemin_complet)
if os.path.exists(chemin_complet):
print("✅ Le fichier existe bien à cet endroit.")
else:
print("❌ Fichier introuvable vérifie si le script la bien créé ou si le dossier est correct.") |
Partager