alda icon indicating copy to clipboard operation
alda copied to clipboard

Validate MIDI note range

Open daveyarwood opened this issue 5 years ago • 6 comments

Currently, attempting to play a note that is out of the MIDI note range (0-127) results in a confusing error message:

$ alda play -c 'piano: o10 c'
[27713] Parsing/evaluating...
[27713] ERROR data1 out of range: 132

We should catch this and throw our own error with a clearer message.

daveyarwood avatar Mar 07 '19 14:03 daveyarwood

I did some investigation on this one. It took me some time to find the source of the "Parsing/evaluating..." message. I eventually found it on alda-client-java//src/alda/AldaServer.java, method play - but now I'm wondering where in the core project this change would take place. If someone can help me and point out on the right direction, I'd appreciate it. Meanwhile I'll try and look into other issues.

iggar avatar Apr 11 '19 13:04 iggar

We're calculating the MIDI note number here: https://github.com/alda-lang/alda-core/blob/d45039101bf347eb84be7afa471db1b812291914/src/alda/lisp/events/note.clj#L40-L42

I think throwing an ex-info when (> midi-note 127) ought to do the trick.

daveyarwood avatar Apr 11 '19 14:04 daveyarwood

...more like when (or (neg? midi-note) (> midi-note 127))

daveyarwood avatar Apr 11 '19 14:04 daveyarwood

I don't remember off-hand whether I fixed this in Alda v2 or not. Keeping this issue open until I have a chance to confirm.

daveyarwood avatar Jan 01 '21 03:01 daveyarwood

I just tried this with Alda 2, and interestingly, playback seems to just silently fail once it gets up to the too-high note. No error message is printed either in the client or in the player logs.

So the disposition is still the same: we should add validation that the MIDI note isn't < 0 or > 127, and I think we should do that validation at score evaluation time instead of playback-time, so that we can display a helpful message earlier.

I think the place to add the validation now is right here after we calculate the MIDI note based on the octave, note letter and accidentals.

daveyarwood avatar Jul 01 '21 02:07 daveyarwood

I have added the validation at the specified place and submitted a PR in response to this issue. Also ran the addition against the test suite.

KartikYZ avatar Dec 31 '21 03:12 KartikYZ

Fixed in https://github.com/alda-lang/alda/pull/461. Will keep this issue open until I have a chance to release it.

daveyarwood avatar Nov 16 '22 14:11 daveyarwood

Fixed in Alda 2.2.4.

daveyarwood avatar Nov 24 '22 18:11 daveyarwood