Class: Diamond::OSC::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/diamond/osc.rb

Overview

An access point for dealing with all OSC functionality for the instrument

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Node

Returns a new instance of Node.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :debug (Boolean)

    Whether to send debug output

  • :server_port (Fixnum)

    The port to listen on (default: 8000)


12
13
14
15
16
# File 'lib/diamond/osc.rb', line 12

def initialize(options = {})
  @debug = options.fetch(:debug, false)
  port = options.fetch(:server_port, 8000)
  @server = ::OSC::EMServer.new(port)
end

Instance Method Details

#enable_parameter_control(arpeggiator, map) ⇒ Boolean

Enable controlling the instrument via OSC

Parameters:

  • arpeggiator (Arpeggiator)

    The arpeggiator to operate on when messages are received

  • map (Array<Hash>)

Returns:

  • (Boolean)

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/diamond/osc.rb', line 22

def enable_parameter_control(arpeggiator, map)
  start_server
  maps = map.map do |item|
    property = item[:property]
    osc_range = item[:value] || (0..1.0)
    @server.add_method(item[:address]) do |message|
      value = message.to_a[0]
      parameter_range = arpeggiator.parameter.constraints(property)
      value = Scale.transform(value).from(osc_range).to(parameter_range)
      puts "[DEBUG]: OSC: #{property}= #{value}" if @debug
      arpeggiator.parameter.send("#{property}=", value)
      true
    end
    true
  end
  maps.any?     
end