class MicroMIDI::State

The DSL state

Constants

DEFAULT

Attributes

auto_output[RW]
channel[RW]
inputs[R]
last_command[R]
last_note[RW]
listeners[R]
octave[RW]
output_cache[R]
outputs[R]
start_time[R]
super_sticky[RW]
sysex_node[RW]
thru_listeners[R]
velocity[RW]

Public Class Methods

new(inputs, outputs, options = {}) click to toggle source

@param [Array<UniMIDI::Input>, UniMIDI::Input] inputs @param [Array<UniMIDI::Output, IO>, IO, UniMIDI::Output] outputs @param [Hash] options @option options [Fixnum] :channel @option options [Fixnum] :octave @option options [Fixnum] :velocity

# File lib/micromidi/state.rb, line 34
def initialize(inputs, outputs, options = {})
  @inputs = [inputs].flatten
  @outputs = [outputs].flatten

  @channel = options[:channel] || DEFAULT[:channel]
  @velocity = options[:velocity] || DEFAULT[:velocity]
  @octave = options[:octave] || DEFAULT[:octave]

  @auto_output = true
  @last_command = nil
  @last_note = nil
  @listeners = []
  @thru_listeners = []
  @output_cache = []
  @start_time = Time.now.to_f
  @super_sticky = false
end

Public Instance Methods

message_properties(options, *properties) click to toggle source

Return message properties with regard to the current state @param [Hash] options @param [*Symbol] properties @return [Hash]

# File lib/micromidi/state.rb, line 108
def message_properties(options, *properties)
  result = {}
  properties.each do |property|
    result[property] = options[property]
    if !result[property].nil? && (send(property).nil? || @super_sticky)
      send("#{property.to_s}=", result[property])
    end
    result[property] ||= send(property.to_s)
  end
  result
end
record(method, args, block, result) click to toggle source

Record that a command was used @param [Symbol, String] method @param [Array<Object>] args @param [Proc] block @param [Object] result

# File lib/micromidi/state.rb, line 57
def record(method, args, block, result)
  timestamp = now
  message = {
    :message => result,
    :timestamp => timestamp
  }
  @output_cache << message
  @last_command = {
    :method => method,
    :args => args,
    :block => block,
    :timestamp => timestamp
  }
end
toggle_auto_output() click to toggle source

Toggles auto-output mode. In auto-output mode, any messages that are instantiated are sent to any available MIDI outputs. @return [Boolean]

# File lib/micromidi/state.rb, line 100
def toggle_auto_output
  @auto_output = !@auto_output
end
toggle_super_sticky() click to toggle source

Toggles super_sticky mode, a mode where any explicit values used to create MIDI messages automatically become sticky. Normally the explicit value would only be used for the current message.

For example, while in super sticky mode

“‘ruby note “C4”, :channel => 5 note “C3” “`

will have the same results as

“‘ruby channel 5 note “C4” note “C3” “`

@return [Boolean]

# File lib/micromidi/state.rb, line 93
def toggle_super_sticky
  @super_sticky = !@super_sticky
end

Private Instance Methods

now() click to toggle source

A timestamp @return [Float]

# File lib/micromidi/state.rb, line 124
def now
  time = Time.now.to_f - @start_time
  time * 1000
end