Class: QLab::Machine

Inherits:
Communicator show all
Defined in:
lib/qlab-ruby/machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Communicator

#send_message

Constructor Details

#initialize(_address, _port) ⇒ Machine

Connect to a running QLab instance. ‘address` can be a domain name or an IP Address.



7
8
9
10
11
12
# File 'lib/qlab-ruby/machine.rb', line 7

def initialize(_address, _port)
  self.name = _address
  self.address = _address
  self.port = _port
  connect
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/qlab-ruby/machine.rb', line 3

def address
  @address
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/qlab-ruby/machine.rb', line 3

def name
  @name
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/qlab-ruby/machine.rb', line 3

def port
  @port
end

Instance Method Details

#alwaysReply=(value) ⇒ Object



75
76
77
78
# File 'lib/qlab-ruby/machine.rb', line 75

def alwaysReply=(value)
  # send set command
  alwaysReply(value)
end

#closeObject



64
65
66
67
# File 'lib/qlab-ruby/machine.rb', line 64

def close
  @connection.close
  @connection = nil
end

#connectObject

Open and return a connection to the running QLab instance



27
28
29
30
31
32
33
# File 'lib/qlab-ruby/machine.rb', line 27

def connect
  if !connected?
    @connection = OSC::TCP::Client.new(@address, @port)
  else
    connection
  end
end

#connected?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/qlab-ruby/machine.rb', line 60

def connected?
  !(@connection.nil? || send_message('/version').nil?)
end

#connectionObject

Reference to the running QLab instance



36
37
38
# File 'lib/qlab-ruby/machine.rb', line 36

def connection
  @connection || connect
end

#find_workspace(params = {}) ⇒ Object

Find a workspace according to the given params.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/qlab-ruby/machine.rb', line 47

def find_workspace params={}
  workspaces.find do |ws|
    matches = true

    # match each key to the given workspace
    params.keys.each do |key|
      matches = matches && (ws.send(key.to_sym) == params[key])
    end

    matches
  end
end

#refreshObject



69
70
71
72
73
# File 'lib/qlab-ruby/machine.rb', line 69

def refresh
  close
  connect
  load_workspaces
end

#workspacesObject

The workspaces provided by the connected QLab instance



41
42
43
# File 'lib/qlab-ruby/machine.rb', line 41

def workspaces
  @workspaces || load_workspaces
end