summaryrefslogtreecommitdiff
path: root/bass_player.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bass_player.rb')
-rw-r--r--bass_player.rb36
1 files changed, 28 insertions, 8 deletions
diff --git a/bass_player.rb b/bass_player.rb
index b625523..9a1d90a 100644
--- a/bass_player.rb
+++ b/bass_player.rb
@@ -10,7 +10,8 @@ module BassPlayer
property(:title) { '' }
property(:duration) { '' }
- property(:current_song) { 0 }
+ property(:current_song) { '' }
+ property(:current_segment) { '' }
property(:model) { QML::ArrayModel.new(:title, :duration) }
property(:segment_model) {
QML::ArrayModel.new(:name, :from, :to)
@@ -48,13 +49,16 @@ module BassPlayer
end
end
- def song_selected(song)
- puts "Selected song: #{song}"
- unless song.nil?
- self.current_song = model[song][:title]
- puts "Setting current song to #{self.current_song}"
+ def song_selected(row)
+ unless row.nil?
+ self.current_song = model[row][:title]
end
+
segment_model.clear
+ self.current_segment = nil
+
+ song = Song.first(title: self.current_song)
+
segments = Song.first(title: self.current_song).segments.map do |segment|
{
name: segment.name,
@@ -63,24 +67,40 @@ module BassPlayer
}
end
+
for segment in segments
segment_model << segment
end
+ return {
+ path: song.path,
+ duration: song.duration
+ }
+ end
+
+ def segment_selected(row)
+ song = Song.first(title: self.current_song)
+ self.current_segment = song.segments[row.to_i].to_hash
end
def add_segment(name, from, to)
song = Song.first(title: current_song)
Segment.create(
- name: name, from: from, to: to,
+ name: name, from: parse_time(from), to: parse_time(to),
song_id: song.id
)
song_selected(nil)
end
def ms_to_time(ms)
- retval = Time.at(ms/1000).utc.strftime("%H:%M:%S")
+ retval = Time.at(ms/1000).utc.strftime("%M:%S")
return retval
end
+
+ def parse_time(string)
+ # Parses a string of the form '3:12' to milliseconds
+ min, sec = string.split(':').map(&:to_i)
+ return ((min * 60) + sec) * 1000
+ end
end
end