summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matias.linares@comprandoengrupo.net>2022-06-22 14:31:23 -0300
committerMatias Linares <matias.linares@comprandoengrupo.net>2022-06-22 14:31:23 -0300
commitbfe3973d0925fa3a429b327563558d36df1934e1 (patch)
tree9f3bf3417012679ac0fa0ac48039f58f8ca52e84
downloadbass-player-bfe3973d0925fa3a429b327563558d36df1934e1.tar.gz
Initial commit
-rw-r--r--Gemfile7
-rw-r--r--Gemfile.lock22
-rw-r--r--Rakefile9
-rw-r--r--bass_player.rb62
-rw-r--r--database.rb1
-rw-r--r--main.qml144
-rw-r--r--migrations/initial.rb20
-rw-r--r--models.rb9
8 files changed, 274 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..f8b9c3d
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,7 @@
+source "https://rubygems.org"
+ruby "3.0.3"
+
+gem "qml"
+gem "sequel"
+gem "rake"
+gem "sqlite3"
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..296f578
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,22 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ qml (1.0.2)
+ rake (13.0.6)
+ sequel (5.57.0)
+ sqlite3 (1.4.4)
+
+PLATFORMS
+ x86_64-linux
+
+DEPENDENCIES
+ qml
+ rake
+ sequel
+ sqlite3
+
+RUBY VERSION
+ ruby 3.0.3p157
+
+BUNDLED WITH
+ 2.3.10
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..adfc922
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,9 @@
+task default: %w[test]
+
+task :test do
+ p "Hello from rakefile"
+end
+
+task :migrate do
+ ruby "migrations/initial.rb"
+end
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
diff --git a/database.rb b/database.rb
new file mode 100644
index 0000000..6cdfb42
--- /dev/null
+++ b/database.rb
@@ -0,0 +1 @@
+require "sequel"
diff --git a/main.qml b/main.qml
new file mode 100644
index 0000000..693938e
--- /dev/null
+++ b/main.qml
@@ -0,0 +1,144 @@
+// main.qml
+import QtQuick 2.15
+import QtQuick.Controls 1.4
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.1
+import QtQuick.Dialogs 1.3
+import QtMultimedia 5.15
+import BassPlayer 0.1
+
+ApplicationWindow {
+ visible: true
+ width: layout.implicitWidth
+ height: layout.implicitHeight
+
+ title: "Bass Player!"
+
+ ColumnLayout {
+ anchors.fill: parent
+ anchors.margins: 10
+ width: 700
+ RowLayout {
+ TableView {
+ id: songTable
+ model: song.model
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+ Layout.alignment: Qt.AlignTop
+ //Layout.minimumWidth: 300
+ alternatingRowColors: true
+
+ TableViewColumn {
+ role: "title"
+ title: "Title"
+ }
+ TableViewColumn {
+ role: "duration"
+ title: "Duration"
+ }
+ onClicked: {
+ song.song_selected('song')
+ }
+ }
+
+ TableView {
+ id: songPartTable
+ model: song.part_model
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+ Layout.alignment: Qt.AlignTop
+ //Layout.minimumWidth: 300
+ alternatingRowColors: true
+
+ TableViewColumn {
+ role: "name"
+ title: "Name"
+ }
+ TableViewColumn {
+ role: "from"
+ title: "From"
+ }
+ TableViewColumn {
+ role: "to"
+ title: "To"
+ }
+ }
+ }
+ FileDialog {
+ id: fileDialog
+ title: "Select a song"
+ folder: shortcuts.music
+ onAccepted: {
+ audioInterface.source = fileDialog.fileUrl.toString()
+ durationText.text = song.ms_to_time(audioInterface.duration)
+ song.add(fileDialog.fileUrl.toString(), audioInterface.duration, audioInterface.metaData)
+
+ }
+ }
+ RowLayout {
+ Slider {
+ id: slider
+ from: 0
+ to: 1
+ value: 0
+ Layout.fillWidth: true
+ }
+ Text {
+ id: durationText
+ text: { '--:--' }
+ }
+ }
+
+ RowLayout {
+ Button {
+ text: "Add"
+ onClicked: {
+ fileDialog.open()
+ }
+ }
+ Button {
+ text: "Play"
+ onClicked: {
+ audioInterface.play()
+ timer.start()
+ durationText.text = song.ms_to_time(audioInterface.duration)
+ }
+ }
+ Button {
+ text: "Stop"
+ onClicked: {
+ audioInterface.stop()
+ timer.restart()
+ }
+ }
+ Button {
+ text: "Pause"
+ onClicked: {
+ audioInterface.pause()
+ timer.stop()
+ }
+ }
+ }
+
+ }
+
+ SongController {
+ id: song
+ title: titleField.text
+ duration: durationField.text
+ }
+
+ Audio {
+ id: audioInterface
+ audioRole: MusicRole
+ }
+
+ Timer {
+ id: timer
+ running: false
+ repeat: true
+ onTriggered: {
+ slider.value = audioInterface.position / audioInterface.duration
+ }
+ }
+}
diff --git a/migrations/initial.rb b/migrations/initial.rb
new file mode 100644
index 0000000..b19aba3
--- /dev/null
+++ b/migrations/initial.rb
@@ -0,0 +1,20 @@
+require "sequel"
+
+DB = Sequel.connect('sqlite:///tmp/bass-player.db')
+
+DB.create_table(:songs) do
+ primary_key :id
+ String :title
+ Integer :duration
+ String :path
+
+ foreign_key :song_id, :songs
+end
+
+DB.create_table(:parts) do
+ primary_key :id
+ String :name
+ Integer :from
+ Integer :to
+ Integer :song_id
+end
diff --git a/models.rb b/models.rb
new file mode 100644
index 0000000..8548fc6
--- /dev/null
+++ b/models.rb
@@ -0,0 +1,9 @@
+require 'sequel'
+DB = Sequel.connect('sqlite:///tmp/bass-player.db')
+
+class Song < Sequel::Model
+ one_to_many :parts
+end
+
+class Part < Sequel::Model
+end