Class: Soundcloud2000::Application

Inherits:
Object
  • Object
show all
Includes:
Controllers, Models, Views
Defined in:
lib/soundcloud2000/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Application

Returns a new instance of Application.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/soundcloud2000/application.rb', line 22

def initialize(client)
  $stderr.reopen("debug.log", "w")
  @canvas = UI::Canvas.new

  @splash_controller = Controller.new(Splash.new(
      UI::Rect.new(0, 0, Curses.cols, Curses.lines)))

  @player_controller = PlayerController.new(PlayerView.new(
      UI::Rect.new(0, 0, Curses.cols, 5)), client)

  @track_controller = TrackController.new(TracksTable.new(
      UI::Rect.new(0, 5, Curses.cols, Curses.lines - 5)), client)

  @track_controller.bind_to(TrackCollection.new(client))

  @track_controller.events.on(:select) do |track|
    @player_controller.play(track)
  end

  @player_controller.events.on(:complete) do
    @track_controller.next_track
  end
end

Class Method Details

.loggerObject



86
87
88
# File 'lib/soundcloud2000/application.rb', line 86

def self.logger
  @logger ||= Logger.new('debug.log')
end

Instance Method Details

#handle(key) ⇒ Object

TODO: look at active controller and send key to active controller instead



69
70
71
72
73
74
75
76
# File 'lib/soundcloud2000/application.rb', line 69

def handle(key)
  case key
  when :left, :right, :space, :one, :two, :three, :four, :five, :six, :seven, :eight, :nine
    @player_controller.events.trigger(:key, key)
  when :down, :up, :enter, :u, :f, :s, :j, :k
    @track_controller.events.trigger(:key, key)
  end
end

#mainObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/soundcloud2000/application.rb', line 46

def main
  loop do
    if @workaround_was_called_once_already
      handle UI::Input.get(-1)
    else
      @workaround_was_called_once_already = true
      handle UI::Input.get(0)
      @track_controller.load
      @track_controller.render
    end

    break if stop?
  end
ensure
  @canvas.close
end

#runObject



63
64
65
66
# File 'lib/soundcloud2000/application.rb', line 63

def run
  @splash_controller.render
  main
end

#stopObject



78
79
80
# File 'lib/soundcloud2000/application.rb', line 78

def stop
  @stop = true
end

#stop?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/soundcloud2000/application.rb', line 82

def stop?
  @stop == true
end