Skip to content

Commit

Permalink
add streamlit for development flow
Browse files Browse the repository at this point in the history
  • Loading branch information
roszcz committed Sep 27, 2024
1 parent 4bf0991 commit f5ecc37
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
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()
18 changes: 17 additions & 1 deletion fortepyan/midi/structures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Optional
from typing import IO, Optional
from dataclasses import field, dataclass

import numpy as np
Expand Down Expand Up @@ -472,6 +472,22 @@ def piece(self) -> MidiPiece:
)
return out

@classmethod
def from_file(cls, midi_file: IO) -> "MidiFile":
"""
Generic wrapper for the pretty_midi.PrettyMIDI interface.
Args:
midi_file (str or file): Path or file pointer to a MIDI file.
Returns:
MidiFile: A new `MidiFile` object containing the input file.
"""
_midi = pretty_midi.PrettyMIDI(midi_file)

midi_file = cls(_midi=_midi)
return midi_file

@classmethod
def from_piece(cls, piece: MidiPiece) -> "MidiFile":
_midi = pretty_midi.PrettyMIDI()
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ dependencies = [
"Levenshtein>=0.20.9",
"cmcrameri>=1.5",
]

requires-python = ">=3.9"

[project.optional-dependencies]
dev = [
"pre-commit ~= 3.8.0",
"streamlit-pianoroll == 0.7.1"
]

[project.urls]
Homepage = "https://github.com/Nospoko/fortepyan"

Expand Down

0 comments on commit f5ecc37

Please sign in to comment.