roszcz commited on
Commit
0c8bdc2
·
1 Parent(s): d201f92
Files changed (1) hide show
  1. app.py +116 -89
app.py CHANGED
@@ -2,95 +2,122 @@ import streamlit as st
2
  import streamlit_pianoroll
3
  from fortepyan import MidiPiece
4
 
5
- piece = MidiPiece.from_file("haydn.mid")
6
-
7
- st.write("## Display a PianoRoll player")
8
-
9
- code = """
10
- import streamlit_pianoroll
11
- from fortepyan import MidiPiece
12
-
13
- piece = MidiPiece.from_file("haydn.mid")
14
- streamlit_pianoroll.from_fortepyan(piece)
15
- """
16
- st.code(code, language="python")
17
- streamlit_pianoroll.from_fortepyan(piece)
18
-
19
- st.write("## Conditional coloring")
20
- st.write("#### Absolute pitch value condition")
21
-
22
- code = """
23
- df = piece.df
24
- ids = df.pitch > pitch_threshold
25
-
26
- part_a = df[ids]
27
- part_b = df[~ids]
28
- piece_a = MidiPiece(df=part_a)
29
- piece_b = MidiPiece(df=part_b)
30
-
31
- streamlit_pianoroll.from_fortepyan(
32
- piece=piece_a,
33
- secondary_piece=piece_b,
34
- )
35
- """
36
- st.code(code, language="python")
37
-
38
- df = piece.df.copy()
39
-
40
- pitch_threshold = st.number_input(
41
- label="pitch_threshold",
42
- min_value=df.pitch.min(),
43
- max_value=df.pitch.max(),
44
- value=60,
45
- )
46
- ids = df.pitch > pitch_threshold
47
-
48
- part_a = df[ids].copy()
49
- part_b = df[~ids].copy()
50
- piece_a = MidiPiece(df=part_a)
51
- piece_b = MidiPiece(df=part_b)
52
-
53
- streamlit_pianoroll.from_fortepyan(
54
- piece=piece_a,
55
- secondary_piece=piece_b,
56
  )
57
 
58
- st.write("#### Note duration condition")
59
-
60
- code = """
61
- df = piece.df
62
-
63
- ids = df.duration > duration_threshold
64
-
65
- part_a = df[ids]
66
- part_b = df[~ids]
67
- piece_a = MidiPiece(df=part_a)
68
- piece_b = MidiPiece(df=part_b)
69
-
70
- streamlit_pianoroll.from_fortepyan(
71
- piece=piece_a,
72
- secondary_piece=piece_b,
73
- )
74
- """
75
- st.code(code, language="python")
76
 
77
- df = piece.df.copy()
78
-
79
- duration_threshold = st.number_input(
80
- label="duration threshold",
81
- min_value=0.05,
82
- max_value=5.,
83
- value=0.25,
84
- )
85
-
86
- ids = df.duration > duration_threshold
87
-
88
- part_a = df[ids].copy()
89
- part_b = df[~ids].copy()
90
- piece_a = MidiPiece(df=part_a)
91
- piece_b = MidiPiece(df=part_b)
92
-
93
- streamlit_pianoroll.from_fortepyan(
94
- piece=piece_a,
95
- secondary_piece=piece_b,
96
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import streamlit_pianoroll
3
  from fortepyan import MidiPiece
4
 
5
+ st.set_page_config(
6
+ page_title="PianoRoll Demo",
7
+ page_icon=":musical_keyboard:",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  )
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ def main():
12
+ piano_music_demo()
13
+
14
+
15
+ def piano_music_demo():
16
+ piece = MidiPiece.from_file("haydn.mid")
17
+
18
+ st.write("## Display a PianoRoll player")
19
+ st.write("""
20
+ The core functionality of pianorolls includes music playback and visualization.
21
+ If you have a MIDI file with piano music, see here for instructions on interacting with it using Streamlit components.
22
+ """)
23
+
24
+ code = """
25
+ import streamlit_pianoroll
26
+ from fortepyan import MidiPiece
27
+
28
+ piece = MidiPiece.from_file("haydn.mid")
29
+ streamlit_pianoroll.from_fortepyan(piece)
30
+ """
31
+ st.code(code, language="python")
32
+ streamlit_pianoroll.from_fortepyan(piece)
33
+ st.info(
34
+ body="This component is dedicated to piano music, there's no way to interract with multiple instruments.",
35
+ icon="🎹",
36
+ )
37
+
38
+ st.write("## Conditional coloring")
39
+ st.write("""
40
+ To create a pianoroll with different notes in separate colors,
41
+ create two `MidiPiece` objects, each containing the notes for one color.
42
+ """)
43
+ st.write("#### Absolute pitch value condition")
44
+
45
+ code = """
46
+ df = piece.df
47
+ ids = df.pitch > pitch_threshold
48
+
49
+ part_a = df[ids]
50
+ part_b = df[~ids]
51
+ piece_a = MidiPiece(df=part_a)
52
+ piece_b = MidiPiece(df=part_b)
53
+
54
+ streamlit_pianoroll.from_fortepyan(
55
+ piece=piece_a,
56
+ secondary_piece=piece_b,
57
+ )
58
+ """
59
+ st.code(code, language="python")
60
+
61
+ df = piece.df.copy()
62
+
63
+ pitch_threshold = st.number_input(
64
+ label="pitch_threshold",
65
+ min_value=df.pitch.min(),
66
+ max_value=df.pitch.max(),
67
+ value=60,
68
+ )
69
+ ids = df.pitch > pitch_threshold
70
+
71
+ part_a = df[ids].copy()
72
+ part_b = df[~ids].copy()
73
+ piece_a = MidiPiece(df=part_a)
74
+ piece_b = MidiPiece(df=part_b)
75
+
76
+ streamlit_pianoroll.from_fortepyan(
77
+ piece=piece_a,
78
+ secondary_piece=piece_b,
79
+ )
80
+
81
+ st.write("#### Note duration condition")
82
+
83
+ code = """
84
+ df = piece.df
85
+
86
+ ids = df.duration > duration_threshold
87
+
88
+ part_a = df[ids]
89
+ part_b = df[~ids]
90
+ piece_a = MidiPiece(df=part_a)
91
+ piece_b = MidiPiece(df=part_b)
92
+
93
+ streamlit_pianoroll.from_fortepyan(
94
+ piece=piece_a,
95
+ secondary_piece=piece_b,
96
+ )
97
+ """
98
+ st.code(code, language="python")
99
+
100
+ df = piece.df.copy()
101
+
102
+ duration_threshold = st.number_input(
103
+ label="duration threshold",
104
+ min_value=0.05,
105
+ max_value=5.,
106
+ value=0.25,
107
+ )
108
+
109
+ ids = df.duration > duration_threshold
110
+
111
+ part_a = df[ids].copy()
112
+ part_b = df[~ids].copy()
113
+ piece_a = MidiPiece(df=part_a)
114
+ piece_b = MidiPiece(df=part_b)
115
+
116
+ streamlit_pianoroll.from_fortepyan(
117
+ piece=piece_a,
118
+ secondary_piece=piece_b,
119
+ )
120
+
121
+
122
+ if __name__ == "__main__":
123
+ main()