Class: MicroMIDI::State
- Inherits:
-
Object
- Object
- MicroMIDI::State
- Defined in:
- lib/micromidi/state.rb
Overview
The DSL state
Constant Summary collapse
- DEFAULT =
{ :channel => 0, :octave => 2, :velocity => 100 }
Instance Attribute Summary collapse
-
#auto_output ⇒ Object
Returns the value of attribute auto_output.
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#last_command ⇒ Object
readonly
Returns the value of attribute last_command.
-
#last_note ⇒ Object
Returns the value of attribute last_note.
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
-
#octave ⇒ Object
Returns the value of attribute octave.
-
#output_cache ⇒ Object
readonly
Returns the value of attribute output_cache.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#super_sticky ⇒ Object
Returns the value of attribute super_sticky.
-
#sysex_node ⇒ Object
Returns the value of attribute sysex_node.
-
#thru_listeners ⇒ Object
readonly
Returns the value of attribute thru_listeners.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Instance Method Summary collapse
-
#initialize(inputs, outputs, options = {}) ⇒ State
constructor
A new instance of State.
-
#message_properties(options, *properties) ⇒ Hash
Return message properties with regard to the current state.
-
#record(method, args, block, result) ⇒ Object
Record that a command was used.
-
#toggle_auto_output ⇒ Boolean
Toggles auto-output mode.
-
#toggle_super_sticky ⇒ Boolean
Toggles super_sticky mode, a mode where any explicit values used to create MIDI messages automatically become sticky.
Constructor Details
#initialize(inputs, outputs, options = {}) ⇒ State
Returns a new instance of State.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/micromidi/state.rb', line 34 def initialize(inputs, outputs, = {}) @inputs = [inputs].flatten @outputs = [outputs].flatten @channel = [:channel] || DEFAULT[:channel] @velocity = [:velocity] || DEFAULT[:velocity] @octave = [: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 |
Instance Attribute Details
#auto_output ⇒ Object
Returns the value of attribute auto_output.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def auto_output @auto_output end |
#channel ⇒ Object
Returns the value of attribute channel.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def channel @channel end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def inputs @inputs end |
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def last_command @last_command end |
#last_note ⇒ Object
Returns the value of attribute last_note.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def last_note @last_note end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def listeners @listeners end |
#octave ⇒ Object
Returns the value of attribute octave.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def octave @octave end |
#output_cache ⇒ Object (readonly)
Returns the value of attribute output_cache.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def output_cache @output_cache end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def outputs @outputs end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def start_time @start_time end |
#super_sticky ⇒ Object
Returns the value of attribute super_sticky.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def super_sticky @super_sticky end |
#sysex_node ⇒ Object
Returns the value of attribute sysex_node.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def sysex_node @sysex_node end |
#thru_listeners ⇒ Object (readonly)
Returns the value of attribute thru_listeners.
20 21 22 |
# File 'lib/micromidi/state.rb', line 20 def thru_listeners @thru_listeners end |
#velocity ⇒ Object
Returns the value of attribute velocity.
12 13 14 |
# File 'lib/micromidi/state.rb', line 12 def velocity @velocity end |
Instance Method Details
#message_properties(options, *properties) ⇒ Hash
Return message properties with regard to the current state
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/micromidi/state.rb', line 108 def (, *properties) result = {} properties.each do |property| result[property] = [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) ⇒ Object
Record that a command was used
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/micromidi/state.rb', line 57 def record(method, args, block, result) = now = { :message => result, :timestamp => } @output_cache << @last_command = { :method => method, :args => args, :block => block, :timestamp => } end |
#toggle_auto_output ⇒ Boolean
Toggles auto-output mode. In auto-output mode, any messages that are instantiated are sent to any available MIDI outputs.
100 101 102 |
# File 'lib/micromidi/state.rb', line 100 def toggle_auto_output @auto_output = !@auto_output end |
#toggle_super_sticky ⇒ Boolean
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” “`
93 94 95 |
# File 'lib/micromidi/state.rb', line 93 def toggle_super_sticky @super_sticky = !@super_sticky end |