Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement MidiFile with pretty_midi #7

Merged
merged 8 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.pymon
.plan
.env
tmp/
Expand Down
40 changes: 40 additions & 0 deletions dashboards/merge_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import streamlit as st
from streamlit_pianoroll import from_fortepyan

from fortepyan import MidiFile


def main():
st.write("# Test MidiFile merging")
uploaded_files = st.file_uploader(
label="Upload one or many MIDI files",
accept_multiple_files=True,
)

if not uploaded_files:
st.write("Waiting for files")
return

midi_files = []
for uploaded_file in uploaded_files:
midi_file = MidiFile.from_file(uploaded_file)
midi_files.append(midi_file)

merge_spacing = st.number_input(
label="merge spacing [s] (time interval inserted between files)",
min_value=0.0,
max_value=30.0,
value=5.0,
)
merged_midi_file = MidiFile.merge_files(
midi_files=midi_files,
space=merge_spacing,
)
st.write("Duration after merge:", merged_midi_file.duration)
st.write("Number of notes after merge:", merged_midi_file.piece.size)

from_fortepyan(merged_midi_file.piece)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion fortepyan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# Pretty MIDI will throw an unwanted error for large files with high PPQ
# This is a workaround
# https://github.com/craffel/pretty-midi/issues/112
pretty_midi.pretty_midi.MAX_TICK = 1e10
pretty_midi.MAX_TICK = 1e10
4 changes: 2 additions & 2 deletions fortepyan/audio/render.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import tempfile
from typing import Union

import pretty_midi
from pydub import AudioSegment
from midi2audio import FluidSynth

from fortepyan.audio import soundfont
from fortepyan.midi import structures
from fortepyan.midi import containers as midi_containers


def midi_to_wav(midi: Union[structures.MidiFile, structures.MidiPiece], wavpath: str):
Expand Down Expand Up @@ -41,7 +41,7 @@ def midi_to_wav(midi: Union[structures.MidiFile, structures.MidiPiece], wavpath:
# Add an silent event to make sure the final notes
# have time to ring out
end_time = midi.get_end_time() + 0.2
pedal_off = midi_containers.ControlChange(64, 0, end_time)
pedal_off = pretty_midi.ControlChange(64, 0, end_time)
midi.instruments[0].control_changes.append(pedal_off)

midi.write(tmp_midi_path)
Expand Down
324 changes: 0 additions & 324 deletions fortepyan/midi/containers.py

This file was deleted.

Loading
Loading