Class: Wavesync::SetEditor

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

Constant Summary collapse

KEY_MAP =
{
  'a' => :add,
  'u' => :move_up,
  'd' => :move_down,
  'r' => :remove,
  's' => :save,
  'c' => :quit,
  ' ' => :toggle_play,
  "\e[A" => :cursor_up,
  "\e[B" => :cursor_down
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(set, library_path) ⇒ SetEditor

Returns a new instance of SetEditor.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wavesync/set_editor.rb', line 20

def initialize(set, library_path)
  @set = set
  @library_path = library_path
  @prompt = TTY::Prompt.new(interrupt: :exit, active_color: :red)
  @ui = UI.new
  @selected = @set.tracks.empty? ? nil : 0
  @player_pid = nil
  @player_track = nil
  @player_state = :stopped
  @player_offset = 0
  @player_started_at = nil
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wavesync/set_editor.rb', line 33

def run
  loop do
    check_player
    render
    action = KEY_MAP[read_key]
    next unless action

    result = handle_action(action)
    break if result == :quit
  end
ensure
  stop_playback
end