Class: MicroMIDI::State

Inherits:
Object
  • Object
show all
Defined in:
lib/micromidi/state.rb

Constant Summary collapse

Default =
{
  :channel => 0,
  :octave => 2,
  :velocity => 100
}

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @auto_output = true
  @last_command = nil
  @last_note = nil    
  @listeners = []
  @thru_listeners = []
  @output_cache = []
  @start_time = Time.now.to_f
  @super_sticky = false

  @channel = options[:channel] || Default[:channel]
  @velocity = options[:velocity] || Default[:velocity]
  @octave = options[:octave] || Default[:octave]  
  
  @inputs = ins
  @outputs = outs  
end

Instance Attribute Details

#auto_outputObject

Returns the value of attribute auto_output.



13
14
15
# File 'lib/micromidi/state.rb', line 13

def auto_output
  @auto_output
end

#channelObject

Returns the value of attribute channel.



13
14
15
# File 'lib/micromidi/state.rb', line 13

def channel
  @channel
end

#inputsObject (readonly)

Returns the value of attribute inputs.



21
22
23
# File 'lib/micromidi/state.rb', line 21

def inputs
  @inputs
end

#last_commandObject (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_noteObject

Returns the value of attribute last_note.



13
14
15
# File 'lib/micromidi/state.rb', line 13

def last_note
  @last_note
end

#listenersObject (readonly)

Returns the value of attribute listeners.



21
22
23
# File 'lib/micromidi/state.rb', line 21

def listeners
  @listeners
end

#octaveObject

Returns the value of attribute octave.



13
14
15
# File 'lib/micromidi/state.rb', line 13

def octave
  @octave
end

#output_cacheObject (readonly)

Returns the value of attribute output_cache.



21
22
23
# File 'lib/micromidi/state.rb', line 21

def output_cache
  @output_cache
end

#outputsObject (readonly)

Returns the value of attribute outputs.



21
22
23
# File 'lib/micromidi/state.rb', line 21

def outputs
  @outputs
end

#start_timeObject (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_stickyObject

Returns the value of attribute super_sticky.



13
14
15
# File 'lib/micromidi/state.rb', line 13

def super_sticky
  @super_sticky
end

#sysex_nodeObject

Returns the value of attribute sysex_node.



13
14
15
# File 'lib/micromidi/state.rb', line 13

def sysex_node
  @sysex_node
end

#thru_listenersObject (readonly)

Returns the value of attribute thru_listeners.



21
22
23
# File 'lib/micromidi/state.rb', line 21

def thru_listeners
  @thru_listeners
end

#velocityObject

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 message_properties(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_outputObject



57
58
59
# File 'lib/micromidi/state.rb', line 57

def toggle_auto_output
  @auto_output = !@auto_output
end

#toggle_super_stickyObject



53
54
55
# File 'lib/micromidi/state.rb', line 53

def toggle_super_sticky
  @super_sticky = !@super_sticky
end