EQPreset.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Foundation
  2. /// Built-in EQ presets with predefined gain values for 3-band EQ.
  3. /// "Custom" is auto-assigned when slider values don't match any named preset.
  4. enum EQPreset: String, CaseIterable, Identifiable {
  5. case flat
  6. case bassBoost
  7. case bassCut
  8. case loudness
  9. case vocalFocus
  10. case custom
  11. var id: String { rawValue }
  12. /// Human-readable label for the preset picker.
  13. var displayName: String {
  14. switch self {
  15. case .flat: "Flat"
  16. case .bassBoost: "Bass Boost"
  17. case .bassCut: "Bass Cut"
  18. case .loudness: "Loudness"
  19. case .vocalFocus: "Vocal Focus"
  20. case .custom: "Custom"
  21. }
  22. }
  23. /// Gain values (low, mid, high) for each named preset.
  24. /// Returns nil for `.custom` since it has no fixed values.
  25. var gains: (low: Float, mid: Float, high: Float)? {
  26. switch self {
  27. case .flat: (0, 0, 0)
  28. case .bassBoost: (6, 0, 0)
  29. case .bassCut: (-24, 0, 0)
  30. case .loudness: (4, -2, 4)
  31. case .vocalFocus: (-4, 4, -2)
  32. case .custom: nil
  33. }
  34. }
  35. /// Auto-detect which preset matches the given gain values,
  36. /// or return `.custom` if no match.
  37. static func detect(low: Float, mid: Float, high: Float) -> EQPreset {
  38. for preset in Self.allCases where preset != .custom {
  39. guard let gains = preset.gains else { continue }
  40. if gains.low == low && gains.mid == mid && gains.high == high {
  41. return preset
  42. }
  43. }
  44. return .custom
  45. }
  46. }