alda-lang / alda-core

The core machinery of Alda
80 stars 26 forks source link

MIDI Export fails randomly with or without error msg #77

Closed truj closed 3 years ago

truj commented 4 years ago

If a file contains too many instruments, the MIDI export does not always react with an error message. Here are two export runs with the same file.

This run reacts like it should:

alda export -f too-many-instruments.alda -o /tmp/output.mid && echo SUCCESS || echo FAILED
[27713] Parsing/evaluating...
[27713] ERROR Ran out of MIDI channels! :(
FAILED

But this one doesn't:

alda export -f too-many-instruments.alda -o /tmp/output.mid && echo SUCCESS || echo FAILED
[27713] Parsing/evaluating...
[27713] Exporting...
SUCCESS

In both cases no file is created.

The export fails always. But sometimes with exit code 1 and an error message, and sometimes with exit code 0 and without error.

Expected behaviour for files with too many instruments: Always print the error message. Always exit with an exit code other than 0.

Background: In Midica I'm using ALDA's exit code for the ALDA file importer. If it's different from 0, I don't try to import the exported MIDI file.

daveyarwood commented 4 years ago

Interesting find! I was able to repro this locally with the following score that has 20 instruments (well over the limit of 16):

piano: c
guitar: c
clarinet: c
flute: c
bassoon: c
timpani: c
xylophone: c
percussion: c
harmonica: c
accordion: c
trumpet: c
trombone: c
tuba: c
french-horn: c
glockenspiel: c
electric-guitar-distorted: c
violin: c
viola: c
cello: c
double-bass: c

If I run alda export -f /tmp/too-many-instruments.alda -o /tmp/too-many-instruments.mid repeatedly, it mostly prints the error message and exits 1, but eventually, there was no error message and it exited 0, yet it didn't successfully export the MIDI file.

I did this again while tailing the worker logs (tail -F ~/.alda/logs/error.log) and I saw that every single time, java.lang.Exception: Ran out of MIDI channels! :( was logged. Even when the client exited successfully and didn't print an error message!

So I think this is probably some kind of miscommunication between the client, server, and worker processes. That whole setup is complicated and from time to time, I see wires getting crossed like this.

I know this is annoying, but I'm going to have to punt on fixing it in Alda v1. Alda v2 has a much simpler architecture that will make this experience much better, so I'm choosing to continue to focus on moving forward with developing Alda v2. In the new version of Alda, either:

daveyarwood commented 4 years ago

For now, as a workaround, I would recommend ignoring Alda's exit code and checking to see whether the file was exported or not.

truj commented 4 years ago

OK, I'll add a MIDI file check as a workaround.

daveyarwood commented 3 years ago

This is no longer an issue in Alda v2, which will be released soon, so I am closing this.

The client will be in charge of assigning MIDI channels, so you'll get an error immediately if you use too many of them, no need to communicate to a player process at all.

I do still intend to do something like this -- will capture it in a separate issue.