Class: Arcenciel::Device

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/arcenciel/manager/device.rb

Defined Under Namespace

Classes: InvalidDeviceError

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOGGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log_error, #log_info, #log_warn, #logger

Constructor Details

#initialize(id, type, port) ⇒ Device

Returns a new instance of Device.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/arcenciel/manager/device.rb', line 14

def initialize(id, type, port)
  @id = id
  @type = type
  @port = port
  @is_arc, @size = parse_type(type)

  @valid = false
  @controller = nil

  @client = OSC::Client.new('localhost', port)
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



12
13
14
# File 'lib/arcenciel/manager/device.rb', line 12

def controller
  @controller
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/arcenciel/manager/device.rb', line 7

def id
  @id
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/arcenciel/manager/device.rb', line 9

def port
  @port
end

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'lib/arcenciel/manager/device.rb', line 10

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/arcenciel/manager/device.rb', line 8

def type
  @type
end

Instance Method Details

#arc?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/arcenciel/manager/device.rb', line 26

def arc?
  !!@is_arc
end

#attach!(controller) ⇒ Object



57
58
59
60
# File 'lib/arcenciel/manager/device.rb', line 57

def attach!(controller)
  validate!
  @controller = controller
end

#attached?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/arcenciel/manager/device.rb', line 30

def attached?
  !!@controller
end

#on_delta(index, delta) ⇒ Object



94
95
96
# File 'lib/arcenciel/manager/device.rb', line 94

def on_delta(index, delta)
  @controller && @controller.on_delta(index, delta)
end

#on_key(index, state) ⇒ Object



98
99
100
# File 'lib/arcenciel/manager/device.rb', line 98

def on_key(index, state)
  @controller && @controller.on_key(index, state)
end

#ring_all(index, level) ⇒ Object



79
80
81
82
# File 'lib/arcenciel/manager/device.rb', line 79

def ring_all(index, level)
  validate!
  @client.send(OSC::Message.new('/arc/ring/all', index, level))
end

#ring_clear(index) ⇒ Object



69
70
71
72
# File 'lib/arcenciel/manager/device.rb', line 69

def ring_clear(index)
  validate!
  ring_all(index, 0)
end

#ring_clear_allObject



62
63
64
65
66
67
# File 'lib/arcenciel/manager/device.rb', line 62

def ring_clear_all
  validate!
  (0...size).each do |i|
    ring_clear(i)
  end
end

#ring_map(index, array) ⇒ Object



84
85
86
87
# File 'lib/arcenciel/manager/device.rb', line 84

def ring_map(index, array)
  validate!
  @client.send(OSC::Message.new('/arc/ring/map', index, *array))
end

#ring_range(index, x1, x2, level) ⇒ Object



89
90
91
92
# File 'lib/arcenciel/manager/device.rb', line 89

def ring_range(index, x1, x2, level)
  validate!
  @client.send(OSC::Message.new('/arc/ring/range', index, x1, x2, level))
end

#ring_set(index, x, level) ⇒ Object



74
75
76
77
# File 'lib/arcenciel/manager/device.rb', line 74

def ring_set(index, x, level)
  validate!
  @client.send(OSC::Message.new('/arc/ring/set', index, x, level))
end

#start!(server_port) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/arcenciel/manager/device.rb', line 42

def start!(server_port)
  set_destination(server_port)
  @valid = true
  ring_clear_all

  log_info "Added device (#{id}; UDP #{port})."
end

#stop!Object



50
51
52
53
54
55
# File 'lib/arcenciel/manager/device.rb', line 50

def stop!
  unassign_controller!
  @valid = false

  log_warn "Removed device (#{id}; UDP #{port})."
end

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/arcenciel/manager/device.rb', line 34

def valid?
  !!@valid
end

#validate!Object

Raises:



38
39
40
# File 'lib/arcenciel/manager/device.rb', line 38

def validate!
  raise InvalidDeviceError unless valid?
end