| import pretty_midi
|
| import random
|
| import os
|
|
|
|
|
| OUTPUT_FOLDER = "dataset_midis_guia"
|
| NUM_FILES = 20
|
| ALLOWED_PITCHES = [67, 68, 72, 73]
|
|
|
| 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")
|
|
|
|
|
| current_time = 2.0
|
| total_duration = 15.0
|
|
|
| while current_time < total_duration:
|
|
|
| pitch = random.choice(ALLOWED_PITCHES)
|
|
|
|
|
| duration_choice = random.choice([0.5, 0.8, 1.2, 2.0])
|
|
|
|
|
| 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)
|
|
|
|
|
| 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() |