-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add helper methods to pack and unpack midi data bytes into number types #333
Comments
pack methods could accept a number of the specified type and maybe an endian value and either return an array, or write to the stream directly (TBD). unpack methods could accept a reference to an array and a starting index and maybe an endian value and would return the parsed value in the specified type |
For packing, if we return to an array instead of writing directly to the stream we have the option of leveraging unused bits before writing into the stream. |
Also when unpacking, an optional length param could be used in the case that less bytes than needed for the specific type are returned. |
@zfields curious to hear your thoughts on this proposal. I assume this would belong in FirmataMarshaller. |
@finson did something similar in his Luni (arduino device driver) library, but for translating larger numbers to and from an array of bytes: https://github.com/finson/Luni/blob/b0.10-i5-globals/src/Device/ByteOrder.h. This is what initially inspired my idea to do something similar but for 7-bit midi data bytes, which is not 2 midi bytes for each 8 bit byte, it's based on the number of bits (7 per midi data byte so 3 midi data bytes to create a 16 bit integer and 5 to create a 32 bit integer, etc). |
@soundanalogous I think they would belong as private members to
Here, you would need the ability to pack the
Here, you don't need anything extra, because basic ASCII has a range between [0, 127]. However, extended ASCII would require more sophisticated The point being, as long as the |
could also consider supporting floats if necessary, however there is a huge advantage to using integers over floats whenever possible on microcontrollers without native floating point processors (most MCUs supported by Firmata). Something like a 40x more efficient using integers. |
examples:
packUint8 / unpackUint8
packInt8 / unpackInt8
packUint16 / unpackUint16
packInt16 / unpackInt16
packUint32 / unpackUint32
packInt32 / unpackInt32
Not sure if we need a set for 64 bits.
Also open to a naming convention here.
The text was updated successfully, but these errors were encountered: