Skip to content

Commit 353451e

Browse files
committed
feat: mute one output device instead of every device
The system mute set the default device's hardware mute, which went quiet across every device. Mix now mutes a device by tapping the apps playing to it and replaying them at zero, the way ducking works, so audio routed anywhere else keeps playing. Any output can be muted from the device menu, and the choice is saved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M1TLqzFzT1nNTy6vsfQ1w1
1 parent 352672b commit 353451e

8 files changed

Lines changed: 199 additions & 19 deletions

File tree

‎.github/workflows/verify.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: verify
2+
on:
3+
push:
4+
branches: [claude/project-thread-3tkayv]
5+
jobs:
6+
build:
7+
runs-on: macos-26
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: checks
11+
run: |
12+
xcodebuild -version
13+
scripts/check.sh
14+
- name: build
15+
run: |
16+
xcodebuild -project Mix.xcodeproj -scheme Mix -configuration Debug -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO build | tail -40
17+
exit ${PIPESTATUS[0]}

‎Mix/Engine/AudioEngine.swift‎

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ final class AudioEngine: @unchecked Sendable {
103103
case .setSystemVolume(let value):
104104
let device = DeviceCatalog.defaultOutput()
105105
DeviceCatalog.setVolume(value, of: device, scope: kAudioObjectPropertyScopeOutput)
106-
case .setSystemMuted(let muted):
107-
let device = DeviceCatalog.defaultOutput()
108-
DeviceCatalog.setMuted(muted, of: device, scope: kAudioObjectPropertyScopeOutput)
106+
case .setOutputMuted(let uid, let muted):
107+
// Mix mutes a device by silencing the audio it sends there, never
108+
// with the device's own mute: that one silenced every device at
109+
// once. Unmuting still clears a hardware mute, so the button always
110+
// brings the sound back whoever muted it.
111+
persistence.setOutputMuted(muted, uid: uid)
112+
if !muted, let device = DeviceCatalog.device(uid: uid),
113+
DeviceCatalog.isMuted(device, scope: kAudioObjectPropertyScopeOutput) {
114+
DeviceCatalog.setMuted(false, of: device, scope: kAudioObjectPropertyScopeOutput)
115+
}
109116
case .setDefaultOutput(let uid):
110117
outputArrivals.removeValue(forKey: uid)
111118
try? DeviceCatalog.setDefaultOutput(uid: uid)
@@ -191,7 +198,7 @@ final class AudioEngine: @unchecked Sendable {
191198
for (bundleID, processes) in grouped where routes[bundleID] == nil && !MixIdentity.isCallApp(bundleID) {
192199
guard let playing = processes.first(where: \.isPlayingOutput) else { continue }
193200
let route = TapRoute(bundleID: bundleID, volume: 1, muted: false, outputUID: nil)
194-
route.duckUID = ProcessCatalog.outputDeviceUID(of: playing)
201+
route.heldUID = ProcessCatalog.outputDeviceUID(of: playing)
195202
routes[bundleID] = route
196203
}
197204
for route in routes.values where !MixIdentity.isCallApp(route.bundleID) {
@@ -200,6 +207,9 @@ final class AudioEngine: @unchecked Sendable {
200207
}
201208
}
202209

210+
let mutedUIDs = persistence.mutedOutputUIDs
211+
applyOutputMutes(mutedUIDs, grouped: grouped, systemUID: systemUID)
212+
203213
for route in routes.values {
204214
let processes = grouped[route.bundleID] ?? []
205215
rebuild(route: route, processes: processes, systemUID: systemUID)
@@ -221,13 +231,15 @@ final class AudioEngine: @unchecked Sendable {
221231
systemOutput: systemOut,
222232
systemInput: systemIn,
223233
systemVolume: DeviceCatalog.volume(of: systemOutID, scope: kAudioObjectPropertyScopeOutput),
224-
systemMuted: DeviceCatalog.isMuted(systemOutID, scope: kAudioObjectPropertyScopeOutput),
234+
systemMuted: mutedUIDs.contains(systemUID)
235+
|| DeviceCatalog.isMuted(systemOutID, scope: kAudioObjectPropertyScopeOutput),
236+
mutedOutputUIDs: mutedUIDs,
225237
systemInputVolume: DeviceCatalog.hasInput(systemInID)
226238
? DeviceCatalog.volume(of: systemInID, scope: kAudioObjectPropertyScopeInput)
227239
: nil,
228240
outputs: DeviceCatalog.outputsForPicker(),
229241
inputs: DeviceCatalog.inputs(),
230-
apps: makeRows(grouped: grouped, systemOut: systemOut),
242+
apps: makeRows(grouped: grouped, systemOut: systemOut, mutedUIDs: mutedUIDs),
231243
permissionGranted: !tapDenied
232244
)
233245
}
@@ -269,6 +281,42 @@ final class AudioEngine: @unchecked Sendable {
269281
arrivals.removeValue(forKey: uid)
270282
}
271283

284+
/// Muting a device taps every app playing to it and plays it back at zero,
285+
/// the same way ducking works, so apps on other devices never notice.
286+
/// An app already routed by Mix just has its gain dropped. Routes that
287+
/// exist only for the mute go away once their device is unmuted, or once
288+
/// the app has no audio processes left.
289+
private func applyOutputMutes(_ mutedUIDs: Set<String>, grouped: [String: [AudioProcess]], systemUID: String) {
290+
if !mutedUIDs.isEmpty {
291+
for (bundleID, processes) in grouped where routes[bundleID] == nil {
292+
guard let playing = processes.first(where: \.isPlayingOutput) else { continue }
293+
let playingUID = ProcessCatalog.outputDeviceUID(of: playing) ?? systemUID
294+
guard mutedUIDs.contains(playingUID) else { continue }
295+
let route = TapRoute(bundleID: bundleID, volume: 1, muted: false, outputUID: nil)
296+
// An app on the system output keeps following it, so switching
297+
// the system output away from a muted device lets it play.
298+
if playingUID != systemUID { route.heldUID = playingUID }
299+
route.muteHold = true
300+
routes[bundleID] = route
301+
}
302+
}
303+
for (bundleID, route) in routes {
304+
let destination = resolvedUID(for: route, systemUID: systemUID)
305+
let muted = mutedUIDs.contains(destination)
306+
route.setDeviceMuted(muted)
307+
guard route.muteHold else { continue }
308+
let alive = !(grouped[bundleID] ?? []).isEmpty
309+
if !muted || !alive {
310+
route.muteHold = false
311+
if !route.duckHold { route.heldUID = nil }
312+
if !route.needsAudio {
313+
route.teardown()
314+
routes.removeValue(forKey: bundleID)
315+
}
316+
}
317+
}
318+
}
319+
272320
private func rebuildRoute(bundleID: String) {
273321
let grouped = ProcessCatalog.grouped()
274322
guard let route = routes[bundleID] else { return }
@@ -295,20 +343,22 @@ final class AudioEngine: @unchecked Sendable {
295343
}
296344

297345
private func resolvedUID(for route: TapRoute, systemUID: String) -> String {
298-
guard let wanted = route.outputUID ?? route.duckUID else { return systemUID }
346+
guard let wanted = route.outputUID ?? route.heldUID else { return systemUID }
299347
if let device = DeviceCatalog.device(uid: wanted), DeviceCatalog.isAlive(device) {
300348
return wanted
301349
}
302350
return systemUID
303351
}
304352

305-
private func makeRows(grouped: [String: [AudioProcess]], systemOut: DeviceInfo) -> [AppRow] {
353+
private func makeRows(grouped: [String: [AudioProcess]], systemOut: DeviceInfo, mutedUIDs: Set<String>) -> [AppRow] {
306354
let saved = persistence.snapshot.apps
307355
// Apps that actually have audio right now, plus anything Mix is already
308356
// routing. A saved route for an app that is not running stays on disk
309357
// and comes back with the app; it never gets a row of its own here.
310358
var bundleIDs = Set(grouped.filter { $0.value.contains(where: \.isPlayingOutput) }.keys)
311-
bundleIDs.formUnion(routes.keys)
359+
// A route held only for a device mute is not something the user set,
360+
// so a paused app does not linger in the list because of it.
361+
bundleIDs.formUnion(routes.filter { !$0.value.isMuteHoldOnly }.keys)
312362

313363
return bundleIDs.sorted { ProcessCatalog.displayName(bundleID: $0) < ProcessCatalog.displayName(bundleID: $1) }.map { bundleID in
314364
let route = routes[bundleID]
@@ -337,6 +387,7 @@ final class AudioEngine: @unchecked Sendable {
337387
outputUID: outputUID,
338388
destinationName: dest.name,
339389
destinationIsFallback: fallback,
390+
destinationMuted: mutedUIDs.contains(dest.uid),
340391
error: route?.error
341392
)
342393
}
@@ -369,7 +420,7 @@ final class AudioEngine: @unchecked Sendable {
369420
private func releaseDuck() {
370421
for (bundleID, route) in routes where route.duckHold {
371422
route.duckHold = false
372-
route.duckUID = nil
423+
if !route.muteHold { route.heldUID = nil }
373424
if !route.needsAudio {
374425
route.teardown()
375426
routes.removeValue(forKey: bundleID)

‎Mix/Engine/Persistence.swift‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ final class Persistence {
4747
}
4848
}
4949

50+
var mutedOutputUIDs: Set<String> {
51+
queue.sync { store.mutedOutputUIDs }
52+
}
53+
54+
func setOutputMuted(_ muted: Bool, uid: String) {
55+
queue.sync {
56+
if muted {
57+
store.mutedOutputUIDs.insert(uid)
58+
} else {
59+
store.mutedOutputUIDs.remove(uid)
60+
}
61+
persistLocked()
62+
}
63+
}
64+
5065
func markPermissionPrompted() {
5166
queue.sync {
5267
store.didRequestAudioPermission = true

‎Mix/Engine/TapRoute.swift‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ final class TapRoute {
3838
private(set) var duck: Float = 1
3939
/// Keeps a route that only exists for the duck alive until Mix lets go.
4040
var duckHold = false
41+
/// Keeps a route that only exists because its device is muted.
42+
var muteHold = false
4143
/// Where the app was already playing, for a route that exists only to duck
42-
/// it; the replay goes there instead of the system output.
43-
var duckUID: String?
44+
/// or mute it; the replay goes there instead of the system output. Nil for
45+
/// an app that was following the system output, so it keeps following it.
46+
var heldUID: String?
47+
/// The device this route plays to is muted. Never persisted on the route;
48+
/// the engine sets it from the muted device list on every refresh.
49+
private(set) var deviceMuted = false
4450
private(set) var assignedUID: String?
4551
private(set) var isActive = false
4652
private(set) var error: String?
@@ -67,7 +73,28 @@ final class TapRoute {
6773
}
6874

6975
var needsAudio: Bool {
70-
volume != 1 || muted || outputUID != nil || duckHold
76+
isUserManaged || duckHold || muteHold
77+
}
78+
79+
/// Something the user set on this app, as opposed to a temporary hold.
80+
var isUserManaged: Bool {
81+
volume != 1 || muted || outputUID != nil
82+
}
83+
84+
/// Exists only to silence a muted device, so it earns no row of its own.
85+
var isMuteHoldOnly: Bool {
86+
muteHold && !duckHold && !isUserManaged
87+
}
88+
89+
func setDeviceMuted(_ value: Bool) {
90+
guard deviceMuted != value else { return }
91+
deviceMuted = value
92+
applyGain()
93+
// Before the tap exists the app is still playing on its own, so a route
94+
// born muted starts silent rather than fading down from full volume.
95+
if !isActive {
96+
gain.withLock { $0.current = $0.target }
97+
}
7198
}
7299

73100
func setDuck(_ value: Float) {
@@ -144,7 +171,7 @@ final class TapRoute {
144171
}
145172

146173
private func applyGain() {
147-
let target = Self.gain(volume: volume, muted: muted, duck: duck)
174+
let target = Self.gain(volume: volume, muted: muted || deviceMuted, duck: duck)
148175
gain.withLock { $0.target = target }
149176
}
150177

‎Mix/Models.swift‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ struct MixerSnapshot: Codable, Equatable {
3636
var systemOutput: DeviceInfo
3737
var systemInput: DeviceInfo
3838
var systemVolume: Float
39+
/// True when the system output is muted, by Mix or by macOS itself.
3940
var systemMuted: Bool
41+
/// Output devices Mix is holding silent. Only audio headed to these is
42+
/// muted; every other device keeps playing.
43+
var mutedOutputUIDs: Set<String>
4044
var systemInputVolume: Float?
4145
var outputs: [DeviceInfo]
4246
var inputs: [DeviceInfo]
@@ -73,14 +77,17 @@ struct AppRow: Codable, Equatable, Identifiable {
7377
var outputUID: String?
7478
var destinationName: String
7579
var destinationIsFallback: Bool
80+
/// The device this app plays through is muted as a whole.
81+
var destinationMuted: Bool
7682
var error: String?
7783

7884
var id: String { bundleID }
7985
}
8086

8187
enum MixCommand: Codable {
8288
case setSystemVolume(Float)
83-
case setSystemMuted(Bool)
89+
/// Mutes one output device. Audio Mix sends anywhere else is untouched.
90+
case setOutputMuted(uid: String, muted: Bool)
8491
case setDefaultOutput(String)
8592
case setDefaultInput(String)
8693
case setSystemInputVolume(Float)
@@ -102,8 +109,24 @@ struct SavedRoute: Codable, Equatable {
102109
struct SavedStore: Codable, Equatable {
103110
var apps: [String: SavedRoute]
104111
var didRequestAudioPermission: Bool
112+
var mutedOutputUIDs: Set<String>
105113

106-
static let empty = SavedStore(apps: [:], didRequestAudioPermission: false)
114+
static let empty = SavedStore(apps: [:], didRequestAudioPermission: false, mutedOutputUIDs: [])
115+
116+
init(apps: [String: SavedRoute], didRequestAudioPermission: Bool, mutedOutputUIDs: Set<String>) {
117+
self.apps = apps
118+
self.didRequestAudioPermission = didRequestAudioPermission
119+
self.mutedOutputUIDs = mutedOutputUIDs
120+
}
121+
122+
/// routes.json written before per-device mute has no `mutedOutputUIDs`.
123+
/// Synthesised decoding would reject the whole file and lose every route.
124+
init(from decoder: Decoder) throws {
125+
let container = try decoder.container(keyedBy: CodingKeys.self)
126+
apps = try container.decode([String: SavedRoute].self, forKey: .apps)
127+
didRequestAudioPermission = try container.decode(Bool.self, forKey: .didRequestAudioPermission)
128+
mutedOutputUIDs = try container.decodeIfPresent(Set<String>.self, forKey: .mutedOutputUIDs) ?? []
129+
}
107130
}
108131

109132
extension SavedRoute {
@@ -140,6 +163,7 @@ extension MixerSnapshot {
140163
systemInput: .noInput,
141164
systemVolume: 0,
142165
systemMuted: false,
166+
mutedOutputUIDs: [],
143167
systemInputVolume: nil,
144168
outputs: [],
145169
inputs: [],

‎Mix/Views/MixerPopover.swift‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ struct MixerPopover: View {
9292
volume: snapshot.systemVolume,
9393
muted: snapshot.systemMuted,
9494
devices: snapshot.outputs,
95+
mutedUIDs: snapshot.mutedOutputUIDs,
9596
onSelect: { store.apply(.setDefaultOutput($0)) },
9697
onVolume: { store.apply(.setSystemVolume($0)) },
97-
onMute: { store.apply(.setSystemMuted($0)) }
98+
onMute: { uid, muted in store.apply(.setOutputMuted(uid: uid, muted: muted)) }
9899
)
99100

100101
SystemInputLine(
@@ -143,16 +144,29 @@ struct SystemOutputHero: View {
143144
var volume: Float
144145
var muted: Bool
145146
var devices: [DeviceInfo]
147+
var mutedUIDs: Set<String>
146148
var onSelect: (String) -> Void
147149
var onVolume: (Float) -> Void
148-
var onMute: (Bool) -> Void
150+
var onMute: (_ uid: String, _ muted: Bool) -> Void
149151

150152
var body: some View {
151153
VStack(alignment: .leading, spacing: MixSpace.tight) {
152154
Menu {
153155
DestinationList(devices: devices) { uid in
154156
if let uid { onSelect(uid) }
155157
}
158+
Divider()
159+
// Any output can be muted on its own, not just the system one,
160+
// so the speaker an app is pinned to can go quiet while the
161+
// rest keep playing.
162+
Menu("Mute Device") {
163+
ForEach(devices) { output in
164+
Toggle(output.name, isOn: Binding(
165+
get: { mutedUIDs.contains(output.uid) },
166+
set: { onMute(output.uid, $0) }
167+
))
168+
}
169+
}
156170
} label: {
157171
HStack(spacing: MixSpace.gutter) {
158172
Image(systemName: "speaker.wave.2")
@@ -177,7 +191,10 @@ struct SystemOutputHero: View {
177191
.controlSize(.large)
178192
.frame(height: MixMetrics.heroSlider)
179193
.animation(.easeOut(duration: 0.1), value: volume)
180-
MuteButton(muted: muted) { onMute(!muted) }
194+
// Mutes this device only. Apps Mix sends elsewhere keep playing.
195+
MuteButton(muted: muted) {
196+
if !device.uid.isEmpty { onMute(device.uid, !muted) }
197+
}
181198
}
182199
}
183200
.padding(.horizontal, MixSpace.row)
@@ -312,6 +329,12 @@ struct AppRouteRow: View {
312329
}
313330
} label: {
314331
HStack(spacing: MixSpace.tight) {
332+
if app.destinationMuted {
333+
Image(systemName: "speaker.slash.fill")
334+
.font(MixType.chevronSmall)
335+
.foregroundStyle(MixPalette.danger)
336+
.accessibilityLabel("Device muted")
337+
}
315338
Text(destinationLabel)
316339
.font(MixType.label)
317340
.lineLimit(1)

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ per app, from a Control Center style panel in the menu bar.
2525
- **Per-app output.** Route Zoom to your headset and Spotify to your speakers at
2626
the same time.
2727
- **Per-app volume and mute**, independent of the system volume.
28+
- **Per-device mute.** The mute button next to the system volume silences the
29+
system output only; apps you sent to other devices keep playing. *Mute Device*
30+
in the output menu mutes any other output the same way.
2831
- **System output and input** in the same panel, so you are not bouncing between
2932
Mix and System Settings.
3033
- **Routes are remembered.** Quit Mix, reopen it, and your apps land back on the

0 commit comments

Comments
 (0)