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.



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

def initialize
  @cursor = TTY::Cursor
  @sticky_lines = []
end

Instance Method Details

#analyze_progress(index, total_count) ⇒ Object



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

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



84
85
86
87
# File 'lib/wavesync/ui.rb', line 84

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



80
81
82
# File 'lib/wavesync/ui.rb', line 80

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



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

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



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

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

#color(text, key) ⇒ Object



89
90
91
# File 'lib/wavesync/ui.rb', line 89

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

#conversion_progress(source_format, target_format) ⇒ Object



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

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



51
52
53
54
55
# File 'lib/wavesync/ui.rb', line 51

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



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

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

#skipObject



57
58
59
# File 'lib/wavesync/ui.rb', line 57

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

#sync_progress(index, total_count, device) ⇒ Object



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

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