Cabbage Logo
Back to Cabbage Site

Make CsScore length dynamic based on midi file length

Hi there!

We are rendering 1 hour of audio offline with the CsScore options set to:
f 0 3600
i 1 0 3600

The midi file we are using to feed our instruments changes its BPM as it goes. So while 2000 bars ends up being close to an hour in length, we end up with a file that either gets cut off too soon or has some blank space at the end.

Is there a way to make the CsScore length end when the midi file ends so we can avoid the render cutting off too soon or leaving blank audio?

This is an interesting one. I’m not sure what the best approach here as you have no way of telling if the MIDI file has actually ended. There is an exitnow that supposedly stops Csound. One possible, yet hacky, way of doing it would be to add a MIDI note number 0 to the end of your MIDI file. Then exit Csound if p4 is ever 0? I can’t imagine you have many note number 0s in your MIDI file?

I will give that a shot and let you know if it works :slight_smile:


That seems to have done the trick. Adding a midi note 0 at the end of the file then having an instrument checking for that 0 with an exit now. It does just kind of chop things off so I am testing adding a timer in after the 0 is received to let the final notes play out.

I also found the -T flag that terminates the render/playback at the end of the midi file which is convenient but creates a harsh ending where the final notes don’t resonate to their conclusion.

Thanks for the help!

Nice. Glad to hear it provides some kind of solution!