summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bass_player.rb15
-rw-r--r--main.qml45
2 files changed, 53 insertions, 7 deletions
diff --git a/bass_player.rb b/bass_player.rb
index 43deba9..4796d61 100644
--- a/bass_player.rb
+++ b/bass_player.rb
@@ -9,6 +9,7 @@ module BassPlayer
property(:title) { '' }
property(:duration) { '' }
+ property(:current_song) { 0 }
property(:model) { QML::ArrayModel.new(:title, :duration) }
property(:part_model) {
QML::ArrayModel.new(:name, :from, :to)
@@ -35,8 +36,11 @@ module BassPlayer
end
def song_selected(song)
+ unless song.nil?
+ self.current_song = model[song][:title]
+ end
part_model.clear
- parts = Part.all.map do |part|
+ parts = Part.join(:songs, title: current_song).all.map do |part|
{
name: part.name,
from: ms_to_time(part.from),
@@ -49,6 +53,15 @@ module BassPlayer
end
end
+ def add_segment(name, from, to)
+ song = Song.first(title: current_song)
+ Part.create(
+ name: name, from: from, to: to,
+ song_id: song.id
+ )
+ song_selected(nil)
+ end
+
def ms_to_time(ms)
retval = Time.at(ms/1000).utc.strftime("%H:%M:%S")
p "ms: '#{ms}' - Time: #{retval}"
diff --git a/main.qml b/main.qml
index 693938e..d0dda5b 100644
--- a/main.qml
+++ b/main.qml
@@ -9,8 +9,6 @@ import BassPlayer 0.1
ApplicationWindow {
visible: true
- width: layout.implicitWidth
- height: layout.implicitHeight
title: "Bass Player!"
@@ -37,7 +35,9 @@ ApplicationWindow {
title: "Duration"
}
onClicked: {
- song.song_selected('song')
+ console.log(song.current_song)
+ song.song_selected(row)
+ console.log(song.current_song)
}
}
@@ -118,19 +118,23 @@ ApplicationWindow {
timer.stop()
}
}
+ Button {
+ text: "Add segment"
+ onClicked: {
+ addSegmentDialog.open()
+ }
+ }
}
}
SongController {
id: song
- title: titleField.text
- duration: durationField.text
}
Audio {
id: audioInterface
- audioRole: MusicRole
+ //audioRole: MusicRole
}
Timer {
@@ -141,4 +145,33 @@ ApplicationWindow {
slider.value = audioInterface.position / audioInterface.duration
}
}
+
+ Dialog {
+ id: addSegmentDialog
+ title: "Add a segment"
+ standardButtons: StandardButton.Save | StandardButton.Cancel
+
+ onAccepted: {
+ song.add_segment(
+ textviewName.text,
+ textviewFrom.text,
+ textviewTo.text
+ )
+ }
+
+ ColumnLayout {
+ TextField {
+ id: textviewName
+ placeholderText: "Name"
+ }
+ TextField {
+ id: textviewFrom
+ placeholderText: "From"
+ }
+ TextField {
+ id: textviewTo
+ placeholderText: "To"
+ }
+ }
+ }
}