diff options
author | Matias Linares <matias.linares@comprandoengrupo.net> | 2022-06-23 15:08:22 -0300 |
---|---|---|
committer | Matias Linares <matias.linares@comprandoengrupo.net> | 2022-06-23 15:08:22 -0300 |
commit | 51510f09b4bcaf21f75c3133aa6ecbe97c8139b8 (patch) | |
tree | fc73a1c6eeb73ecd2488b7614c0eac8b9b0869d1 | |
parent | 93e814553c2c2471afd78fd65490a883765f4ffd (diff) | |
download | bass-player-51510f09b4bcaf21f75c3133aa6ecbe97c8139b8.tar.gz |
"Add" button now is functional
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | bass_player.rb | 32 |
2 files changed, 24 insertions, 9 deletions
@@ -5,3 +5,4 @@ gem "qml" gem "sequel" gem "rake" gem "sqlite3" +gem "ruby-audioinfo" diff --git a/bass_player.rb b/bass_player.rb index 4796d61..6cb73c4 100644 --- a/bass_player.rb +++ b/bass_player.rb @@ -1,4 +1,5 @@ require 'qml' +require 'audioinfo' require './models' module BassPlayer @@ -18,7 +19,6 @@ module BassPlayer def initialize super() Song.all.each do |song| - p song model << { title: song.title, duration: ms_to_time(song.duration) @@ -27,20 +27,35 @@ module BassPlayer end def add(file_url, duration, metadata) - item = { - title: file_url, - duration: duration - } - p item - model << item + path = file_url.split('file://').last + AudioInfo.open(path) do |info| + title = if info.title.empty? + File.basename(path) + else + info.title + end + song = Song.create( + title: title, + duration: info.length * 1000, + path: file_url + ) + + item = { + title: song.title, + duration: ms_to_time(song.duration) + } + model << item + 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}" end part_model.clear - parts = Part.join(:songs, title: current_song).all.map do |part| + parts = Song.first(title: self.current_song).parts.map do |part| { name: part.name, from: ms_to_time(part.from), @@ -64,7 +79,6 @@ module BassPlayer def ms_to_time(ms) retval = Time.at(ms/1000).utc.strftime("%H:%M:%S") - p "ms: '#{ms}' - Time: #{retval}" return retval end end |