DBraun / DawDreamer

Digital Audio Workstation with Python; VST instruments/effects, parameter automation, FAUST, JAX, Warp Markers, and JUCE processors
GNU General Public License v3.0
918 stars 66 forks source link

engine.set_bpm(123.45) should affect MIDI timing #89

Closed kyungyunlee closed 2 years ago

kyungyunlee commented 2 years ago

Hi, thanks for the great library!

While trying to confirm that DawDreamer renders MIDI exactly the same as when rendering with Reaper (or any DAW), I found that DawDreamer renders at a slower tempo. Any idea why this is happening?

I am rendering using Addictive keys with a preset I saved.

  engine = daw.RenderEngine(SAMPLE_RATE, BUFFER_SIZE)
  synth = engine.make_plugin_processor("my_synth", vst)
  assert synth.get_name() == "my_synth"

  if ".vst3" in vst:
      assert synth.load_vst3_preset(vst_preset_path)
  else:
      assert synth.load_preset(vst_preset_path)

  assert synth.load_midi(midi_path)

  time.sleep(0.5)

  graph = [
      (synth, []),
  ]
  engine.load_graph(graph)

  engine.render(duration)  
  audio = engine.get_audio()  # Returns array shaped (2, NUM_SAMPLES)

  sf.write(output_wav_path, audio.transpose(), SAMPLE_RATE)
Screen Shot 2022-04-28 at 11 10 11 AM
DBraun commented 2 years ago

Taking a slight guess here. The MIDI file contains BPM information at PPQ-rate. Right now load_midi uses this info to place the notes at seconds positions on the timeline. Then engine.set_bpm(90.) or anything else will actually have no effect. I would want to improve this in the future so that you can change the BPM after loading a MIDI file (BPM does affect plugins and PlaybackWarpProcessor). But long story short, my guess is that the BPM of the MIDI file is not what Reaper is set to.

And the unfortunate short term solution is to use some other python library to parse the MIDI notes and feed them to the synth.add_midi_note one at a time with a custom time-scaling.

kyungyunlee commented 2 years ago

@DBraun Oops, I think it's a Reaper thing...Works fine with Logic Pro! Thanks for the quick comment.

I think the changing bpm option would also be quite useful in the future.

DBraun commented 2 years ago

New features in 0.6.6 fix this!