skytnt commited on
Commit
aa6fbf4
1 Parent(s): c51a1c9

fix visualizer

Browse files
Files changed (2) hide show
  1. app.py +4 -11
  2. javascript/app.js +5 -1
app.py CHANGED
@@ -173,12 +173,8 @@ def run(model_name, tab, instruments, drum_kit, bpm, mid, midi_events, gen_event
173
  with open(f"output.mid", 'wb') as f:
174
  f.write(MIDI.score2midi(mid))
175
  audio = synthesis(MIDI.score2opus(mid), soundfont_path)
176
- # resend all msgs
177
- msgs = [create_msg("visualizer_end", None), create_msg("visualizer_clear", True)]
178
- for tokens in mid_seq:
179
- msgs.append(create_msg("visualizer_append", tokenizer.tokens2event(tokens)))
180
- msgs.append(create_msg("visualizer_end", None))
181
- yield mid_seq, "output.mid", (44100, audio), send_msgs(msgs)
182
 
183
 
184
  def cancel_run(mid_seq):
@@ -188,11 +184,8 @@ def cancel_run(mid_seq):
188
  with open(f"output.mid", 'wb') as f:
189
  f.write(MIDI.score2midi(mid))
190
  audio = synthesis(MIDI.score2opus(mid), soundfont_path)
191
- msgs = [create_msg("visualizer_end", None), create_msg("visualizer_clear", True)]
192
- for tokens in mid_seq:
193
- msgs.append(create_msg("visualizer_append", tokenizer.tokens2event(tokens)))
194
- msgs.append(create_msg("visualizer_end", None))
195
- return "output.mid", (44100, audio), send_msgs(msgs)
196
 
197
 
198
  def load_javascript(dir="javascript"):
 
173
  with open(f"output.mid", 'wb') as f:
174
  f.write(MIDI.score2midi(mid))
175
  audio = synthesis(MIDI.score2opus(mid), soundfont_path)
176
+ events = [tokenizer.tokens2event(tokens) for tokens in mid_seq]
177
+ yield mid_seq, "output.mid", (44100, audio), send_msgs([create_msg("visualizer_end", events)])
 
 
 
 
178
 
179
 
180
  def cancel_run(mid_seq):
 
184
  with open(f"output.mid", 'wb') as f:
185
  f.write(MIDI.score2midi(mid))
186
  audio = synthesis(MIDI.score2opus(mid), soundfont_path)
187
+ events = [tokenizer.tokens2event(tokens) for tokens in mid_seq]
188
+ return "output.mid", (44100, audio), send_msgs([create_msg("visualizer_end", events)])
 
 
 
189
 
190
 
191
  def load_javascript(dir="javascript"):
javascript/app.js CHANGED
@@ -427,7 +427,7 @@ customElements.define('midi-visualizer', MidiVisualizer);
427
  handled_msgs.push(msg.uuid);
428
  switch (msg.name) {
429
  case "visualizer_clear":
430
- midi_visualizer.clearMidiEvents(msg.data);
431
  createProgressBar(midi_visualizer_container_inited)
432
  break;
433
  case "visualizer_append":
@@ -439,6 +439,10 @@ customElements.define('midi-visualizer', MidiVisualizer);
439
  setProgressBar(midi_visualizer_container_inited, progress, total)
440
  break;
441
  case "visualizer_end":
 
 
 
 
442
  midi_visualizer.finishAppendMidiEvent()
443
  midi_visualizer.setPlayTime(0);
444
  removeProgressBar(midi_visualizer_container_inited);
 
427
  handled_msgs.push(msg.uuid);
428
  switch (msg.name) {
429
  case "visualizer_clear":
430
+ midi_visualizer.clearMidiEvents(false);
431
  createProgressBar(midi_visualizer_container_inited)
432
  break;
433
  case "visualizer_append":
 
439
  setProgressBar(midi_visualizer_container_inited, progress, total)
440
  break;
441
  case "visualizer_end":
442
+ midi_visualizer.clearMidiEvents(true);
443
+ msg.data.forEach( value => {
444
+ midi_visualizer.appendMidiEvent(value);
445
+ })
446
  midi_visualizer.finishAppendMidiEvent()
447
  midi_visualizer.setPlayTime(0);
448
  removeProgressBar(midi_visualizer_container_inited);