From d4164dfa72a2131f5657b644c8e67ed64d042c83 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Wed, 13 Feb 2019 21:24:32 -0500 Subject: [PATCH] Double clicking on a track in the queue plays it --- Persephone/Controllers/QueueViewController.swift | 9 +++++++++ Persephone/MPDClient/MPDClient.swift | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Persephone/Controllers/QueueViewController.swift b/Persephone/Controllers/QueueViewController.swift index 4f9cb20..d31f6bb 100644 --- a/Persephone/Controllers/QueueViewController.swift +++ b/Persephone/Controllers/QueueViewController.swift @@ -52,6 +52,15 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV ) } + @IBAction func playTrack(_ sender: Any) { + guard let view = sender as? NSOutlineView + else { return } + + let queuePos = view.selectedRow - 1 + + AppDelegate.mpdClient.playTrack(queuePos: queuePos) + } + @objc func stateChanged(_ notification: Notification) { guard let state = notification.userInfo?[Notification.stateKey] as? MPDClient.Status.State else { return } diff --git a/Persephone/MPDClient/MPDClient.swift b/Persephone/MPDClient/MPDClient.swift index 87ed839..b2a940e 100644 --- a/Persephone/MPDClient/MPDClient.swift +++ b/Persephone/MPDClient/MPDClient.swift @@ -22,8 +22,8 @@ class MPDClient { private let commandQueue = DispatchQueue(label: "commandQueue") enum Command { - case prevTrack, nextTrack, playPause, stop, fetchStatus, fetchQueue, - fetchAllAlbums + case prevTrack, nextTrack, playPause, stop, + fetchStatus, fetchQueue, fetchAllAlbums } struct Idle: OptionSet { @@ -101,6 +101,14 @@ class MPDClient { queueCommand(command: .nextTrack) } + func playTrack(queuePos: Int) { + noIdle() + commandQueue.async { [unowned self] in + mpd_run_play_pos(self.connection, UInt32(queuePos)) + } + idle() + } + func queueCommand(command: Command) { noIdle() commandQueue.async { [unowned self] in