from mido import Message, MidiFile, MidiTrack import re import pandas as pd df =…
- User
from mido import Message, MidiFile, MidiTrack import re import pandas as pd
df = pd.read_excel("instrument notes.xlsx")
df = df.iloc[1:]
note_map = {}
for index, row in df.iterrows(): midi_note_number = row[0] instrument_note_type = row[1]
codenote_map[instrument_note_type] = midi_note_numberbpm = int(input("Enter the BPM: ")) beats_per_bar = int(input("Enter the number of beats per bar: ")) note_type = int(input("Enter the note type that gets the beat (e.g. 4 for quarter notes): "))
midi_file = MidiFile() midi_track = MidiTrack()
while True: instrument_note_type = input("Enter the instrument note type (or 'q' to quit): ")
codeif instrument_note_type == 'q': break midi_note_number = note_map[instrument_note_type] positions_str = input("Enter the positions you want to select (e.g. 1 3 5): ") # Split the string on any combination of spaces and commas positions = list(map(int, re.split(r'[\s,]+', positions_str))) # Calculate the timing values for the selected on-beat and off-beat notes timing_values = calculate_timing_values(bpm, beats_per_bar, note_type, positions) # Create a note_on message for the MIDI note and add it to the track note_on = Message("note_on", note=midi_note_number, velocity=127, time=0) midi_track.append(note_on) # Iterate over the timing values and create a note_off message for each timing value, with the corresponding time value for timing_value in timing_values: note_off = Message("note_off", note=midi_note_number, velocity=127, time=int(timing_value)) midi_track.append(note_off)midi_file.tracks.append(midi_track)
midi_filename = input("Enter the name of the MIDI file: ")
midi_file.save(midi_filename)
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.