Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,15 +70,18 @@ class HexachordApp:
|
|
| 70 |
# returns 3 triples of midipath, piano roll, audio player
|
| 71 |
reals = self._hexachord.generate_3_chords_realizations(self._hexachord_base_sequence)
|
| 72 |
midi_path1 = self.create_midi(reals[0], "real1.mid")
|
| 73 |
-
piano_roll_path1 = self.generate_piano_roll(reals[0], "real1.png")
|
|
|
|
| 74 |
audio_path1 = self.convert_midi_to_audio(midi_path1, "real1")
|
| 75 |
midi_path2 = self.create_midi(reals[1], "real2.mid")
|
| 76 |
-
piano_roll_path2 = self.generate_piano_roll(reals[1], "real2.png")
|
|
|
|
| 77 |
audio_path2 = self.convert_midi_to_audio(midi_path2, "real2")
|
| 78 |
midi_path3 = self.create_midi(reals[2], "real3.mid")
|
| 79 |
-
piano_roll_path3 = self.generate_piano_roll(reals[2], "real3.png")
|
|
|
|
| 80 |
audio_path3 = self.convert_midi_to_audio(midi_path3, "real3")
|
| 81 |
-
return midi_path1,
|
| 82 |
|
| 83 |
def create_midi(self, chords, file_name):
|
| 84 |
mid = MidiFile()
|
|
@@ -184,12 +187,10 @@ class HexachordApp:
|
|
| 184 |
return "Invalid input. Enter 6 MIDI note numbers separated by spaces."
|
| 185 |
chords = self.generate_chords(notes, itvl)
|
| 186 |
midi_path = self.create_midi(chords, "base_chords.mid")
|
| 187 |
-
# piano_roll_path = self.generate_piano_roll(chords, "base_chords.png")
|
| 188 |
score_path = self.generate_svg (midi_path, "score_base_chords.svg")
|
| 189 |
audio_path = self.convert_midi_to_audio(midi_path, "base_chords")
|
| 190 |
-
|
| 191 |
# return midi_path, piano_roll_path, audio_path
|
| 192 |
-
return midi_path, score_path, audio_path
|
| 193 |
|
| 194 |
def render(self):
|
| 195 |
with gr.Blocks() as ui:
|
|
@@ -211,10 +212,19 @@ class HexachordApp:
|
|
| 211 |
)
|
| 212 |
generate_button = gr.Button("Generate Chords")
|
| 213 |
with gr.Row():
|
|
|
|
| 214 |
midi_output = gr.File(label="Download MIDI File", scale=1)
|
| 215 |
-
# piano_roll_output = gr.Image(label="Piano Roll Visualization")
|
| 216 |
score_output = gr.Image(label="Score Visualization", scale=3)
|
| 217 |
audio_output = gr.Audio(label="Play Generated Chords", value=None, interactive=False, scale=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
hexachord_selector.change(
|
| 219 |
fn=self.get_selected_hexachord,
|
| 220 |
inputs=[hexachord_selector],
|
|
@@ -224,35 +234,18 @@ class HexachordApp:
|
|
| 224 |
fn=self.process_hexachord,
|
| 225 |
inputs=[hexachord_input, interval_switch],
|
| 226 |
# outputs=[midi_output, piano_roll_output, audio_output]
|
| 227 |
-
outputs =
|
| 228 |
)
|
| 229 |
# Pressing Enter in the textbox also triggers processing
|
| 230 |
hexachord_input.submit(
|
| 231 |
fn=self.process_hexachord,
|
| 232 |
inputs=[hexachord_input, interval_switch],
|
| 233 |
-
outputs=
|
| 234 |
)
|
| 235 |
|
| 236 |
with gr.TabItem("Alternative Chord Realizations"):
|
| 237 |
gr.Markdown("Alternative Chord Realizations")
|
| 238 |
|
| 239 |
-
realization_button = gr.Button("Generate Alternative Realizations")
|
| 240 |
-
realization_outputs = []
|
| 241 |
-
|
| 242 |
-
for i in range(3): # Three alternative realizations
|
| 243 |
-
with gr.Group():
|
| 244 |
-
gr.Markdown(f"#### Realization {i + 1}")
|
| 245 |
-
midi_output = gr.File(label="Download MIDI File")
|
| 246 |
-
piano_roll = gr.Image(label=f"Piano Roll {i + 1}")
|
| 247 |
-
audio_player = gr.Audio(label=f"Play Chords {i + 1}", interactive=False)
|
| 248 |
-
realization_outputs.append((midi_output, piano_roll, audio_player))
|
| 249 |
-
|
| 250 |
-
# Clicking the button triggers realization generation
|
| 251 |
-
realization_button.click(
|
| 252 |
-
fn=self.generate_realizations,
|
| 253 |
-
inputs=[],
|
| 254 |
-
outputs=[output for trip in realization_outputs for output in trip]
|
| 255 |
-
)
|
| 256 |
|
| 257 |
with gr.TabItem("Settings"):
|
| 258 |
gr.Markdown("### Configuration Options")
|
|
|
|
| 70 |
# returns 3 triples of midipath, piano roll, audio player
|
| 71 |
reals = self._hexachord.generate_3_chords_realizations(self._hexachord_base_sequence)
|
| 72 |
midi_path1 = self.create_midi(reals[0], "real1.mid")
|
| 73 |
+
# piano_roll_path1 = self.generate_piano_roll(reals[0], "real1.png")
|
| 74 |
+
score_path1 = self.generate_svg(midi_path1, "real1.svg")
|
| 75 |
audio_path1 = self.convert_midi_to_audio(midi_path1, "real1")
|
| 76 |
midi_path2 = self.create_midi(reals[1], "real2.mid")
|
| 77 |
+
# piano_roll_path2 = self.generate_piano_roll(reals[1], "real2.png")
|
| 78 |
+
score_path2 = self.generate_svg(midi_path2, "real2.svg")
|
| 79 |
audio_path2 = self.convert_midi_to_audio(midi_path2, "real2")
|
| 80 |
midi_path3 = self.create_midi(reals[2], "real3.mid")
|
| 81 |
+
# piano_roll_path3 = self.generate_piano_roll(reals[2], "real3.png")
|
| 82 |
+
score_path3 = self.generate_svg(midi_path3, "real3.svg")
|
| 83 |
audio_path3 = self.convert_midi_to_audio(midi_path3, "real3")
|
| 84 |
+
return midi_path1, score_path1, audio_path1, midi_path2, score_path2, audio_path2, midi_path3, score_path3, audio_path3
|
| 85 |
|
| 86 |
def create_midi(self, chords, file_name):
|
| 87 |
mid = MidiFile()
|
|
|
|
| 187 |
return "Invalid input. Enter 6 MIDI note numbers separated by spaces."
|
| 188 |
chords = self.generate_chords(notes, itvl)
|
| 189 |
midi_path = self.create_midi(chords, "base_chords.mid")
|
|
|
|
| 190 |
score_path = self.generate_svg (midi_path, "score_base_chords.svg")
|
| 191 |
audio_path = self.convert_midi_to_audio(midi_path, "base_chords")
|
|
|
|
| 192 |
# return midi_path, piano_roll_path, audio_path
|
| 193 |
+
return (midi_path, score_path, audio_path) + self.generate_realizations()
|
| 194 |
|
| 195 |
def render(self):
|
| 196 |
with gr.Blocks() as ui:
|
|
|
|
| 212 |
)
|
| 213 |
generate_button = gr.Button("Generate Chords")
|
| 214 |
with gr.Row():
|
| 215 |
+
gr.Markdown(f"#### base chords")
|
| 216 |
midi_output = gr.File(label="Download MIDI File", scale=1)
|
|
|
|
| 217 |
score_output = gr.Image(label="Score Visualization", scale=3)
|
| 218 |
audio_output = gr.Audio(label="Play Generated Chords", value=None, interactive=False, scale=3)
|
| 219 |
+
realization_outputs = [midi_output, score_output, audio_output]
|
| 220 |
+
for i in range(3): # Three alternative realizations
|
| 221 |
+
with gr.Row():
|
| 222 |
+
gr.Markdown(f"#### Realization {i + 1}")
|
| 223 |
+
midi_output = gr.File(label="Download MIDI File", scale=1)
|
| 224 |
+
piano_roll = gr.Image(label=f"Piano Roll {i + 1}", scale=3)
|
| 225 |
+
audio_player = gr.Audio(label=f"Play Chords {i + 1}", interactive=False, scale=3)
|
| 226 |
+
realization_outputs += (midi_output, piano_roll, audio_player)
|
| 227 |
+
|
| 228 |
hexachord_selector.change(
|
| 229 |
fn=self.get_selected_hexachord,
|
| 230 |
inputs=[hexachord_selector],
|
|
|
|
| 234 |
fn=self.process_hexachord,
|
| 235 |
inputs=[hexachord_input, interval_switch],
|
| 236 |
# outputs=[midi_output, piano_roll_output, audio_output]
|
| 237 |
+
outputs = realization_outputs
|
| 238 |
)
|
| 239 |
# Pressing Enter in the textbox also triggers processing
|
| 240 |
hexachord_input.submit(
|
| 241 |
fn=self.process_hexachord,
|
| 242 |
inputs=[hexachord_input, interval_switch],
|
| 243 |
+
outputs=realization_outputs
|
| 244 |
)
|
| 245 |
|
| 246 |
with gr.TabItem("Alternative Chord Realizations"):
|
| 247 |
gr.Markdown("Alternative Chord Realizations")
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
with gr.TabItem("Settings"):
|
| 251 |
gr.Markdown("### Configuration Options")
|