Module: MIDICommunicationsMacOS::TypeConversion

Extended by:
TypeConversion
Included in:
TypeConversion
Defined in:
lib/midi-communications-macos/type_conversion.rb

Overview

Utility methods for converting between MIDI data formats.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.numeric_bytes_to_hex_string(bytes) ⇒ String

Converts an array of numeric bytes to a hex string.

Examples:

TypeConversion.numeric_bytes_to_hex_string([0x90, 0x40, 0x40])
# => "904040"

Parameters:

  • bytes (Array<Integer>)

    array of numeric bytes (e.g., [0x90, 0x40, 0x40])

Returns:

  • (String)

    uppercase hex string (e.g., "904040")



16
17
18
19
20
21
22
23
# File 'lib/midi-communications-macos/type_conversion.rb', line 16

def numeric_bytes_to_hex_string(bytes)
  string_bytes = bytes.map do |byte|
    str = byte.to_s(16).upcase
    str = "0#{str}" if byte < 16
    str
  end
  string_bytes.join
end

Instance Method Details

#numeric_bytes_to_hex_string(bytes) ⇒ String

Converts an array of numeric bytes to a hex string.

Examples:

TypeConversion.numeric_bytes_to_hex_string([0x90, 0x40, 0x40])
# => "904040"

Parameters:

  • bytes (Array<Integer>)

    array of numeric bytes (e.g., [0x90, 0x40, 0x40])

Returns:

  • (String)

    uppercase hex string (e.g., "904040")



16
17
18
19
20
21
22
23
# File 'lib/midi-communications-macos/type_conversion.rb', line 16

def numeric_bytes_to_hex_string(bytes)
  string_bytes = bytes.map do |byte|
    str = byte.to_s(16).upcase
    str = "0#{str}" if byte < 16
    str
  end
  string_bytes.join
end