summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matias.linares@comprandoengrupo.net>2022-06-23 15:08:22 -0300
committerMatias Linares <matias.linares@comprandoengrupo.net>2022-06-23 15:08:22 -0300
commit51510f09b4bcaf21f75c3133aa6ecbe97c8139b8 (patch)
treefc73a1c6eeb73ecd2488b7614c0eac8b9b0869d1
parent93e814553c2c2471afd78fd65490a883765f4ffd (diff)
downloadbass-player-51510f09b4bcaf21f75c3133aa6ecbe97c8139b8.tar.gz
"Add" button now is functional
-rw-r--r--Gemfile1
-rw-r--r--bass_player.rb32
2 files changed, 24 insertions, 9 deletions
diff --git a/Gemfile b/Gemfile
index f8b9c3d..548bcf9 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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