From 51510f09b4bcaf21f75c3133aa6ecbe97c8139b8 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Thu, 23 Jun 2022 15:08:22 -0300 Subject: "Add" button now is functional --- bass_player.rb | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'bass_player.rb') 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 -- cgit v1.2.3-70-g09d2