Module: MIDICommunications::TypeConversion
- Extended by:
- TypeConversion
- Included in:
- TypeConversion
- Defined in:
- lib/midi-communications/type_conversion.rb
Overview
Utility methods for converting between MIDI data formats.
Class Method Summary collapse
-
.numeric_byte_array_to_hex_string(bytes) ⇒ String
Converts an array of numeric bytes to a hex string.
Instance Method Summary collapse
-
#numeric_byte_array_to_hex_string(bytes) ⇒ String
Converts an array of numeric bytes to a hex string.
Class Method Details
.numeric_byte_array_to_hex_string(bytes) ⇒ String
Converts an array of numeric bytes to a hex string.
Every byte becomes exactly two characters. Without the padding a byte below 0x10 produces one, and the string can no longer be read back as bytes: [0x90, 0x0A, 0x64] came out as "90a64", which is five characters and describes no MIDI message at all.
25 26 27 |
# File 'lib/midi-communications/type_conversion.rb', line 25 def numeric_byte_array_to_hex_string(bytes) bytes.map { |byte| format('%02X', byte) }.join end |
Instance Method Details
#numeric_byte_array_to_hex_string(bytes) ⇒ String
Converts an array of numeric bytes to a hex string.
Every byte becomes exactly two characters. Without the padding a byte below 0x10 produces one, and the string can no longer be read back as bytes: [0x90, 0x0A, 0x64] came out as "90a64", which is five characters and describes no MIDI message at all.
25 26 27 |
# File 'lib/midi-communications/type_conversion.rb', line 25 def numeric_byte_array_to_hex_string(bytes) bytes.map { |byte| format('%02X', byte) }.join end |