From bfe3973d0925fa3a429b327563558d36df1934e1 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 22 Jun 2022 14:31:23 -0300 Subject: Initial commit --- bass_player.rb | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 bass_player.rb (limited to 'bass_player.rb') diff --git a/bass_player.rb b/bass_player.rb new file mode 100644 index 0000000..43deba9 --- /dev/null +++ b/bass_player.rb @@ -0,0 +1,62 @@ +require 'qml' +require './models' + +module BassPlayer + VERSION = '0.1' + class SongController + include QML::Access + register_to_qml + + property(:title) { '' } + property(:duration) { '' } + property(:model) { QML::ArrayModel.new(:title, :duration) } + property(:part_model) { + QML::ArrayModel.new(:name, :from, :to) + } + + def initialize + super() + Song.all.each do |song| + p song + model << { + title: song.title, + duration: ms_to_time(song.duration) + } + end + end + + def add(file_url, duration, metadata) + item = { + title: file_url, + duration: duration + } + p item + model << item + end + + def song_selected(song) + part_model.clear + parts = Part.all.map do |part| + { + name: part.name, + from: ms_to_time(part.from), + to: ms_to_time(part.to) + } + end + + for part in parts + part_model << part + end + end + + def ms_to_time(ms) + retval = Time.at(ms/1000).utc.strftime("%H:%M:%S") + p "ms: '#{ms}' - Time: #{retval}" + return retval + end + end +end + +QML.run do |app| + app.load_path Pathname(__FILE__) + '../main.qml' +end -- cgit v1.2.3-70-g09d2