diff --git a/Persephone/Controllers/WindowController.swift b/Persephone/Controllers/WindowController.swift
index cc9648b..7f323f6 100644
--- a/Persephone/Controllers/WindowController.swift
+++ b/Persephone/Controllers/WindowController.swift
@@ -9,6 +9,8 @@
import Cocoa
class WindowController: NSWindowController {
+ let timerFont = NSFont.monospacedDigitSystemFont(ofSize: 13, weight: .regular)
+
enum TransportAction: Int {
case prevTrack, playPause, stop, nextTrack
}
@@ -38,6 +40,9 @@ class WindowController: NSWindowController {
name: Notification.timeChanged,
object: AppDelegate.mpdClient
)
+
+ trackProgress.font = timerFont
+ trackRemaining.font = timerFont
}
@objc func stateChanged(_ notification: Notification) {
@@ -83,6 +88,7 @@ class WindowController: NSWindowController {
trackProgressBar.maxValue = Double(totalTime * 1000)
trackProgressBar.integerValue = Int(elapsedTimeMs)
setTimeElapsed()
+ setTimeRemaining()
trackProgressBar.isEnabled = [.playing, .paused].contains(state)
@@ -108,6 +114,7 @@ class WindowController: NSWindowController {
trackProgressBar.integerValue = Int(elapsedTimeMs!)
setTimeElapsed()
+ setTimeRemaining()
}
func setTimeElapsed() {
@@ -118,6 +125,16 @@ class WindowController: NSWindowController {
trackProgress.stringValue = time.formattedTime
}
+ func setTimeRemaining() {
+ guard let elapsedTimeMs = elapsedTimeMs,
+ let totalTime = totalTime
+ else { return }
+
+ let time = Time(timeInSeconds: -(Int(totalTime) - Int(elapsedTimeMs) / 1000))
+
+ trackRemaining.stringValue = time.formattedTime
+ }
+
@IBAction func handleTransportControl(_ sender: NSSegmentedControl) {
guard let transportAction = TransportAction(rawValue: sender.selectedSegment)
else { return }
@@ -134,6 +151,12 @@ class WindowController: NSWindowController {
}
}
+ @IBAction func changeTrackProgress(_ sender: NSSlider) {
+ let seekTime = Float(sender.integerValue) / 1000
+
+ AppDelegate.mpdClient.seekCurrentSong(timeInSeconds: seekTime)
+ }
+
@IBOutlet var transportControls: NSSegmentedCell!
@IBOutlet var trackProgress: NSTextField!
diff --git a/Persephone/MPDClient/MPDClient.swift b/Persephone/MPDClient/MPDClient.swift
index c10d3f1..d4481fa 100644
--- a/Persephone/MPDClient/MPDClient.swift
+++ b/Persephone/MPDClient/MPDClient.swift
@@ -110,6 +110,14 @@ class MPDClient {
idle()
}
+ func seekCurrentSong(timeInSeconds: Float) {
+ noIdle()
+ commandQueue.async { [unowned self] in
+ mpd_run_seek_current(self.connection, timeInSeconds, false)
+ }
+ idle()
+ }
+
func queueCommand(command: Command) {
noIdle()
commandQueue.async { [unowned self] in
diff --git a/Persephone/Resources/Base.lproj/Main.storyboard b/Persephone/Resources/Base.lproj/Main.storyboard
index 10a4372..8d883df 100644
--- a/Persephone/Resources/Base.lproj/Main.storyboard
+++ b/Persephone/Resources/Base.lproj/Main.storyboard
@@ -139,14 +139,16 @@
-
+
-
-
+
+
+
+
-
+
-
+
@@ -154,21 +156,26 @@
-
+
+
+
+
-
+
-
-
+
+
+
+
-
+
-
+
@@ -176,11 +183,11 @@
-
+
-
+