summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bass_player.rb26
-rw-r--r--main.qml8
-rw-r--r--migrations/initial.rb6
-rw-r--r--models.rb5
4 files changed, 25 insertions, 20 deletions
diff --git a/bass_player.rb b/bass_player.rb
index 9d8b00c..9a1d90a 100644
--- a/bass_player.rb
+++ b/bass_player.rb
@@ -13,7 +13,7 @@ module BassPlayer
property(:current_song) { '' }
property(:current_segment) { '' }
property(:model) { QML::ArrayModel.new(:title, :duration) }
- property(:part_model) {
+ property(:segment_model) {
QML::ArrayModel.new(:name, :from, :to)
}
@@ -54,22 +54,22 @@ module BassPlayer
self.current_song = model[row][:title]
end
- # Clear current segment
+ segment_model.clear
self.current_segment = nil
- # Update model
song = Song.first(title: self.current_song)
- part_model.clear
- parts = song.parts.map do |part|
+
+ segments = Song.first(title: self.current_song).segments.map do |segment|
{
- name: part.name,
- from: ms_to_time(part.from),
- to: ms_to_time(part.to)
+ name: segment.name,
+ from: ms_to_time(segment.from),
+ to: ms_to_time(segment.to)
}
end
- for part in parts
- part_model << part
+
+ for segment in segments
+ segment_model << segment
end
return {
path: song.path,
@@ -79,12 +79,12 @@ module BassPlayer
def segment_selected(row)
song = Song.first(title: self.current_song)
- self.current_segment = song.parts[row.to_i].to_hash
+ self.current_segment = song.segments[row.to_i].to_hash
end
def add_segment(name, from, to)
song = Song.first(title: current_song)
- Part.create(
+ Segment.create(
name: name, from: parse_time(from), to: parse_time(to),
song_id: song.id
)
@@ -92,7 +92,7 @@ module BassPlayer
end
def ms_to_time(ms)
- retval = Time.at(ms/1000).utc.strftime("%H:%M:%S")
+ retval = Time.at(ms/1000).utc.strftime("%M:%S")
return retval
end
diff --git a/main.qml b/main.qml
index a4bb28a..12a0f3d 100644
--- a/main.qml
+++ b/main.qml
@@ -45,7 +45,7 @@ ApplicationWindow {
TableView {
id: songPartTable
- model: song.part_model
+ model: song.segment_model
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
@@ -89,6 +89,11 @@ ApplicationWindow {
Layout.fillWidth: true
}
Text {
+ id: currentPositionText
+ text: { '--:--' }
+ }
+ Text { text: '/' }
+ Text {
id: durationText
text: { '--:--' }
}
@@ -146,6 +151,7 @@ ApplicationWindow {
running: false
repeat: true
onTriggered: {
+ currentPositionText.text = song.ms_to_time(audioInterface.position)
slider.value = audioInterface.position / audioInterface.duration
// Cool segment
diff --git a/migrations/initial.rb b/migrations/initial.rb
index b19aba3..a882142 100644
--- a/migrations/initial.rb
+++ b/migrations/initial.rb
@@ -7,14 +7,12 @@ DB.create_table(:songs) do
String :title
Integer :duration
String :path
-
- foreign_key :song_id, :songs
end
-DB.create_table(:parts) do
+DB.create_table(:segments) do
primary_key :id
String :name
Integer :from
Integer :to
- Integer :song_id
+ foreign_key :song_id, :songs
end
diff --git a/models.rb b/models.rb
index 8548fc6..777a50f 100644
--- a/models.rb
+++ b/models.rb
@@ -2,8 +2,9 @@ require 'sequel'
DB = Sequel.connect('sqlite:///tmp/bass-player.db')
class Song < Sequel::Model
- one_to_many :parts
+ one_to_many :segments
end
-class Part < Sequel::Model
+class Segment < Sequel::Model
+ many_to_one :song
end