CornetAI / src /generadores /genmidisreales.py
jmp684's picture
Upload 12 files
4f8d622 verified
import pretty_midi
import random
import os
# --- CONFIGURACIÓN ---
OUTPUT_FOLDER = "dataset_midis_guia"
NUM_FILES = 20
ALLOWED_PITCHES = [67, 68, 72, 73] # Sol4, Lab4, Do5, Reb5
def generate_human_guides():
if not os.path.exists(OUTPUT_FOLDER):
os.makedirs(OUTPUT_FOLDER)
print(f"Generando {NUM_FILES} partituras guía para grabación...")
for i in range(NUM_FILES):
pm = pretty_midi.PrettyMIDI()
instrument = pretty_midi.Instrument(program=0, name="Corneta Guia")
# Empezamos en el segundo 2.0
current_time = 2.0
total_duration = 15.0
while current_time < total_duration:
# LÓGICA MÁS MUSICAL
pitch = random.choice(ALLOWED_PITCHES)
# 0.5s, 1.0s, 2.0s
duration_choice = random.choice([0.5, 0.8, 1.2, 2.0])
# Variamos la intensidad (Dinámica)
velocity = random.randint(95, 120)
note = pretty_midi.Note(
velocity=velocity,
pitch=pitch,
start=current_time,
end=current_time + duration_choice
)
instrument.notes.append(note)
# TIEMPO DE RESPIRACIÓN
gap = random.uniform(0.3, 0.8)
current_time += duration_choice + gap
pm.instruments.append(instrument)
filename = f"guia_{i:02d}.mid"
pm.write(os.path.join(OUTPUT_FOLDER, filename))
print(f"-> {filename}")
print("¡Listos! Ahora conviértelos a WAV y úsalos de backing track.")
if __name__ == "__main__":
generate_human_guides()