Need help converting MIDI to gp tabs #43
Unanswered
petr-michovsky
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey! I'm having trouble setting up my project so that I can read in a MIDI file using mido that contains drum MIDI for a whole song. I have sucessfully managed to extract the MIDI events from the file, but I'm having a hard time figuring out how to convert the MIDI ticks into gp time formats. So far I've only managed to import a single measure with all notes being quarter notes. I couldn't even figure out how to change the values to not be quarter notes to begin with. I've read the documentation and source code several time, but I can't seem to figure it out. If anybody would help me resolve my issue, I would be very grateful!
Leaving my code below:
CODE
import mido
import guitarpro as gp
from guitarpro.models import *
"""
The Note object represents a point on a single vertical line in the measure/bar.
The Beat object represents the collection of notes at a specific time.
The Measure object represents one bar.
"""
DEFAULT_PERCUSSION_CHANNEL = 9
Load the MIDI file
midi_file = mido.MidiFile('test_midi.mid')
ppq = midi_file.ticks_per_beat # Get PPQ (Pulses Per Quarter Note) from the MIDI file
print(f"PPQ: {ppq}")
gp_midi_map = {
"Kick": 35,
"Snare": 38,
"Highest Tom": 50,
"High Tom": 48,
"Mid Tom": 47,
"Floor Tom": 41,
"Floor Tom 2": 43,
"Hat": 42,
"Hat Open": 46,
"Foot X Hat Closet": 44,
"Crash": 49,
"Crash 2": 57,
"Ride": 51,
"China": 52,
"Ride Bell": 53,
"Splash": 55,
"Cowbell": 56,
}
ggd_midi_map = {
"Kick": 24,
"Snare": 26
}
reverse_ggd_midi_map = {value: key for key, value in ggd_midi_map.items()}
print("reverse_ggd_midi_map:", reverse_ggd_midi_map)
print("gp_midi_map:", gp_midi_map)
def extract_measure(midi_file_path, measure_number, ppq, time_signature=(4, 4), bpm=130):
# Load the MIDI file
midi_file = mido.MidiFile(midi_file_path)
first_measure = extract_measure('test_midi.mid', 1, ppq=480, bpm=130)
second_measure = extract_measure('test_midi.mid', 5, ppq=480, bpm=130)
def ticks_to_guitar_pro_duration(ticks):
# Example for a quarter note duration
beats = ticks / ppq
duration_percent = beats / 1.0 # Assuming 1 beat for a quarter note
return duration_percent
def parse_midi_for_drums():
drum_events = []
def create_empty_guitar_pro_track(bpm, song_name, artist):
print(f"Creating Guitar Pro Track: {song_name} by {artist} at {bpm} BPM")
Example usage
create_empty_guitar_pro_track(130, 'My Song', 'My Artist')
Beta Was this translation helpful? Give feedback.
All reactions