class MicroMIDI::State
The DSL state
Constants
- DEFAULT
Attributes
Public Class Methods
@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
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 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
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
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
A timestamp @return [Float]
# File lib/micromidi/state.rb, line 124 def now time = Time.now.to_f - @start_time time * 1000 end