Class: MicroMIDI::Context
- Inherits:
-
Object
- Object
- MicroMIDI::Context
- Extended by:
- Forwardable
- Includes:
- Instructions::Composite
- Defined in:
- lib/micromidi/context.rb,
lib/micromidi/instructions/shorthand.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#edit(&block) ⇒ Object
open a block for editing/live coding in this Context.
-
#initialize(ins, outs, &block) ⇒ Context
constructor
A new instance of Context.
- #method_missing(m, *a, &b) ⇒ Object
- #repeat ⇒ Object (also: #r)
Methods included from Instructions::Composite
Constructor Details
#initialize(ins, outs, &block) ⇒ Context
Returns a new instance of Context.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/micromidi/context.rb', line 15 def initialize(ins, outs, &block) @state = State.new(ins, outs) @instructions = { :process => Instructions::Process.new(@state), :input => Instructions::Input.new(@state), :message => Instructions::Message.new(@state), :output => Instructions::Output.new(@state), :sticky => Instructions::Sticky.new(@state), :sysex => Instructions::SysEx.new(@state) } edit(&block) unless block.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/micromidi/context.rb', line 40 def method_missing(m, *a, &b) delegated = false outp = nil = a.last.kind_of?(Hash) ? a.last : {} do_output = [:output] || true [@instructions[:sysex], @instructions[:message], @instructions[:process]].each do |dsl| if dsl.respond_to?(m) msg = dsl.send(m, *a, &b) outp = @state.auto_output && do_output ? @instructions[:output].output(msg) : msg delegated = true end end unless delegated [@instructions[:input], @instructions[:output], @instructions[:sticky]].each do |dsl| if dsl.respond_to?(m) outp = dsl.send(m, *a, &b) delegated = true end end end @state.record(m, a, b, outp) delegated ? outp : super end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
11 12 13 |
# File 'lib/micromidi/context.rb', line 11 def state @state end |
Instance Method Details
#edit(&block) ⇒ Object
open a block for editing/live coding in this Context
32 33 34 |
# File 'lib/micromidi/context.rb', line 32 def edit(&block) self.instance_eval(&block) end |
#repeat ⇒ Object Also known as: r
36 37 38 |
# File 'lib/micromidi/context.rb', line 36 def repeat self.send(@state.last_command[:method], *@state.last_command[:args]) unless @state.last_command.nil? end |