/motherbrain

wip: Ruby library for creating device-specific MIDI system exclusive messaging interfaces

Primary LanguageRuby

module Motherbrain do
  add_fmt
    # named placeholders

  snd_msg_fmt
  rcv_msg_fmt
end


Format strings:
  - Each byte is notated in hex or as a byte specifier or a combination
  - Byte specifiers consist of a label string followed by a number,
    optionally followed by an "m" or "l" (case insensitive) indicator,
    enclosed in square brackets
    - Label string is converted to a symbol and used for reference
      when adding commands
    - the number is the number of bits for the value
    - trailing "m" or "l" indicates most signifant bit or least significant bit
        - left-padded with 0s if "l"/"L"
        - right-padded with 0s if "m"/"M"
        - if "m" or "l" indicator is not present, do not pad


[device_num:4m] - 4 bit number (most significant)
[foo:8M]        - 8 bit number (most significant)
[bar:7l]        - 7 bit number (least significant) -- (pad beginning w/ 0)
[baz:8L]        - 8 bit number (least significant)

Adding a format using string style:

add_fmt(:transmit, "43 1[device_number:4] 5E [pah:7l] [pam:7l] [pal:7l] [dvm:7l] [dvl:7l]")

Adding a format using block style:

  add_fmt :transmit do
    add("43")
    add("1[device_number:4]")
    add("5E")

    %w{pah pam pal dvm dvl}.each {|label| add("[#{label}:7L]") }
  end


Add a command:

add_cmd(:do_something, {
  :format         => :transmit,  # which format to use

  :device_number  => 4,   # set fixed values
  :pah            => 11,  # "
  :pam            => 12,  # "
  :pal            => 66,  # "

  # Argument value to the command will be split across these bytes (in order)
  :value_bytes    => [:dvm, :dvl]
})

# calling the command method with a single value argument
do_something(1667)



COMMAND DEFINITIONS

# transmit commands
tx do
  # omit f0 and f7 because these are standard
  # (or ignore if present?)

  # Order matters!
  # Set values that will be set later to nil
  bytes(
    yamaha_id:                0x43,
    device_number:            0x15,
    model_id:                 0x5E,
    parameter_address_high:   nil,
    parameter_address_middle: nil,
    parameter_address_low:    nil,
    data_value_ms:            nil,
    data_value_ls:            nil
  )

  # "performance", "common", etc are arbitrary
  # names corresponding to naming used in
  # the MIDI device's specs

  performance do
    common do
      # :lo and :hi params set minimum and maximum
      # input val -- should raise exception if
      # outside range
      name_0(
        parameter_address_high:   0x10,
        parameter_address_middle: 0x00,
        parameter_address_low:    0x11,
        low_limit:                0x20,
        high_limit:               0x7F
      )
    end
  end
end