Class: Wavesync::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/wavesync/ui.rb

Constant Summary collapse

THEME =
{
  primary: :lightgray,
  secondary: :darkgray,
  tertiary: :dimgray,
  highlight: :orangered,
  surface: :hotpink,
  extra: :deepskyblue
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeUI

Returns a new instance of UI.



18
19
20
21
22
# File 'lib/wavesync/ui.rb', line 18

def initialize
  @cursor = TTY::Cursor
  @sticky_lines = []
  @prompt = TTY::Prompt.new(interrupt: :exit, active_color: :red)
end

Instance Method Details

#analyze_progress(index, total_count) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/wavesync/ui.rb', line 74

def analyze_progress(index, total_count)
  parts = [
    in_color('wavesync analyze', :primary),
    in_color("#{index + 1}/#{total_count}", :extra)
  ]
  sticky(parts.join(' '), 0)
end

#analyze_result(file, bpm) ⇒ Object



86
87
88
89
# File 'lib/wavesync/ui.rb', line 86

def analyze_result(file, bpm)
  label = bpm ? in_color("#{bpm} BPM", :highlight) : in_color('No BPM detected', :highlight)
  set_analyze_file_stickies(file, label)
end

#analyze_skip(file, bpm) ⇒ Object



82
83
84
# File 'lib/wavesync/ui.rb', line 82

def analyze_skip(file, bpm)
  set_analyze_file_stickies(file, in_color("#{bpm} BPM already set", :highlight))
end

#bpm(tbpm, original_bars: nil, target_bars: nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/wavesync/ui.rb', line 63

def bpm(tbpm, original_bars: nil, target_bars: nil)
  if tbpm.nil?
    sticky('', 4)
  elsif original_bars && target_bars
    bar_info = original_bars == target_bars ? "#{original_bars} bars" : "#{original_bars}#{target_bars} bars"
    sticky("#{tbpm} bpm · #{bar_info}", 4)
  else
    sticky("#{tbpm} bpm", 4)
  end
end

#clearObject



105
106
107
108
# File 'lib/wavesync/ui.rb', line 105

def clear
  print @cursor.clear_screen
  print @cursor.move_to(0, 0)
end

#color(text, key) ⇒ Object



101
102
103
# File 'lib/wavesync/ui.rb', line 101

def color(text, key)
  in_color(text, key)
end

#confirm(message) ⇒ Object



91
92
93
94
95
# File 'lib/wavesync/ui.rb', line 91

def confirm(message)
  print in_color(message, :secondary)
  response = $stdin.gets.to_s.strip.downcase
  response == 'y'
end

#conversion_progress(source_format, target_format) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wavesync/ui.rb', line 41

def conversion_progress(source_format, target_format)
  effective = source_format.merge(target_format)

  source_info = audio_info(source_format.sample_rate, source_format.bit_depth)
  target_info = audio_info(effective.sample_rate, effective.bit_depth)

  formatted_line = in_color(
    "Converting #{source_format.file_type} (#{source_info}) ⇢ #{effective.file_type} (#{target_info})", :highlight
  )
  sticky(formatted_line, 3)
end

#copy(source_format) ⇒ Object



53
54
55
56
57
# File 'lib/wavesync/ui.rb', line 53

def copy(source_format)
  info = audio_info(source_format.sample_rate, source_format.bit_depth)

  sticky(in_color("Copying #{source_format.file_type} (#{info})", :highlight), 3)
end

#file_progress(filename) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/wavesync/ui.rb', line 24

def file_progress(filename)
  path = Pathname.new(filename)
  file_stem = path.basename(path.extname).to_s
  parent_name = path.parent.basename.to_s
  sticky(in_color(parent_name, :secondary), 1)
  sticky(in_color(file_stem, :tertiary), 2)
end

#select(label, options) ⇒ Object



97
98
99
# File 'lib/wavesync/ui.rb', line 97

def select(label, options)
  @prompt.select(label, options, cycle: true)
end

#skipObject



59
60
61
# File 'lib/wavesync/ui.rb', line 59

def skip
  sticky(in_color('↷ Skipping, already synced', :highlight), 3)
end

#sync_progress(index, total_count, device) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/wavesync/ui.rb', line 32

def sync_progress(index, total_count, device)
  parts = [
    in_color("wavesync #{device.name}", :primary),
    in_color("#{index + 1}/#{total_count}", :extra)
  ]

  sticky(parts.join(' '), 0)
end