mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
Finish up number display and add seek function
This commit is contained in:
parent
ad837e8cb2
commit
8749be7544
@ -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!
|
||||
|
||||
@ -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
|
||||
|
||||
@ -139,14 +139,16 @@
|
||||
</segmentedControl>
|
||||
</toolbarItem>
|
||||
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="9ol-aR-mzv"/>
|
||||
<toolbarItem implicitItemIdentifier="D72AC4FE-1D0A-420A-8EA8-F28DBFCE9A8E" explicitItemIdentifier="trackProgress" label="Track progress" paletteLabel="Track progress" sizingBehavior="auto" id="n52-8S-6kR">
|
||||
<toolbarItem implicitItemIdentifier="D72AC4FE-1D0A-420A-8EA8-F28DBFCE9A8E" explicitItemIdentifier="trackProgress" label="Track progress" paletteLabel="Track progress" id="n52-8S-6kR">
|
||||
<nil key="toolTip"/>
|
||||
<textField key="view" horizontalHuggingPriority="251" verticalHuggingPriority="750" id="kx6-xm-TAN">
|
||||
<rect key="frame" x="14" y="14" width="59" height="17"/>
|
||||
<size key="minSize" width="50" height="17"/>
|
||||
<size key="maxSize" width="55" height="17"/>
|
||||
<textField key="view" horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="50" id="kx6-xm-TAN">
|
||||
<rect key="frame" x="16" y="14" width="55" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" placeholderString="00:00" id="g0c-k5-wCA">
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="right" placeholderString="8:88:88" id="g0c-k5-wCA">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="textColor" name="tertiaryLabelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
@ -154,21 +156,26 @@
|
||||
<toolbarItem implicitItemIdentifier="71780196-F7F7-466C-8DED-D4AB25336BD1" explicitItemIdentifier="trackProgressBar" label="Track progress bar" paletteLabel="Track progress bar" id="s1h-EC-nvL">
|
||||
<nil key="toolTip"/>
|
||||
<size key="minSize" width="96" height="17"/>
|
||||
<size key="maxSize" width="1000" height="17"/>
|
||||
<size key="maxSize" width="540" height="17"/>
|
||||
<slider key="view" verticalHuggingPriority="750" id="KMy-xf-rmN">
|
||||
<rect key="frame" x="5" y="14" width="96" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<sliderCell key="cell" controlSize="small" enabled="NO" state="on" alignment="left" maxValue="100" tickMarkPosition="above" sliderType="linear" id="zAF-pq-e9g"/>
|
||||
<connections>
|
||||
<action selector="changeTrackProgress:" target="B8D-0N-5wS" id="Dkh-9b-A5y"/>
|
||||
</connections>
|
||||
</slider>
|
||||
</toolbarItem>
|
||||
<toolbarItem implicitItemIdentifier="1FD81C0E-71C5-41A5-9EAE-A6B12A08FA13" label="Track remaining" paletteLabel="Track remaining" sizingBehavior="auto" id="5U7-UV-xn2">
|
||||
<toolbarItem implicitItemIdentifier="1FD81C0E-71C5-41A5-9EAE-A6B12A08FA13" label="Track remaining" paletteLabel="Track remaining" id="5U7-UV-xn2">
|
||||
<nil key="toolTip"/>
|
||||
<textField key="view" horizontalHuggingPriority="251" verticalHuggingPriority="750" id="9WZ-ij-lrb">
|
||||
<rect key="frame" x="20" y="14" width="52" height="17"/>
|
||||
<size key="minSize" width="58" height="17"/>
|
||||
<size key="maxSize" width="60" height="17"/>
|
||||
<textField key="view" horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="58" id="9WZ-ij-lrb">
|
||||
<rect key="frame" x="16" y="14" width="60" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" placeholderString="-00:00" id="XUa-pD-s5c">
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="left" placeholderString="-8:88:88" id="XUa-pD-s5c">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="textColor" name="tertiaryLabelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
@ -176,11 +183,11 @@
|
||||
</allowedToolbarItems>
|
||||
<defaultToolbarItems>
|
||||
<toolbarItem reference="p3r-ty-Pxf"/>
|
||||
<toolbarItem reference="mhg-16-CNM"/>
|
||||
<toolbarItem reference="9ol-aR-mzv"/>
|
||||
<toolbarItem reference="n52-8S-6kR"/>
|
||||
<toolbarItem reference="s1h-EC-nvL"/>
|
||||
<toolbarItem reference="5U7-UV-xn2"/>
|
||||
<toolbarItem reference="mhg-16-CNM"/>
|
||||
<toolbarItem reference="9ol-aR-mzv"/>
|
||||
</defaultToolbarItems>
|
||||
</toolbar>
|
||||
<connections>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user