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
Overview
The DSL context
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#edit(&block) ⇒ Object
Eval a block for editing/live coding in this context.
-
#initialize(inputs, outputs, &block) ⇒ Context
constructor
A new instance of Context.
-
#method_missing(method, *args, &block) ⇒ Object
Delegates a command to one of the instruction classes.
-
#repeat ⇒ Object
(also: #r)
Repeat the last instruction in the history.
Methods included from Instructions::Composite
Constructor Details
#initialize(inputs, outputs, &block) ⇒ Context
Returns a new instance of Context.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/micromidi/context.rb', line 16 def initialize(inputs, outputs, &block) @state = State.new(inputs, outputs) @instructions = { :process => Instructions::Process.new(@state), :message => Instructions::Message.new(@state), :output => Instructions::Output.new(@state), :sticky => Instructions::Sticky.new(@state), :sysex => Instructions::SysEx.new(@state) } @instructions[:input] = Instructions::Input.new(@state) { || @instructions[:output].output() } edit(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegates a command to one of the instruction classes
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/micromidi/context.rb', line 52 def method_missing(method, *args, &block) results = delegate(method, args, &block) if results.empty? super else = results.map do |result| @state.record(method, args, block, result[:message]) @instructions[:output].output(result[:message]) if output?(result[:instruction_type]) result[:message] end .compact.first end end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/micromidi/context.rb', line 9 def state @state end |
Instance Method Details
#edit(&block) ⇒ Object
Eval a block for editing/live coding in this context
35 36 37 |
# File 'lib/micromidi/context.rb', line 35 def edit(&block) instance_eval(&block) end |
#repeat ⇒ Object Also known as: r
Repeat the last instruction in the history
41 42 43 44 45 |
# File 'lib/micromidi/context.rb', line 41 def repeat unless @state.last_command.nil? send(@state.last_command[:method], *@state.last_command[:args]) end end |