Class: LiveAPI::LiveConnection

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

Overview

A class to manage a UDP Open Sound Control connection

to Ableton Live

Constant Summary collapse

TypeTags =
{'i' => :decode_int32, 'f' => :decode_float32, 'b' => :decode_blob, 's' => :decode_string}
ClassMap =
{Fixnum => 'i', Float => 'f', String => 's'}

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ LiveConnection

Initialize



39
40
41
42
43
44
45
46
# File 'lib/live_api.rb', line 39

def initialize(host, port)
 @host = host
 @server_port = port.succ
 @client_port = port
 @client = OSC::UDPSocket.new
 @server = OSC::UDPServer.new
 @server.bind(nil, @server_port)
end

Instance Method Details

#request(path, *cmds) ⇒ Object

Send an OSC message



50
51
52
53
54
55
# File 'lib/live_api.rb', line 50

def request(path, *cmds)
  type_tags = cmds.map{|cmd| ClassMap[cmd.class]}.join
  message = OSC::Message.new(path, type_tags, *cmds)
  @client.send(message, 0, 'localhost', 9000)
  cmds.last == 'getinfo' ? receive_multi : receive unless(cmds.first == 'set')
end