class Diamond::OSC::Node

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

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [Boolean] :debug Whether to send debug output @option options [Fixnum] :server_port The port to listen on (default: 8000)

# 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

Public Instance Methods

enable_parameter_control(arpeggiator, map) click to toggle source

Enable controlling the instrument via OSC @param [Arpeggiator] arpeggiator The arpeggiator to operate on when messages are received @param [Array<Hash>] map @return [Boolean]

# 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

Private Instance Methods

start_server() click to toggle source

Start the server @return [Thread]

# File lib/diamond/osc.rb, line 44
def start_server
  @thread = Thread.new do
    begin
      EM.epoll
      EM.run { @server.run }
    rescue Exception => exception
      Thread.main.raise(exception)
    end
  end
  @thread.abort_on_exception = true
  @thread
end