summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matias.linares@comprandoengrupo.net>2022-06-24 09:45:28 -0300
committerMatias Linares <matias.linares@comprandoengrupo.net>2022-06-24 09:45:28 -0300
commita9a4830d15f2b57f97c88536276675a8eddf89f0 (patch)
tree4a7f4464c3aece4ceea190786b3267c3093b7ef9
parentb0d2b24c6f552b5a54b0f3c3c2b00d596a5ad9c1 (diff)
parent66fb186681ba955c32e4ec954344a781ad52362b (diff)
downloadbass-player-a9a4830d15f2b57f97c88536276675a8eddf89f0.tar.gz
Merge remote-tracking branch 'origin/master'
-rw-r--r--bass_player.rb36
-rw-r--r--main.qml30
2 files changed, 52 insertions, 14 deletions
diff --git a/bass_player.rb b/bass_player.rb
index b625523..9a1d90a 100644
--- a/bass_player.rb
+++ b/bass_player.rb
@@ -10,7 +10,8 @@ module BassPlayer
property(:title) { '' }
property(:duration) { '' }
- property(:current_song) { 0 }
+ property(:current_song) { '' }
+ property(:current_segment) { '' }
property(:model) { QML::ArrayModel.new(:title, :duration) }
property(:segment_model) {
QML::ArrayModel.new(:name, :from, :to)
@@ -48,13 +49,16 @@ module BassPlayer
end
end
- def song_selected(song)
- puts "Selected song: #{song}"
- unless song.nil?
- self.current_song = model[song][:title]
- puts "Setting current song to #{self.current_song}"
+ def song_selected(row)
+ unless row.nil?
+ self.current_song = model[row][:title]
end
+
segment_model.clear
+ self.current_segment = nil
+
+ song = Song.first(title: self.current_song)
+
segments = Song.first(title: self.current_song).segments.map do |segment|
{
name: segment.name,
@@ -63,24 +67,40 @@ module BassPlayer
}
end
+
for segment in segments
segment_model << segment
end
+ return {
+ path: song.path,
+ duration: song.duration
+ }
+ end
+
+ def segment_selected(row)
+ song = Song.first(title: self.current_song)
+ self.current_segment = song.segments[row.to_i].to_hash
end
def add_segment(name, from, to)
song = Song.first(title: current_song)
Segment.create(
- name: name, from: from, to: to,
+ name: name, from: parse_time(from), to: parse_time(to),
song_id: song.id
)
song_selected(nil)
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
+
+ def parse_time(string)
+ # Parses a string of the form '3:12' to milliseconds
+ min, sec = string.split(':').map(&:to_i)
+ return ((min * 60) + sec) * 1000
+ end
end
end
diff --git a/main.qml b/main.qml
index ab7a07a..12a0f3d 100644
--- a/main.qml
+++ b/main.qml
@@ -9,6 +9,8 @@ import BassPlayer 0.1
ApplicationWindow {
visible: true
+ height: 400
+ width: 600
title: "Bass Player!"
@@ -35,9 +37,9 @@ ApplicationWindow {
title: "Duration"
}
onClicked: {
- console.log(song.current_song)
- song.song_selected(row)
- console.log(song.current_song)
+ var tmp = song.song_selected(row)
+ audioInterface.source = tmp.path
+ durationText.text = song.ms_to_time(tmp.duration)
}
}
@@ -62,6 +64,9 @@ ApplicationWindow {
role: "to"
title: "To"
}
+ onClicked: {
+ song.segment_selected(row)
+ }
}
}
FileDialog {
@@ -84,6 +89,11 @@ ApplicationWindow {
Layout.fillWidth: true
}
Text {
+ id: currentPositionText
+ text: { '--:--' }
+ }
+ Text { text: '/' }
+ Text {
id: durationText
text: { '--:--' }
}
@@ -101,7 +111,6 @@ ApplicationWindow {
onClicked: {
audioInterface.play()
timer.start()
- durationText.text = song.ms_to_time(audioInterface.duration)
}
}
Button {
@@ -142,7 +151,16 @@ ApplicationWindow {
running: false
repeat: true
onTriggered: {
+ currentPositionText.text = song.ms_to_time(audioInterface.position)
slider.value = audioInterface.position / audioInterface.duration
+
+ // Cool segment
+ if (song.current_segment) {
+ if(audioInterface.position < song.current_segment.from ||
+ audioInterface.position > song.current_segment.to) {
+ audioInterface.seek(song.current_segment.from)
+ }
+ }
}
}
@@ -166,11 +184,11 @@ ApplicationWindow {
}
TextField {
id: textviewFrom
- placeholderText: "From"
+ placeholderText: "00:00"
}
TextField {
id: textviewTo
- placeholderText: "To"
+ placeholderText: "00:00"
}
}
}