dtas.git  about / heads / tags
duct tape audio suite for *nix
blob 5fde3f0a477662f6cae752ea8d96076c4d084d7c 1862 bytes (raw)
$ git show tfx-pu:bin/dtas-tl	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 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
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
 
#!/usr/bin/env ruby
# Copyright (C) 2013-2015 all contributors <dtas-all@nongnu.org>
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
#
# WARNING: totally unstable API, use dtas-ctl for scripting (but the protocol
# itself is also unstable, but better than this one probably).
require 'dtas/unix_client'
require 'yaml'
require 'shellwords'

def get_track_ids(c)
  track_ids = c.req("tl tracks")
  # we could get more, but SEQPACKET limits size...
  track_ids = track_ids.split(/ /)
  track_ids.shift
  track_ids
end

c = DTAS::UNIXClient.new
case cmd = ARGV[0]
when "cat"
  get_track_ids(c).each do |track_id|
    res = c.req("tl get #{track_id}")
    res.sub!(/\A1 /, '')
    print "#{res}\n"
  end
when "clear"
  get_track_ids(c).each do |track_id|
    print("#{track_id} " << c.req("tl remove #{track_id}") << "\n")
  end
when "addhead"
  ARGV.shift
  ARGV.reverse.each do |path|
    path = File.expand_path(path)
    res = c.req(%W(tl add #{path}))
    print "#{path} #{res}\n"
  end
when "addtail"
  ARGV.shift
  track_ids = get_track_ids(c)
  last_id = track_ids.pop
  ARGV.each do |path|
    path = File.expand_path(path)
    req = %W(tl add #{path})
    req << last_id.to_s if last_id
    res = c.req(req)
    print "#{path} #{res}\n"
    last_id = res if res =~ /\A\d+\z/
  end
when "reto"
  fixed = ARGV.delete("-F")
  ignorecase = ARGV.delete("-i")
  re = ARGV[1]
  time = ARGV[2]
  re = Regexp.quote(re) if fixed
  re = ignorecase ? %r{#{re}}i : %r{#{re}}
  get_track_ids(c).each do |track_id|
    res = c.req("tl get #{track_id}")
    res.sub!(/\A1 \d+=/, '')
    if re =~ res
      req = %W(tl goto #{track_id})
      req << time if time
      res = c.req(req)
      puts res
      exit(res == "OK")
    end
  end
  warn "#{re.inspect} not found"
  exit 1
else
  # act like dtas-ctl for now...
  puts c.req([ "tl", *ARGV ])
end

git clone git://80x24.org/dtas.git
git clone https://80x24.org/dtas.git