Class: SurfaceMaster::Orbit::Device

Inherits:
Device
  • Object
show all
Includes:
MIDICodes
Defined in:
lib/surface_master/orbit/device.rb

Overview

Low-level interface to Numark Orbit wireless MIDI control surface.

Constant Summary

Constants included from MIDICodes

MIDICodes::CONTROLS, MIDICodes::SELECTORS, MIDICodes::SHOULDERS

Instance Method Summary collapse

Methods inherited from Device

#close, #closed?, #input_enabled?, #output_enabled?

Methods included from Logging

#logger, #logger=

Constructor Details

#initialize(opts = nil) ⇒ Device

Returns a new instance of Device.



7
8
9
10
11
# File 'lib/surface_master/orbit/device.rb', line 7

def initialize(opts = nil)
  @name = "Numark ORBIT"
  super(opts)
  init!
end

Instance Method Details

#init!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/surface_master/orbit/device.rb', line 15

def init!
  # Hack to get around apparent portmidi message truncation.
  return

  # Skip Sysex begin, vendor header, command code, aaaaand sysex end --
  # this will let us compare command vs. response payloads to determine
  # if the state of the device is what we want.  Of course, sometimes it
  # lies, but we can't do much about that.
  # expected_state = MAPPINGS[1..-1]
  # sysex!(MAPPINGS)
  # sleep 0.1
  # sysex!(READ_STATE)
  # current_state       = []
  # started_at          = Time.now.to_f
  # attempts            = 1
  # state               = :looking_for_start
  # loop do
  #   raw = @input.read
  #   unless raw
  #     elapsed = Time.now.to_f - started_at
  #     if elapsed > 4.0
  #       logger.error { "Timeout fetching state of Numark Orbit!" }
  #       break
  #     elsif elapsed > (1.0 * attempts)
  #       logger.error { "Asking for current state of Numark Orbit again!" }
  #       attempts     += 1
  #       current_state = []
  #       state         = :looking_for_start
  #       sysex!(READ_STATE)
  #       next
  #     end
  #     sleep 0.01
  #     next
  #   end

  #   case state
  #   when :looking_for_start
  #     idx = raw.find_index { |ii| ii[:message][0] == 0xF0 }
  #     if idx
  #       state           = :looking_for_end
  #       raw             = raw[idx..-1]
  #       current_state  += raw.map { |ii| ii[:message] }.flatten
  #     end
  #   when :looking_for_end
  #     idx = raw.find_index { |ii| ii[:message][0] == 0xF7 }
  #     if idx
  #       # TODO: Now what?
  #       current_state = current_state[6..-1]
  #       if expected_state != current_state
  #         logger.error { "UH OH!  Numark Orbit state didn't match what we sent!" }
  #         logger.error { "Expected: #{format_msg(expected_state)}" }
  #         logger.error { "Got:      #{format_msg(current_state)}" }
  #       else
  #         logger.debug { "Your Numark Orbit should be in the right state now." }
  #         return
  #       end
  #     else
  #       idx = -1
  #     end
  #     raw             = raw[0..idx]
  #     current_state  += raw.map { |ii| ii[:message] }.flatten
  #   end
  # end

  # logger.error { "Didn't get state from Numark Orbit!" }
end

#readObject



82
83
84
85
86
# File 'lib/surface_master/orbit/device.rb', line 82

def read
  super
    .map { |input| decode_input(input) }
    .compact
end

#reset!Object



13
# File 'lib/surface_master/orbit/device.rb', line 13

def reset!; end