Skip to content

Commit 6b798e7

Browse files
committed
Playback speed view
Fixes GH-83
1 parent 91129f9 commit 6b798e7

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

Submariner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
3E53DBBC27E41B6400DB4C84 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E53DBBB27E41B6400DB4C84 /* CoreMedia.framework */; };
4545
3E5C42E029846E25009B9699 /* SBOnboardingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E5C42DE29846E25009B9699 /* SBOnboardingController.swift */; };
4646
3E69A2FF28B02D86009800D8 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E69A2FD28B02D86009800D8 /* UserNotifications.framework */; };
47+
3E6DF3D72C3DEA6800055A52 /* SBPlayRateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6DF3D62C3DEA6800055A52 /* SBPlayRateController.swift */; };
4748
3E702DE32A3E8E1F005F7184 /* SBAppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E702DE22A3E8E1F005F7184 /* SBAppDelegate.swift */; };
4849
3E702DE72A428A1B005F7184 /* Synchronized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E702DE62A428A1B005F7184 /* Synchronized.swift */; };
4950
3E702DE92A428CF6005F7184 /* SBSubsonicParsingOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E702DE82A428CF6005F7184 /* SBSubsonicParsingOperation.swift */; };
@@ -206,6 +207,7 @@
206207
3E5C42DE29846E25009B9699 /* SBOnboardingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SBOnboardingController.swift; sourceTree = "<group>"; };
207208
3E6126EB2AD7363100B2A1E2 /* Submariner v4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Submariner v4.xcdatamodel"; sourceTree = "<group>"; };
208209
3E69A2FD28B02D86009800D8 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
210+
3E6DF3D62C3DEA6800055A52 /* SBPlayRateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SBPlayRateController.swift; sourceTree = "<group>"; };
209211
3E702DE22A3E8E1F005F7184 /* SBAppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SBAppDelegate.swift; sourceTree = "<group>"; };
210212
3E702DE62A428A1B005F7184 /* Synchronized.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Synchronized.swift; sourceTree = "<group>"; };
211213
3E702DE82A428CF6005F7184 /* SBSubsonicParsingOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SBSubsonicParsingOperation.swift; sourceTree = "<group>"; };
@@ -718,6 +720,7 @@
718720
3E04F5EC2B70487200E24E56 /* SBAddServerPlaylistController.swift */,
719721
3E04F5EA2B7043F600E24E56 /* SBMergeArtistsController.swift */,
720722
3EA755512C37749D00852938 /* SBJumpToTimestampController.swift */,
723+
3E6DF3D62C3DEA6800055A52 /* SBPlayRateController.swift */,
721724
);
722725
name = "Window Controllers";
723726
sourceTree = "<group>";
@@ -862,6 +865,7 @@
862865
3E32BE522B8D9FDE00E77CF0 /* SBLibraryItemPasteboardWriter.swift in Sources */,
863866
3E1B785E2ACE5039008927C6 /* SBInspectorController.swift in Sources */,
864867
3EF978022BC3C4E300C986E9 /* SBMessageTextView.swift in Sources */,
868+
3E6DF3D72C3DEA6800055A52 /* SBPlayRateController.swift in Sources */,
865869
3E70B2DF2A2BDC55002C0B93 /* SBApplication.swift in Sources */,
866870
3E702DE72A428A1B005F7184 /* Synchronized.swift in Sources */,
867871
3EC03B4029F4F2E0001FDE50 /* SBDownloads.swift in Sources */,

Submariner/SBDatabaseController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
@class SBEditServerController;
4646
@class SBAddServerPlaylistController;
4747
@class SBJumpToTimestampController;
48+
@class SBPlayRateController;
4849
@class SBMusicController;
4950
@class SBMusicSearchController;
5051
@class SBServerSearchController;
@@ -79,6 +80,7 @@
7980
IBOutlet NSTreeController *resourcesController;
8081
IBOutlet SBEditServerController *editServerController;
8182
SBJumpToTimestampController *jumpToTimestampController;
83+
SBPlayRateController *playRateController;
8284
SBAddServerPlaylistController *addServerPlaylistController;
8385
IBOutlet NSProgressIndicator *progressIndicator;
8486
IBOutlet NSButton *toggleButton;

Submariner/SBDatabaseController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ - (id)initWithManagedObjectContext:(NSManagedObjectContext *)context {
131131
// init sheet controllers not managed by IB
132132
jumpToTimestampController = [[SBJumpToTimestampController alloc] init];
133133
jumpToTimestampController.parentWindow = self.window;
134+
playRateController = [[SBPlayRateController alloc] init];
135+
playRateController.parentWindow = self.window;
134136

135137
[onboardingController setDatabaseController:self];
136138
[musicController setDatabaseController:self];
@@ -975,6 +977,11 @@ - (IBAction)jumpToTimestamp:(id)sender {
975977
[jumpToTimestampController openSheet: sender];
976978
}
977979

980+
981+
- (IBAction)showPlayRate:(id)sender {
982+
[playRateController openSheet: sender];
983+
}
984+
978985
#pragma mark -
979986
#pragma mark NSTimer
980987

Submariner/SBPlayRateController.swift

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//
2+
// SBPlayRateController.swift
3+
// Submariner
4+
//
5+
// Created by Calvin Buckley on 2024-07-09.
6+
//
7+
// Copyright (c) 2024 Calvin Buckley
8+
// SPDX-License-Identifier: BSD-3-Clause
9+
//
10+
11+
import Cocoa
12+
import SwiftUI
13+
14+
@objc class SBPlayRateController: SBSheetController {
15+
var newTimestampString: String?
16+
17+
override func openSheet(_ sender: Any!) {
18+
let timestampString = SBPlayer.sharedInstance().currentTimeString
19+
let viewController = NSHostingController(rootView: PlayRateControllerView(playRateController: self))
20+
let sheet = NSWindow(contentViewController: viewController)
21+
sheet.hasShadow = true
22+
sheet.isReleasedWhenClosed = true
23+
// This is pretty gross and based on vibes, but not sure how to get the content size;
24+
// preferredContentSize seems to be small as possible.
25+
sheet.setContentSize(NSSize(width: 300, height: 100))
26+
self.sheet = sheet
27+
28+
super.openSheet(sender)
29+
}
30+
31+
override func closeSheet(_ sender: Any!) {
32+
// TODO: Put some effort into parsing?
33+
if let newTimestampString = self.newTimestampString {
34+
SBPlayer.sharedInstance().seek(to: newTimestampString.toTimeInterval())
35+
}
36+
37+
super.closeSheet(sender)
38+
}
39+
40+
struct PlayRateControllerView: View {
41+
weak var playRateController: SBPlayRateController!
42+
43+
@AppStorage("playRate") private var playRate: Double = 1.0
44+
45+
var body: some View {
46+
VStack {
47+
Form {
48+
Slider(value: $playRate, in: 0.5...2, step: 0.25) {
49+
Text("Playback Speed")
50+
} minimumValueLabel: {
51+
Text("0.5")
52+
} maximumValueLabel: {
53+
Text("2")
54+
}
55+
}
56+
HStack {
57+
Button {
58+
playRate = 1.0
59+
} label: {
60+
Text("Reset")
61+
}
62+
Spacer()
63+
Button {
64+
playRateController.closeSheet(playRateController)
65+
} label: {
66+
Text("OK")
67+
}
68+
.keyboardShortcut(.defaultAction)
69+
}
70+
}
71+
.padding(20)
72+
}
73+
}
74+
}
75+

Submariner/en.lproj/MainMenu.xib

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,13 @@ DQ
518518
<binding destination="s2r-9F-vP5" name="value" keyPath="values.shuffle" id="hud-gw-zmG"/>
519519
</connections>
520520
</menuItem>
521+
<menuItem isSeparatorItem="YES" id="RXO-ow-3eh"/>
522+
<menuItem title="Playback Speed..." id="ZS2-kE-T3v">
523+
<modifierMask key="keyEquivalentModifierMask"/>
524+
<connections>
525+
<action selector="showPlayRate:" target="-1" id="KSg-pu-9n2"/>
526+
</connections>
527+
</menuItem>
521528
</items>
522529
</menu>
523530
</menuItem>

0 commit comments

Comments
 (0)