Class: MicroMIDI::State

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

Constant Summary

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (State) initialize(ins, outs, options = {})

A new instance of State



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/micromidi/state.rb', line 28

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

- (Object) auto_output

Returns the value of attribute auto_output



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

def auto_output
  @auto_output
end

- (Object) channel

Returns the value of attribute channel



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

def channel
  @channel
end

- (Object) inputs (readonly)

Returns the value of attribute inputs



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

def inputs
  @inputs
end

- (Object) last_command (readonly)

Returns the value of attribute last_command



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

def last_command
  @last_command
end

- (Object) last_note

Returns the value of attribute last_note



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

def last_note
  @last_note
end

- (Object) listeners (readonly)

Returns the value of attribute listeners



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

def listeners
  @listeners
end

- (Object) octave

Returns the value of attribute octave



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

def octave
  @octave
end

- (Object) output_cache (readonly)

Returns the value of attribute output_cache



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

def output_cache
  @output_cache
end

- (Object) outputs (readonly)

Returns the value of attribute outputs



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

def outputs
  @outputs
end

- (Object) start_time (readonly)

Returns the value of attribute start_time



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

def start_time
  @start_time
end

- (Object) super_sticky

Returns the value of attribute super_sticky



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

def super_sticky
  @super_sticky
end

- (Object) thru_listeners (readonly)

Returns the value of attribute thru_listeners



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

def thru_listeners
  @thru_listeners
end

- (Object) velocity

Returns the value of attribute velocity



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

def velocity
  @velocity
end

Instance Method Details

- (Object) message_properties(opts, *props)



60
61
62
63
64
65
66
67
68
# File 'lib/micromidi/state.rb', line 60

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

- (Object) record(m, a, b, outp)



46
47
48
49
50
# File 'lib/micromidi/state.rb', line 46

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

- (Object) toggle_auto_output



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

def toggle_auto_output
  @auto_output = !@auto_output
end

- (Object) toggle_super_sticky



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

def toggle_super_sticky
  @super_sticky = !@super_sticky
end