Class: MicroMIDI::State
- Inherits:
-
Object
- Object
- MicroMIDI::State
- Defined in:
- lib/micromidi/state.rb
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(ins, outs, options = {}) ⇒ State
constructor
A new instance of State.
- #message_properties(opts, *props) ⇒ Object
- #record(m, a, b, outp) ⇒ Object
- #toggle_auto_output ⇒ Object
- #toggle_super_sticky ⇒ Object
Constructor Details
#initialize(ins, outs, options = {}) ⇒ State
Returns a new instance of State.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/micromidi/state.rb', line 29 def initialize(ins, outs, = {}) @auto_output = true @last_command = nil @last_note = nil @listeners = [] @thru_listeners = [] @output_cache = [] @start_time = Time.now.to_f @super_sticky = false @channel = [:channel] || Default[:channel] @velocity = [:velocity] || Default[:velocity] @octave = [:octave] || Default[:octave] @inputs = ins @outputs = outs end |
Instance Attribute Details
#auto_output ⇒ Object
Returns the value of attribute auto_output.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def auto_output @auto_output end |
#channel ⇒ Object
Returns the value of attribute channel.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def channel @channel end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def inputs @inputs end |
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def last_command @last_command end |
#last_note ⇒ Object
Returns the value of attribute last_note.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def last_note @last_note end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def listeners @listeners end |
#octave ⇒ Object
Returns the value of attribute octave.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def octave @octave end |
#output_cache ⇒ Object (readonly)
Returns the value of attribute output_cache.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def output_cache @output_cache end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def outputs @outputs end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def start_time @start_time end |
#super_sticky ⇒ Object
Returns the value of attribute super_sticky.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def super_sticky @super_sticky end |
#sysex_node ⇒ Object
Returns the value of attribute sysex_node.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def sysex_node @sysex_node end |
#thru_listeners ⇒ Object (readonly)
Returns the value of attribute thru_listeners.
21 22 23 |
# File 'lib/micromidi/state.rb', line 21 def thru_listeners @thru_listeners end |
#velocity ⇒ Object
Returns the value of attribute velocity.
13 14 15 |
# File 'lib/micromidi/state.rb', line 13 def velocity @velocity end |
Instance Method Details
#message_properties(opts, *props) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/micromidi/state.rb', line 61 def (opts, *props) output = {} props.each do |prop| output[prop] = opts[prop] self.send("#{prop.to_s}=", output[prop]) if !output[prop].nil? && (self.send(prop).nil? || @super_sticky) output[prop] ||= self.send(prop.to_s) end output end |
#record(m, a, b, outp) ⇒ Object
47 48 49 50 51 |
# File 'lib/micromidi/state.rb', line 47 def record(m, a, b, outp) ts = now @output_cache << { :message => outp, :timestamp => ts } @last_command = { :method => m, :args => a, :block => b, :timestamp => ts } end |
#toggle_auto_output ⇒ Object
57 58 59 |
# File 'lib/micromidi/state.rb', line 57 def toggle_auto_output @auto_output = !@auto_output end |
#toggle_super_sticky ⇒ Object
53 54 55 |
# File 'lib/micromidi/state.rb', line 53 def toggle_super_sticky @super_sticky = !@super_sticky end |