Skip to content

Commit 802f027

Browse files
committed
bit depth detection now optional
1 parent 783b5f1 commit 802f027

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

Quality.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@
342342
CODE_SIGN_ENTITLEMENTS = Quality/Quality.entitlements;
343343
CODE_SIGN_STYLE = Automatic;
344344
COMBINE_HIDPI_IMAGES = YES;
345-
CURRENT_PROJECT_VERSION = 13;
345+
CURRENT_PROJECT_VERSION = 14;
346346
DEVELOPMENT_ASSET_PATHS = "\"Quality/Preview Content\"";
347347
DEVELOPMENT_TEAM = 3X69W4AQD6;
348348
ENABLE_HARDENED_RUNTIME = YES;
@@ -376,7 +376,7 @@
376376
CODE_SIGN_ENTITLEMENTS = Quality/Quality.entitlements;
377377
CODE_SIGN_STYLE = Automatic;
378378
COMBINE_HIDPI_IMAGES = YES;
379-
CURRENT_PROJECT_VERSION = 13;
379+
CURRENT_PROJECT_VERSION = 14;
380380
DEVELOPMENT_ASSET_PATHS = "\"Quality/Preview Content\"";
381381
DEVELOPMENT_TEAM = 3X69W4AQD6;
382382
ENABLE_HARDENED_RUNTIME = YES;

Quality/AppDelegate.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7575
let showSampleRateItem = NSMenuItem(title: defaults.statusBarItemTitle, action: #selector(toggleSampleRate(item:)), keyEquivalent: "")
7676
menu.addItem(showSampleRateItem)
7777

78+
let enableBitDepthItem = NSMenuItem(title: "Bit Depth Switching", action: #selector(toggleBitDepthDetection(item:)), keyEquivalent: "")
79+
menu.addItem(enableBitDepthItem)
80+
enableBitDepthItem.state = defaults.userPreferBitDepthDetection ? .on : .off
81+
7882
let selectedDeviceItem = NSMenuItem(title: "Selected Device", action: nil, keyEquivalent: "")
7983
self.devicesMenu = NSMenu()
8084
selectedDeviceItem.submenu = self.devicesMenu
@@ -164,4 +168,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
164168
item.title = defaults.statusBarItemTitle
165169
}
166170

171+
@objc func toggleBitDepthDetection(item: NSMenuItem) {
172+
Task {
173+
await defaults.setPreferBitDepthDetection(newValue: !defaults.userPreferBitDepthDetection)
174+
item.state = defaults.userPreferBitDepthDetection ? .on : .off
175+
}
176+
}
177+
167178
}

Quality/Defaults.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77

88
import Foundation
99

10-
class Defaults {
10+
class Defaults: ObservableObject {
1111
static let shared = Defaults()
1212
private let kUserPreferIconStatusBarItem = "com.vincent-neo.LosslessSwitcher-Key-UserPreferIconStatusBarItem"
1313
private let kSelectedDeviceUID = "com.vincent-neo.LosslessSwitcher-Key-SelectedDeviceUID"
14+
private let kUserPreferBitDepthDetection = "com.vincent-neo.LosslessSwitcher-Key-BitDepthDetection"
1415

1516
private init() {
1617
UserDefaults.standard.register(defaults: [
17-
kUserPreferIconStatusBarItem : true
18+
kUserPreferIconStatusBarItem : true,
19+
kUserPreferBitDepthDetection : false
1820
])
21+
22+
self.userPreferBitDepthDetection = UserDefaults.standard.bool(forKey: kUserPreferBitDepthDetection)
1923
}
2024

2125
var userPreferIconStatusBarItem: Bool {
@@ -35,6 +39,14 @@ class Defaults {
3539
UserDefaults.standard.set(newValue, forKey: kSelectedDeviceUID)
3640
}
3741
}
42+
43+
@Published var userPreferBitDepthDetection: Bool
44+
45+
46+
@MainActor func setPreferBitDepthDetection(newValue: Bool) {
47+
UserDefaults.standard.set(newValue, forKey: kUserPreferBitDepthDetection)
48+
self.userPreferBitDepthDetection = newValue
49+
}
3850

3951
var statusBarItemTitle: String {
4052
let title = self.userPreferIconStatusBarItem ? "Show Sample Rate" : "Show Icon"

Quality/OutputDevices.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class OutputDevices: ObservableObject {
1616
@Published var outputDevices = [AudioDevice]()
1717
@Published var currentSampleRate: Float64?
1818

19+
private var enableBitDepthDetection = Defaults.shared.userPreferBitDepthDetection
20+
private var enableBitDepthDetectionCancellable: AnyCancellable?
21+
1922
private let coreAudio = SimplyCoreAudio()
2023

2124
private var changesCancellable: AnyCancellable?
@@ -53,12 +56,18 @@ class OutputDevices: ObservableObject {
5356
self.getDeviceSampleRate()
5457
})
5558

59+
enableBitDepthDetectionCancellable = Defaults.shared.$userPreferBitDepthDetection.sink(receiveValue: { newValue in
60+
self.enableBitDepthDetection = newValue
61+
})
62+
63+
5664
}
5765

5866
deinit {
5967
changesCancellable?.cancel()
6068
defaultChangesCancellable?.cancel()
6169
timerCancellable?.cancel()
70+
enableBitDepthDetectionCancellable?.cancel()
6271
//timer.upstream.connect().cancel()
6372
}
6473

@@ -118,10 +127,15 @@ class OutputDevices: ObservableObject {
118127
let musicLogs = try Console.getRecentEntries(type: .music)
119128
let coreAudioLogs = try Console.getRecentEntries(type: .coreAudio)
120129
let coreMediaLogs = try Console.getRecentEntries(type: .coreMedia)
121-
allStats.append(contentsOf: CMPlayerParser.parseMusicConsoleLogs(musicLogs))
122-
//allStats.append(contentsOf: CMPlayerParser.parseCoreAudioConsoleLogs(coreAudioLogs))
123-
allStats.append(contentsOf: CMPlayerParser.parseCoreMediaConsoleLogs(coreMediaLogs))
124130

131+
allStats.append(contentsOf: CMPlayerParser.parseMusicConsoleLogs(musicLogs))
132+
if enableBitDepthDetection {
133+
allStats.append(contentsOf: CMPlayerParser.parseCoreAudioConsoleLogs(coreAudioLogs))
134+
}
135+
else {
136+
allStats.append(contentsOf: CMPlayerParser.parseCoreMediaConsoleLogs(coreMediaLogs))
137+
}
138+
125139
allStats.sort(by: {$0.priority > $1.priority})
126140
print("[getAllStats] \(allStats)")
127141
}
@@ -140,7 +154,7 @@ class OutputDevices: ObservableObject {
140154
let sampleRate = Float64(first.sampleRate)
141155
let bitDepth = Int32(first.bitDepth)
142156

143-
if self.currentTrack == self.previousTrack/*, let prevSampleRate = currentSampleRate, prevSampleRate > sampleRate */ {
157+
if self.currentTrack == self.previousTrack, let prevSampleRate = currentSampleRate, prevSampleRate > sampleRate {
144158
print("same track, prev sample rate is higher")
145159
return
146160
}

0 commit comments

Comments
 (0)