diff --git a/Persephone/Controllers/AlbumDetailView.swift b/Persephone/Controllers/AlbumDetailView.swift
index d611770..d24380d 100644
--- a/Persephone/Controllers/AlbumDetailView.swift
+++ b/Persephone/Controllers/AlbumDetailView.swift
@@ -61,6 +61,21 @@ class AlbumDetailView: NSViewController {
albumCoverView.image = .defaultCoverArt
}
+ @IBAction func playAlbum(_ sender: NSButton) {
+ guard let album = album else { return }
+
+ App.store.dispatch(MPDPlayAlbum(album: album.mpdAlbum))
+ }
+
+ @IBAction func playSong(_ sender: AlbumDetailSongListView) {
+ guard let song = dataSource.albumSongs[sender.selectedRow].song
+ else { return }
+
+ let queueLength = App.store.state.queueState.queue.count
+ App.store.dispatch(MPDAppendTrack(song: song.mpdSong))
+ App.store.dispatch(MPDPlayTrack(queuePos: queueLength))
+ }
+
func getAlbumSongs(for album: Album) {
App.mpdClient.getAlbumSongs(for: album.mpdAlbum) { [weak self] (mpdSongs: [MPDClient.MPDSong]) in
self?.dataSource.setAlbumSongs(
@@ -135,6 +150,10 @@ extension AlbumDetailView: NSTableViewDelegate {
return view
}
+ func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
+ return dataSource.albumSongs[row].disc == nil
+ }
+
func cellForDiscNumber(_ tableView: NSTableView, with disc: String) -> NSView {
let cellView = tableView.makeView(
withIdentifier: .discNumber,
diff --git a/Persephone/Controllers/AlbumViewItem.swift b/Persephone/Controllers/AlbumViewItem.swift
index 311f874..8689a81 100644
--- a/Persephone/Controllers/AlbumViewItem.swift
+++ b/Persephone/Controllers/AlbumViewItem.swift
@@ -58,12 +58,6 @@ class AlbumViewItem: NSCollectionViewItem {
}
}
- @IBAction func playAlbum(_ sender: NSButton) {
- guard let album = album else { return }
-
- App.store.dispatch(MPDPlayAlbum(album: album.mpdAlbum))
- }
-
@IBAction func showAlbumDetail(_ sender: NSButton) {
guard let album = album else { return }
diff --git a/Persephone/MPDClient/Extensions/MPDClient+Command.swift b/Persephone/MPDClient/Extensions/MPDClient+Command.swift
index 7163b59..0934c89 100644
--- a/Persephone/MPDClient/Extensions/MPDClient+Command.swift
+++ b/Persephone/MPDClient/Extensions/MPDClient+Command.swift
@@ -58,6 +58,10 @@ extension MPDClient {
guard let songs = userData["songs"] as? [MPDSong]
else { return }
sendReplaceQueue(songs)
+ case .appendSong:
+ guard let song = userData["song"] as? MPDSong
+ else { return }
+ sendAppendSong(song)
// Album commands
case .fetchAllAlbums:
diff --git a/Persephone/MPDClient/Extensions/MPDClient+Queue.swift b/Persephone/MPDClient/Extensions/MPDClient+Queue.swift
index e8b7829..43c4792 100644
--- a/Persephone/MPDClient/Extensions/MPDClient+Queue.swift
+++ b/Persephone/MPDClient/Extensions/MPDClient+Queue.swift
@@ -18,6 +18,10 @@ extension MPDClient {
enqueueCommand(command: .playTrack, userData: ["queuePos": queuePos])
}
+ func appendSong(_ song: MPDSong) {
+ enqueueCommand(command: .appendSong, userData: ["song": song])
+ }
+
func sendPlayTrack(at queuePos: Int) {
mpd_run_play_pos(self.connection, UInt32(queuePos))
}
@@ -40,4 +44,8 @@ extension MPDClient {
}
mpd_run_play_pos(self.connection, 0)
}
+
+ func sendAppendSong(_ song: MPDSong) {
+ mpd_run_add(self.connection, song.uri)
+ }
}
diff --git a/Persephone/MPDClient/Models/MPDCommand.swift b/Persephone/MPDClient/Models/MPDCommand.swift
index 0bf5330..eaa328c 100644
--- a/Persephone/MPDClient/Models/MPDCommand.swift
+++ b/Persephone/MPDClient/Models/MPDCommand.swift
@@ -30,6 +30,7 @@ extension MPDClient {
case fetchQueue
case playTrack
case replaceQueue
+ case appendSong
// Album commands
case fetchAllAlbums
diff --git a/Persephone/Resources/AlbumDetailView.xib b/Persephone/Resources/AlbumDetailView.xib
index 0b3f423..17a1cf9 100644
--- a/Persephone/Resources/AlbumDetailView.xib
+++ b/Persephone/Resources/AlbumDetailView.xib
@@ -59,6 +59,9 @@
+
+
+
@@ -209,6 +212,9 @@
+
+
+
diff --git a/Persephone/Resources/AlbumViewItem.xib b/Persephone/Resources/AlbumViewItem.xib
index c802cf7..f2f0746 100644
--- a/Persephone/Resources/AlbumViewItem.xib
+++ b/Persephone/Resources/AlbumViewItem.xib
@@ -51,20 +51,6 @@
-
@@ -73,7 +59,6 @@
-
@@ -81,12 +66,10 @@
-
-
@@ -94,6 +77,5 @@
-
diff --git a/Persephone/State/Actions/MPDActions.swift b/Persephone/State/Actions/MPDActions.swift
index f13fb37..d748a5a 100644
--- a/Persephone/State/Actions/MPDActions.swift
+++ b/Persephone/State/Actions/MPDActions.swift
@@ -16,6 +16,10 @@ struct MPDStopAction: Action {}
struct MPDNextTrackAction: Action {}
struct MPDPrevTrackAction: Action {}
+struct MPDAppendTrack: Action {
+ let song: MPDClient.MPDSong
+}
+
struct MPDPlayTrack: Action {
let queuePos: Int
}
diff --git a/Persephone/State/Reducers/MPDReducer.swift b/Persephone/State/Reducers/MPDReducer.swift
index 3e85308..81b992f 100644
--- a/Persephone/State/Reducers/MPDReducer.swift
+++ b/Persephone/State/Reducers/MPDReducer.swift
@@ -30,6 +30,9 @@ func mpdReducer(action: Action, state: MPDState?) -> MPDState {
case is MPDPrevTrackAction:
App.mpdClient.prevTrack()
+ case let action as MPDAppendTrack:
+ App.mpdClient.appendSong(action.song)
+
case let action as MPDPlayTrack:
App.mpdClient.playTrack(at: action.queuePos)
diff --git a/Persephone/Views/AlbumItemView.swift b/Persephone/Views/AlbumItemView.swift
index 0d74816..ce56c16 100644
--- a/Persephone/Views/AlbumItemView.swift
+++ b/Persephone/Views/AlbumItemView.swift
@@ -9,80 +9,9 @@
import AppKit
class AlbumItemView: NSView {
- var trackingArea: NSTrackingArea?
-
- override func updateTrackingAreas() {
- super.updateTrackingAreas()
-
- guard let albumImageView = imageView else { return }
-
- if let trackingArea = self.trackingArea {
- self.removeTrackingArea(trackingArea)
- }
-
- let trackingArea = NSTrackingArea(
- rect: albumImageView.frame,
- options: [.mouseEnteredAndExited, .activeAlways],
- owner: self,
- userInfo: nil
- )
-
- self.trackingArea = trackingArea
- addTrackingArea(trackingArea)
- }
-
required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
-
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(viewWillScroll(_:)),
- name: NSScrollView.willStartLiveScrollNotification,
- object: nil
- )
-
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(viewDidScroll(_:)),
- name: NSScrollView.didLiveScrollNotification,
- object: nil
- )
- }
-
- override func prepareForReuse() {
- super.prepareForReuse()
-
- hidePlayButton()
- }
-
- @objc func viewWillScroll(_ notification: Notification) {
- hidePlayButton()
- }
-
- @objc func viewDidScroll(_ notification: Notification) {
- hidePlayButton()
- }
-
- override func resize(withOldSuperviewSize oldSize: NSSize) {
- hidePlayButton()
- }
-
- override func mouseEntered(with event: NSEvent) {
- showPlayButton()
- }
-
- override func mouseExited(with event: NSEvent) {
- hidePlayButton()
- }
-
- func showPlayButton() {
- playButton.isHidden = false
- }
-
- func hidePlayButton() {
- playButton.isHidden = true
}
@IBOutlet var imageView: NSImageView!
- @IBOutlet var playButton: NSButton!
}