Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

Match menubar waveform strip styling to other visualizers

authored by

Esteban Uribe and committed by
prompt.ac/@jeffrey
decc2bd9 1e111e44

+51 -6
+51 -6
slab/menuband/Sources/MenuBand/MenuBarWaveformStrip.swift
··· 11 11 final class MenuBarWaveformStrip { 12 12 private let menuBand: MenuBandController 13 13 private let waveformView = WaveformView() 14 + private let waveformBezel = NSView() 14 15 private var panel: NSPanel? 15 16 private weak var statusButton: NSStatusBarButton? 16 17 ··· 54 55 init(menuBand: MenuBandController) { 55 56 self.menuBand = menuBand 56 57 waveformView.menuBand = menuBand 58 + waveformBezel.wantsLayer = true 59 + waveformBezel.layer?.cornerRadius = 6 60 + waveformBezel.layer?.backgroundColor = NSColor(white: 0.06, alpha: 1.0).cgColor 61 + waveformBezel.layer?.borderWidth = 1 57 62 } 58 63 59 64 /// Pre-build the panel so the first note doesn't pay construction cost. ··· 138 143 panel.setFrame(NSRect(x: target.origin.x, y: hiddenY, 139 144 width: target.width, height: target.height), 140 145 display: true) 146 + applyAppearanceToVisualizer() 147 + applyWaveformTint() 141 148 waveformView.isLive = true 142 149 panel.orderFrontRegardless() 143 150 ··· 259 266 p.acceptsMouseMovedEvents = false 260 267 261 268 waveformView.translatesAutoresizingMaskIntoConstraints = false 262 - p.contentView = NSView() 263 - p.contentView!.addSubview(waveformView) 269 + waveformBezel.translatesAutoresizingMaskIntoConstraints = false 270 + let content = NSView() 271 + content.wantsLayer = true 272 + content.layer?.backgroundColor = NSColor.clear.cgColor 273 + p.contentView = content 274 + p.contentView!.addSubview(waveformBezel) 275 + waveformBezel.addSubview(waveformView) 276 + let bezelInset: CGFloat = 5 264 277 NSLayoutConstraint.activate([ 265 - waveformView.leadingAnchor.constraint(equalTo: p.contentView!.leadingAnchor), 266 - waveformView.trailingAnchor.constraint(equalTo: p.contentView!.trailingAnchor), 267 - waveformView.topAnchor.constraint(equalTo: p.contentView!.topAnchor), 268 - waveformView.bottomAnchor.constraint(equalTo: p.contentView!.bottomAnchor), 278 + waveformBezel.leadingAnchor.constraint(equalTo: p.contentView!.leadingAnchor), 279 + waveformBezel.trailingAnchor.constraint(equalTo: p.contentView!.trailingAnchor), 280 + waveformBezel.topAnchor.constraint(equalTo: p.contentView!.topAnchor), 281 + waveformBezel.bottomAnchor.constraint(equalTo: p.contentView!.bottomAnchor), 282 + waveformView.leadingAnchor.constraint(equalTo: waveformBezel.leadingAnchor, constant: bezelInset), 283 + waveformView.trailingAnchor.constraint(equalTo: waveformBezel.trailingAnchor, constant: -bezelInset), 284 + waveformView.topAnchor.constraint(equalTo: waveformBezel.topAnchor, constant: bezelInset), 285 + waveformView.bottomAnchor.constraint(equalTo: waveformBezel.bottomAnchor, constant: -bezelInset), 269 286 ]) 287 + applyAppearanceToVisualizer() 288 + applyWaveformTint() 270 289 271 290 panel = p 272 291 } ··· 274 293 private func positionPanel(_ panel: NSPanel) { 275 294 guard let target = targetFrame() else { return } 276 295 panel.setFrame(target, display: true) 296 + } 297 + 298 + private func applyAppearanceToVisualizer() { 299 + let isDark = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua 300 + waveformView.setLightMode(!isDark) 301 + if isDark { 302 + waveformBezel.layer?.backgroundColor = NSColor(white: 0.06, alpha: 1.0).cgColor 303 + } else { 304 + waveformBezel.layer?.backgroundColor = NSColor(white: 0.82, alpha: 1.0).cgColor 305 + } 306 + } 307 + 308 + private func applyWaveformTint() { 309 + if menuBand.midiMode { 310 + waveformView.setDotMatrix(MenuBandPopoverViewController.midiDotPattern) 311 + waveformView.setBaseColor(.controlAccentColor) 312 + waveformBezel.layer?.borderColor = NSColor.controlAccentColor 313 + .withAlphaComponent(0.55).cgColor 314 + } else { 315 + waveformView.setDotMatrix(nil) 316 + let safe = max(0, min(127, Int(menuBand.melodicProgram))) 317 + let familyColor = InstrumentListView.colorForProgram(safe) 318 + waveformView.setBaseColor(familyColor) 319 + waveformBezel.layer?.borderColor = familyColor 320 + .withAlphaComponent(0.55).cgColor 321 + } 277 322 } 278 323 }