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