From 0bed74b7d3f1fe36437d92d601df1290674d0176 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Fri, 25 Jan 2019 17:19:36 -0500 Subject: [PATCH] You can press a button and a thing happens! --- Persephone.xcodeproj/project.pbxproj | 107 +++++++++++++++++++++++--- Persephone/Base.lproj/Main.storyboard | 13 ++-- Persephone/MPDClient.swift | 62 +++++++++++++++ Persephone/Persephone.entitlements | 7 +- Persephone/ViewController.swift | 1 - Persephone/WindowController.swift | 34 +++++++- Persephone/include/module.modulemap | 5 ++ Persephone/include/mpd | 1 + Persephone/module.modulemap | 4 - 9 files changed, 205 insertions(+), 29 deletions(-) create mode 100644 Persephone/MPDClient.swift create mode 100644 Persephone/include/module.modulemap create mode 120000 Persephone/include/mpd delete mode 100644 Persephone/module.modulemap diff --git a/Persephone.xcodeproj/project.pbxproj b/Persephone.xcodeproj/project.pbxproj index fd66e87..f37a739 100644 --- a/Persephone.xcodeproj/project.pbxproj +++ b/Persephone.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ E407863A2110CE70006887B1 /* PersephoneUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E40786392110CE70006887B1 /* PersephoneUITests.swift */; }; E41B22C021FB6BBA00D544F6 /* libmpdclient.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */; settings = {ATTRIBUTES = (Required, ); }; }; E41B22C121FB6C3300D544F6 /* libmpdclient.2.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; + E41B22C621FB932700D544F6 /* MPDClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E41B22C521FB932700D544F6 /* MPDClient.swift */; }; E465049A21E94DF500A70F4C /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E465049921E94DF500A70F4C /* WindowController.swift */; }; /* End PBXBuildFile section */ @@ -65,6 +66,42 @@ E407863B2110CE70006887B1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libmpdclient.2.dylib; path = libmpdclient/output/libmpdclient.2.dylib; sourceTree = ""; }; E41B22C421FB715A00D544F6 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; + E41B22C521FB932700D544F6 /* MPDClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDClient.swift; sourceTree = ""; }; + E41B22C921FB966C00D544F6 /* connection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = connection.h; sourceTree = ""; }; + E41B22CA21FB966C00D544F6 /* protocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = protocol.h; sourceTree = ""; }; + E41B22CB21FB966C00D544F6 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = error.h; sourceTree = ""; }; + E41B22CC21FB966C00D544F6 /* recv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = recv.h; sourceTree = ""; }; + E41B22CD21FB966C00D544F6 /* client.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = client.h; sourceTree = ""; }; + E41B22CE21FB966C00D544F6 /* song.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = song.h; sourceTree = ""; }; + E41B22CF21FB966C00D544F6 /* response.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = response.h; sourceTree = ""; }; + E41B22D021FB966C00D544F6 /* status.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = status.h; sourceTree = ""; }; + E41B22D121FB966C00D544F6 /* tag.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tag.h; sourceTree = ""; }; + E41B22D221FB966C00D544F6 /* compiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = compiler.h; sourceTree = ""; }; + E41B22D321FB966C00D544F6 /* settings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = settings.h; sourceTree = ""; }; + E41B22D421FB966C00D544F6 /* version.h.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = version.h.in; sourceTree = ""; }; + E41B22D521FB966C00D544F6 /* parser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = parser.h; sourceTree = ""; }; + E41B22D621FB966C00D544F6 /* idle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = idle.h; sourceTree = ""; }; + E41B22D721FB966C00D544F6 /* message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = message.h; sourceTree = ""; }; + E41B22D821FB966C00D544F6 /* player.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = player.h; sourceTree = ""; }; + E41B22D921FB966C00D544F6 /* output.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = output.h; sourceTree = ""; }; + E41B22DA21FB966C00D544F6 /* mixer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mixer.h; sourceTree = ""; }; + E41B22DB21FB966C00D544F6 /* list.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list.h; sourceTree = ""; }; + E41B22DC21FB966C00D544F6 /* async.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = async.h; sourceTree = ""; }; + E41B22DD21FB966C00D544F6 /* directory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = directory.h; sourceTree = ""; }; + E41B22DE21FB966C00D544F6 /* database.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = database.h; sourceTree = ""; }; + E41B22DF21FB966C00D544F6 /* entity.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = entity.h; sourceTree = ""; }; + E41B22E021FB966C00D544F6 /* pair.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pair.h; sourceTree = ""; }; + E41B22E121FB966C00D544F6 /* send.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = send.h; sourceTree = ""; }; + E41B22E221FB966C00D544F6 /* password.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = password.h; sourceTree = ""; }; + E41B22E321FB966C00D544F6 /* audio_format.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = audio_format.h; sourceTree = ""; }; + E41B22E421FB966C00D544F6 /* mount.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mount.h; sourceTree = ""; }; + E41B22E521FB966C00D544F6 /* sticker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sticker.h; sourceTree = ""; }; + E41B22E621FB966C00D544F6 /* search.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = search.h; sourceTree = ""; }; + E41B22E721FB966C00D544F6 /* socket.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = socket.h; sourceTree = ""; }; + E41B22E821FB966C00D544F6 /* stats.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stats.h; sourceTree = ""; }; + E41B22E921FB966C00D544F6 /* capabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = capabilities.h; sourceTree = ""; }; + E41B22EA21FB966C00D544F6 /* queue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = queue.h; sourceTree = ""; }; + E41B22EB21FB966C00D544F6 /* playlist.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = playlist.h; sourceTree = ""; }; E465049921E94DF500A70F4C /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -118,6 +155,7 @@ E407861A2110CE6E006887B1 /* Persephone */ = { isa = PBXGroup; children = ( + E41B22C721FB966C00D544F6 /* include */, E407861B2110CE6E006887B1 /* AppDelegate.swift */, E407861D2110CE6E006887B1 /* ViewController.swift */, E407861F2110CE70006887B1 /* Assets.xcassets */, @@ -125,7 +163,7 @@ E465049921E94DF500A70F4C /* WindowController.swift */, E40786242110CE70006887B1 /* Info.plist */, E40786252110CE70006887B1 /* Persephone.entitlements */, - E41B22C421FB715A00D544F6 /* module.modulemap */, + E41B22C521FB932700D544F6 /* MPDClient.swift */, ); path = Persephone; sourceTree = ""; @@ -156,6 +194,57 @@ name = Frameworks; sourceTree = ""; }; + E41B22C721FB966C00D544F6 /* include */ = { + isa = PBXGroup; + children = ( + E41B22C421FB715A00D544F6 /* module.modulemap */, + E41B22C821FB966C00D544F6 /* mpd */, + ); + path = include; + sourceTree = ""; + }; + E41B22C821FB966C00D544F6 /* mpd */ = { + isa = PBXGroup; + children = ( + E41B22DC21FB966C00D544F6 /* async.h */, + E41B22E321FB966C00D544F6 /* audio_format.h */, + E41B22E921FB966C00D544F6 /* capabilities.h */, + E41B22CD21FB966C00D544F6 /* client.h */, + E41B22D221FB966C00D544F6 /* compiler.h */, + E41B22C921FB966C00D544F6 /* connection.h */, + E41B22DE21FB966C00D544F6 /* database.h */, + E41B22DD21FB966C00D544F6 /* directory.h */, + E41B22DF21FB966C00D544F6 /* entity.h */, + E41B22CB21FB966C00D544F6 /* error.h */, + E41B22D621FB966C00D544F6 /* idle.h */, + E41B22DB21FB966C00D544F6 /* list.h */, + E41B22D721FB966C00D544F6 /* message.h */, + E41B22DA21FB966C00D544F6 /* mixer.h */, + E41B22E421FB966C00D544F6 /* mount.h */, + E41B22D921FB966C00D544F6 /* output.h */, + E41B22E021FB966C00D544F6 /* pair.h */, + E41B22D521FB966C00D544F6 /* parser.h */, + E41B22E221FB966C00D544F6 /* password.h */, + E41B22D821FB966C00D544F6 /* player.h */, + E41B22EB21FB966C00D544F6 /* playlist.h */, + E41B22CA21FB966C00D544F6 /* protocol.h */, + E41B22EA21FB966C00D544F6 /* queue.h */, + E41B22CC21FB966C00D544F6 /* recv.h */, + E41B22CF21FB966C00D544F6 /* response.h */, + E41B22E621FB966C00D544F6 /* search.h */, + E41B22E121FB966C00D544F6 /* send.h */, + E41B22D321FB966C00D544F6 /* settings.h */, + E41B22E721FB966C00D544F6 /* socket.h */, + E41B22CE21FB966C00D544F6 /* song.h */, + E41B22E821FB966C00D544F6 /* stats.h */, + E41B22D021FB966C00D544F6 /* status.h */, + E41B22E521FB966C00D544F6 /* sticker.h */, + E41B22D121FB966C00D544F6 /* tag.h */, + E41B22D421FB966C00D544F6 /* version.h.in */, + ); + path = mpd; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -225,6 +314,11 @@ TargetAttributes = { E40786172110CE6E006887B1 = { CreatedOnToolsVersion = 9.4.1; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 0; + }; + }; }; E40786292110CE70006887B1 = { CreatedOnToolsVersion = 9.4.1; @@ -289,6 +383,7 @@ files = ( E407861E2110CE6E006887B1 /* ViewController.swift in Sources */, E465049A21E94DF500A70F4C /* WindowController.swift in Sources */, + E41B22C621FB932700D544F6 /* MPDClient.swift in Sources */, E407861C2110CE6E006887B1 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -471,10 +566,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; - SYSTEM_HEADER_SEARCH_PATHS = ( - libmpdclient/include, - Persephone, - ); + SYSTEM_HEADER_SEARCH_PATHS = Persephone/include; USER_HEADER_SEARCH_PATHS = libmpdclient/output; }; name = Debug; @@ -501,10 +593,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; - SYSTEM_HEADER_SEARCH_PATHS = ( - libmpdclient/include, - Persephone, - ); + SYSTEM_HEADER_SEARCH_PATHS = Persephone/include; USER_HEADER_SEARCH_PATHS = libmpdclient/output; }; name = Release; diff --git a/Persephone/Base.lproj/Main.storyboard b/Persephone/Base.lproj/Main.storyboard index fc5ff26..16867e0 100644 --- a/Persephone/Base.lproj/Main.storyboard +++ b/Persephone/Base.lproj/Main.storyboard @@ -693,7 +693,6 @@ - @@ -705,13 +704,15 @@ - - - + + + + + @@ -762,13 +763,13 @@ - + - + diff --git a/Persephone/MPDClient.swift b/Persephone/MPDClient.swift new file mode 100644 index 0000000..1e09dbf --- /dev/null +++ b/Persephone/MPDClient.swift @@ -0,0 +1,62 @@ +// +// MPDClient.swift +// Persephone +// +// Created by Daniel Barber on 2019/1/25. +// Copyright © 2019 Dan Barber. All rights reserved. +// + +import Foundation +import mpdclient + +class MPDClient { + let HOST = "localhost" + let PORT: UInt32 = 6600 + private let connection: OpaquePointer + private var status: OpaquePointer? + + init?() { + guard let connection = mpd_connection_new(HOST, PORT, 0) + else { return nil } + + mpd_connection_set_keepalive(connection, true) + + self.connection = connection + } + + deinit { + mpd_connection_free(connection) + } + + func getStatus() { + status = mpd_status_begin() + } + + func playPause() { + mpd_run_toggle_pause(connection) + } + + func stop() { + mpd_run_stop(connection) + } + + func prevTrack() { + mpd_run_previous(connection) + } + + func nextTrack() { + mpd_run_next(connection) + } + + func getLastErrorMessage() -> String! { + if mpd_connection_get_error(connection) == MPD_ERROR_SUCCESS { + return "no error" + } + + if let errorMessage = mpd_connection_get_error_message(connection) { + return String(cString: errorMessage) + } + + return "no error message" + } +} diff --git a/Persephone/Persephone.entitlements b/Persephone/Persephone.entitlements index f2ef3ae..0c67376 100644 --- a/Persephone/Persephone.entitlements +++ b/Persephone/Persephone.entitlements @@ -1,10 +1,5 @@ - - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - + diff --git a/Persephone/ViewController.swift b/Persephone/ViewController.swift index ee033d8..33ea205 100644 --- a/Persephone/ViewController.swift +++ b/Persephone/ViewController.swift @@ -7,7 +7,6 @@ // import Cocoa -import mpdclient class ViewController: NSViewController { override func viewDidLoad() { diff --git a/Persephone/WindowController.swift b/Persephone/WindowController.swift index fb9ab65..81dc51d 100644 --- a/Persephone/WindowController.swift +++ b/Persephone/WindowController.swift @@ -9,8 +9,36 @@ import Cocoa class WindowController: NSWindowController { - override func windowDidLoad() { - super.windowDidLoad() - window?.titleVisibility = .hidden + enum TransportAction: Int { + case prevTrack = 0 + case playPause = 1 + case stop = 2 + case nextTrack = 3 + } + var mpdClient: MPDClient? + + override func windowDidLoad() { + super.windowDidLoad() + window?.titleVisibility = .hidden + mpdClient = MPDClient() + mpdClient?.getStatus() + } + + @IBAction func handleTransportControl(_ sender: NSSegmentedControl) { + guard let transportAction = TransportAction(rawValue: sender.selectedSegment) + else { return } + + switch transportAction { + case .prevTrack: + mpdClient?.prevTrack() + case .playPause: + mpdClient?.playPause() + case .stop: + mpdClient?.stop() + case .nextTrack: + mpdClient?.nextTrack() + default: + break } + } } diff --git a/Persephone/include/module.modulemap b/Persephone/include/module.modulemap new file mode 100644 index 0000000..9f7f1d5 --- /dev/null +++ b/Persephone/include/module.modulemap @@ -0,0 +1,5 @@ +module mpdclient { + umbrella header "mpd/client.h" + export * + module * { export * } +} diff --git a/Persephone/include/mpd b/Persephone/include/mpd new file mode 120000 index 0000000..ecfbd3a --- /dev/null +++ b/Persephone/include/mpd @@ -0,0 +1 @@ +../../libmpdclient/include/mpd \ No newline at end of file diff --git a/Persephone/module.modulemap b/Persephone/module.modulemap deleted file mode 100644 index 1bcf28c..0000000 --- a/Persephone/module.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -module mpdclient [system] { - umbrella "mpd" - export * -}