1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Stop relying on libmpdclient enums outside of MPDClient

This commit is contained in:
Daniel Barber 2019-02-08 13:27:02 -05:00
parent 58dcab754f
commit 78e732cb7b
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
4 changed files with 26 additions and 9 deletions

View File

@ -7,7 +7,6 @@
// //
import Foundation import Foundation
import mpdclient
class NotificationsController: MPDClientDelegate { class NotificationsController: MPDClientDelegate {
let notificationQueue = DispatchQueue.main let notificationQueue = DispatchQueue.main

View File

@ -7,7 +7,6 @@
// //
import Cocoa import Cocoa
import mpdclient
class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineViewDelegate { class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineViewDelegate {
var queue: [MPDClient.Song] = [] var queue: [MPDClient.Song] = []
@ -73,8 +72,6 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
guard let queuePos = notification.userInfo?[Notification.queuePosKey] as? Int guard let queuePos = notification.userInfo?[Notification.queuePosKey] as? Int
else { return } else { return }
print(queuePos)
let oldSongRowPos = self.queuePos + 1 let oldSongRowPos = self.queuePos + 1
let newSongRowPos = queuePos + 1 let newSongRowPos = queuePos + 1
self.queuePos = queuePos self.queuePos = queuePos
@ -150,7 +147,7 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
owner: self owner: self
) as! NSTableCellView ) as! NSTableCellView
cellView.textField?.stringValue = songItem.song.getTag(MPD_TAG_TITLE) cellView.textField?.stringValue = songItem.song.getTag(.title)
return cellView return cellView
case "songArtistColumn": case "songArtistColumn":
@ -159,7 +156,7 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
owner: self owner: self
) as! NSTableCellView ) as! NSTableCellView
cellView.textField?.stringValue = songItem.song.getTag(MPD_TAG_ARTIST) cellView.textField?.stringValue = songItem.song.getTag(.artist)
return cellView return cellView
default: default:

View File

@ -12,6 +12,26 @@ import mpdclient
extension MPDClient { extension MPDClient {
class Song { class Song {
let mpdSong: OpaquePointer let mpdSong: OpaquePointer
enum TagType: Int {
case unknown = -1
case artist, album, albumArtist, title, track, name,
genre, date, composer, performer, comment, disc
case musicBrainzArtistId
case musicBrainzAlbumId
case musicBrainzAlbumArtistId
case musicBrainzTrackId
case musicBrainzReleaseTrackId
case originalDate
case artistSort
case albumArtistSort
case albumSort
case tagCount
}
init(_ mpdSong: OpaquePointer) { init(_ mpdSong: OpaquePointer) {
self.mpdSong = mpdSong self.mpdSong = mpdSong
@ -21,8 +41,10 @@ extension MPDClient {
mpd_song_free(mpdSong) mpd_song_free(mpdSong)
} }
func getTag(_ tagType: mpd_tag_type) -> String { func getTag(_ tagType: TagType) -> String {
guard let tag = mpd_song_get_tag(mpdSong, tagType, 0) let mpdTagType = mpd_tag_type(rawValue: Int32(tagType.rawValue))
guard let tag = mpd_song_get_tag(mpdSong, mpdTagType, 0)
else { return "" } else { return "" }
return String(cString: tag) return String(cString: tag)

View File

@ -7,7 +7,6 @@
// //
import Foundation import Foundation
import mpdclient
protocol MPDClientDelegate { protocol MPDClientDelegate {
func didUpdateState(mpdClient: MPDClient, state: MPDClient.Status.State) func didUpdateState(mpdClient: MPDClient, state: MPDClient.Status.State)