adafruit / FifteenStep

A general purpose Arduino MIDI sequencer library
GNU General Public License v3.0
130 stars 17 forks source link

byte doesn't allow for negative #9

Open douweh opened 4 years ago

douweh commented 4 years ago

The definition of addNote has a (byte typed) step param (with a default value of -1); therefore the following code (lines 369-372):

if(step == -1)
    position = _quantizedPosition();
  else
    position = step;

should result in position being equal to _quantizedPosition() when you omit the step from the addNote call.

However a byte doesn't allow for a negative value (and -1 gets silently casted to 255: see https://www.arduino.cc/reference/en/language/variables/data-types/byte/). Therefore when omitting the step (or setting it to -1) the actual value will be 255 and consequently the position will also result in 255... and not what we expect.

Typing the step param as byte solves this.