Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Camera9// File : App/Sources/Features/Camera/DialPanel.swift10// Description : The parameter strip (ISO, shutter, EV, focus, white11// balance, zoom) and the dial that opens for the selected12// parameter. Ranges and stops come from the camera's13// capabilities; values shown are read back from it.14// Module : Features15// Repository : https://git.spboucher.ai/orix-camera16// Project Website : https://www.orixlab.dev17// Created : 2026-11-2118// Last Modified : 2026-11-2119//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : Proprietary, all rights reserved (see license file)85// License File : LICENSE86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import ORIXDesign94import ORIXImaging95import SwiftUI9697struct ParameterStrip: View {98 @Bindable var model: CameraModel99100 var body: some View {101 let live = model.live, caps = model.capabilities102 HStack(spacing: 2) {103 chip(.iso, "ISO", ExposureMath.isoLabel(live.iso), manual: live.exposureMode == .manual, enabled: caps?.supportsManualExposure == true)104 chip(.shutter, "SHUTTER", ExposureMath.shutterLabel(live.exposureDuration), manual: live.exposureMode == .manual, enabled: caps?.supportsManualExposure == true)105 chip(.bias, "EV", live.exposureMode == .manual ? String(format: "%+.1f", live.exposureOffset) : String(format: "%+.1f", live.exposureBias),106 manual: abs(live.exposureBias) > 0.01 || live.exposureMode == .locked, enabled: true)107 chip(.focus, live.focusMode == .manual ? "MF" : "AF", live.focusMode == .manual ? String(format: "%.2f", live.lensPosition) : (live.isAdjustingFocus ? "…" : "AUTO"),108 manual: live.focusMode == .manual, enabled: caps?.supportsManualFocus == true)109 chip(.whiteBalance, "WB", live.whiteBalanceMode == .locked ? "\(Int((live.temperature / 50).rounded()) * 50)K" : "AUTO",110 manual: live.whiteBalanceMode == .locked, enabled: caps?.supportsWhiteBalanceLock == true)111 chip(.zoom, "ZOOM", String(format: "%.1f×", live.zoom), manual: live.zoom > 1.01, enabled: (caps?.maxZoom ?? 1) > 1)112 }113 .padding(.horizontal, 8)114 }115116 private func chip(_ dial: ProDial, _ label: LocalizedStringKey, _ value: String, manual: Bool, enabled: Bool) -> some View {117 Button {118 guard enabled else {119 model.show(explanation(for: dial), .info); return120 }121 withAnimation(.snappy(duration: 0.2)) { model.activeDial = model.activeDial == dial ? nil : dial }122 model.applyMonitoring()123 model.haptic()124 } label: {125 ReadoutChip(label: label, value: value, isManual: manual, isSelected: model.activeDial == dial, isEnabled: enabled)126 }127 .buttonStyle(.plain)128 .accessibilityIdentifier("chip.\(dial.rawValue)")129 .accessibilityLabel(Text(label))130 .accessibilityValue(Text(value))131 .accessibilityAddTraits(model.activeDial == dial ? .isSelected : [])132 }133134 private func explanation(for dial: ProDial) -> String {135 guard let caps = model.capabilities else { return "" }136 switch dial {137 case .iso, .shutter: return caps.localizedExplanation(for: .manualExposure) ?? ""138 case .focus: return caps.localizedExplanation(for: .manualFocus) ?? ""139 case .whiteBalance, .tint: return caps.localizedExplanation(for: .whiteBalanceLock) ?? ""140 default: return String(localized: "Not available on this camera.")141 }142 }143}144145struct DialPanel: View {146 @Bindable var model: CameraModel147 let dial: ProDial148149 var body: some View {150 VStack(spacing: 4) {151 switch dial {152 case .iso: isoDial153 case .shutter: shutterDial154 case .bias: biasDial155 case .focus: focusDial156 case .whiteBalance, .tint: whiteBalanceDial157 case .zoom: zoomDial158 }159 }160 .padding(.horizontal, 12)161 .padding(.top, 6)162 .background(Instrument.panel.opacity(0.9))163 .transition(.move(edge: .bottom).combined(with: .opacity))164 }165166 private func nearest(_ values: [Double], _ target: Double) -> Int {167 values.indices.min { abs(log(values[$0] / max(target, 1e-9))) < abs(log(values[$1] / max(target, 1e-9))) } ?? 0168 }169170 @ViewBuilder private var isoDial: some View {171 if let caps = model.capabilities {172 let stops = ExposureMath.stops(ExposureMath.isoStops, min: caps.minISO, max: caps.maxISO)173 HStack {174 PillButton(title: "AUTO", isOn: model.live.exposureMode == .auto) { model.setAutoExposure() }.accessibilityIdentifier("dial.auto")175 RulerDial(count: stops.count, index: Binding(get: { nearest(stops, model.live.exposureMode == .manual ? model.manualISO : model.live.iso) },176 set: { model.setManualExposure(iso: stops[$0]) }),177 label: { ExposureMath.isoLabel(stops[$0]) }, accessibilityName: "ISO", haptics: model.settings.haptics)178 }179 }180 }181182 @ViewBuilder private var shutterDial: some View {183 if let caps = model.capabilities {184 // Fastest first reads naturally on a ruler: drag right for a longer exposure.185 let stops = ExposureMath.stops(ExposureMath.shutterStops, min: caps.minExposureDuration, max: caps.maxExposureDuration)186 HStack {187 PillButton(title: "AUTO", isOn: model.live.exposureMode == .auto) { model.setAutoExposure() }.accessibilityIdentifier("dial.auto")188 if model.mode == .video {189 PillButton(title: "180°", isOn: abs(model.live.exposureDuration - ExposureMath.shutter180(frameRate: model.settings.videoFrameRate)) < 0.0005 && model.live.exposureMode == .manual) { model.applyShutter180() }190 .accessibilityLabel(Text("180 degree shutter"))191 }192 RulerDial(count: stops.count, index: Binding(get: { nearest(stops, model.live.exposureMode == .manual ? model.manualShutter : model.live.exposureDuration) },193 set: { model.setManualExposure(shutter: stops[$0]) }),194 label: { ExposureMath.shutterLabel(stops[$0]) }, accessibilityName: "Shutter speed", haptics: model.settings.haptics)195 }196 }197 }198199 @ViewBuilder private var biasDial: some View {200 if let caps = model.capabilities {201 let lower = max(caps.minExposureBias, -4), upper = min(caps.maxExposureBias, 4)202 let count = Int(((upper - lower) * 3).rounded()) + 1203 HStack {204 PillButton(title: "0", isOn: abs(model.bias) < 0.01) { model.setBias(0); model.haptic() }.accessibilityLabel(Text("Reset exposure compensation"))205 PillButton(title: "AE-L", isOn: model.live.exposureMode == .locked) { model.toggleExposureLock() }.accessibilityLabel(Text("Exposure lock"))206 RulerDial(count: count, index: Binding(get: { Int(((model.bias - lower) * 3).rounded()) }, set: { model.setBias(lower + Double($0) / 3) }),207 label: { String(format: "%+.1f", lower + Double($0) / 3) }, accessibilityName: "Exposure compensation", haptics: model.settings.haptics)208 }209 if model.live.exposureMode == .manual {210 Text("In manual exposure, EV shows the metered offset from the camera's target.")211 .font(.caption2).foregroundStyle(Instrument.textFaint).frame(maxWidth: .infinity, alignment: .leading)212 }213 }214 }215216 @ViewBuilder private var focusDial: some View {217 HStack {218 PillButton(title: "AF", isOn: model.live.focusMode == .auto) { model.setAutoFocus(); model.applyMonitoring() }.accessibilityIdentifier("dial.auto").accessibilityLabel(Text("Autofocus"))219 RulerDial(count: 101, index: Binding(get: { Int(((model.live.focusMode == .manual ? model.manualFocus : model.live.lensPosition) * 100).rounded()) },220 set: { model.setManualFocus(Double($0) / 100); model.applyMonitoring() }),221 majorEvery: 10, label: { $0 == 0 ? String(localized: "near") : ($0 == 100 ? String(localized: "far") : String(format: "%.1f", Double($0) / 100)) },222 accessibilityName: "Focus position", haptics: false)223 }224 HStack(spacing: 6) {225 Text("Lens position, 0 (near) to 1 (far). Not a distance.").font(.caption2).foregroundStyle(Instrument.textFaint).lineLimit(2)226 Spacer(minLength: 4)227 PillButton(title: "A", isOn: model.focusPullA != nil) { model.focusPullA = model.live.lensPosition; model.haptic() }.accessibilityLabel(Text("Set focus mark A"))228 PillButton(title: "B", isOn: model.focusPullB != nil) { model.focusPullB = model.live.lensPosition; model.haptic() }.accessibilityLabel(Text("Set focus mark B"))229 PillButton(title: "PULL", isOn: false) { model.runFocusPull() }230 .disabled(model.focusPullA == nil || model.focusPullB == nil)231 .opacity(model.focusPullA == nil || model.focusPullB == nil ? 0.4 : 1)232 .accessibilityLabel(Text("Run focus pull from A to B"))233 }234 }235236 @ViewBuilder private var whiteBalanceDial: some View {237 let kelvin = stride(from: 2000.0, through: 10000, by: 100).map { $0 }238 HStack {239 PillButton(title: "AWB", isOn: model.live.whiteBalanceMode == .auto) { model.setAutoWhiteBalance() }.accessibilityIdentifier("dial.auto").accessibilityLabel(Text("Auto white balance"))240 RulerDial(count: kelvin.count, index: Binding(get: { nearest(kelvin, model.live.whiteBalanceMode == .locked ? model.wbTemperature : model.live.temperature) },241 set: { model.setWhiteBalance(temperature: kelvin[$0]) }),242 majorEvery: 5, label: { "\(Int(kelvin[$0]))K" }, accessibilityName: "White balance temperature", haptics: model.settings.haptics)243 }244 ScrollView(.horizontal, showsIndicators: false) {245 HStack(spacing: 6) {246 PillButton(title: "WB-L", isOn: model.live.whiteBalanceMode == .locked) { model.toggleWhiteBalanceLock() }.accessibilityLabel(Text("White balance lock"))247 ForEach(WhiteBalancePreset.builtIn) { preset in248 Button { model.apply(preset) } label: {249 Label(LocalizedStringKey(preset.title), systemImage: preset.symbol)250 .font(Instrument.label).foregroundStyle(Instrument.text)251 .padding(.horizontal, 10).frame(minHeight: 32)252 .background(Instrument.panelRaised, in: Capsule()).frame(minHeight: 44)253 }254 .buttonStyle(.plain)255 .accessibilityIdentifier("wb.\(preset.id)")256 }257 Text("Tint").font(Instrument.label).foregroundStyle(Instrument.textFaint)258 Slider(value: Binding(get: { model.live.whiteBalanceMode == .locked ? model.wbTint : model.live.tint }, set: { model.setWhiteBalance(tint: $0) }), in: -150...150)259 .frame(width: 130).tint(Instrument.manual)260 .accessibilityLabel(Text("White balance tint"))261 }262 }263 }264265 @ViewBuilder private var zoomDial: some View {266 if let caps = model.capabilities {267 let count = Int(((caps.maxZoom - caps.minZoom) * 10).rounded()) + 1268 HStack {269 PillButton(title: "1×", isOn: model.live.zoom < 1.01) { model.setZoom(1); model.haptic() }.accessibilityLabel(Text("Reset zoom"))270 RulerDial(count: count, index: Binding(get: { Int(((model.zoom - caps.minZoom) * 10).rounded()) }, set: { model.setZoom(caps.minZoom + Double($0) / 10) }),271 majorEvery: 10, label: { String(format: "%.0f×", caps.minZoom + Double($0) / 10) }, accessibilityName: "Zoom", haptics: false)272 }273 Text("Digital zoom: a crop of this lens. Pick another lens for optical magnification.")274 .font(.caption2).foregroundStyle(Instrument.textFaint).frame(maxWidth: .infinity, alignment: .leading)275 }276 }277}278