Class: Qcmd::Handler

Inherits:
Object
  • Object
show all
Extended by:
Plaintext
Defined in:
lib/qcmd/handler.rb

Class Method Summary collapse

Methods included from Plaintext

ascii_qlab, centered_text, columns, joined_wrapped, log, pluralize, print, print_wrapped, right_text, set_columns, split_text, table, word_wrap, wrapped_text

Class Method Details

.handle(message) ⇒ Object

Handle OSC response message from QLab



7
8
9
10
11
12
13
14
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
# File 'lib/qcmd/handler.rb', line 7

def handle message
  Qcmd.debug "[Handler handle] converting OSC::Message to QLab::Reply"
  reply = QLab::Reply.new(message)

  Qcmd.debug "[Handler handle] handling #{ reply.to_s }"

  case reply.address
  when %r[/(selectedCues|runningCues|runningOrPausedCues)]
    Qcmd.debug "[Handler handle] received cue list from #{reply.address}"

    if reply.has_data?
      cues = reply.data.map {|cue| Qcmd::QLab::Cue.new(cue)}

      if cues.size > 0
        title = case reply.address
                when /selectedCues/;        "Selected Cues"
                when /runningCues/;         "Running Cues"
                when /runningOrPausedCues/; "Running or Paused Cues"
                end

        print
        print centered_text(" #{title} ", '-')
        table(['Number', 'Id', 'Name', 'Type'], cues.map {|cue|
          [cue.number, cue.id, cue.name, cue.type]
        })
        print
      else
        print "no cues found"
      end
    end

  when %r[/thump]
    print reply.data

  else
    Qcmd.debug "[Handler handle] unrecognized message from QLab, cannot handle #{ reply.address }"

    if !reply.status.nil? && reply.status != 'ok'
      print reply.status
    end
  end
end


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/qcmd/handler.rb', line 50

def print_workspace_list
  if Qcmd.context.machine.workspaces.nil? || Qcmd.context.machine.workspaces.empty?
    Qcmd.print "there are no workspaces! you're gonna have a bad time :("
    return
  end

  Qcmd.print Qcmd.centered_text(" Workspaces ", '-')
  Qcmd.print

  Qcmd.context.machine.workspaces.each_with_index do |ws, n|
    Qcmd.print "#{ n + 1 }. #{ ws.name }#{ ws.passcode? ? ' [PROTECTED]' : ''}"
  end

  Qcmd.print
  Qcmd.print_wrapped('Type `use "WORKSPACE NAME" PASSCODE` to load a workspace. Passcode is required if workspace is [PROTECTED].')
  Qcmd.print
end