Class: Aud::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/aud/cli.rb

Instance Method Summary collapse

Instance Method Details

#listenObject



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
# File 'lib/aud/cli.rb', line 42

def listen
  output = UniMIDI::Output.first

  if options[:strategy] == 'tick'
    aud = Aud::Tick.new(output, options)
  else
    raise 'Only tick strategy is supported, but feel free to contribute another!'
  end

  _exit = false
  Signal.trap(:INT)  do _exit = true end
  Signal.trap(:TERM) do _exit = true end

  process_line = lambda { |line|
    line = line.strip
    aud.process(line)
    puts line unless options[:notext]
    sleep(options[:delay] / 1000.0)
  }

  if options[:file]
    File.open(options[:file]).each do |line|
      process_line.call(line) unless _exit
    end
  else
    # fixup ARGF
    ARGV.clear
    ARGF.each_line do |line|
      process_line.call(line) unless _exit
    end
  end
end