72 lines
2.0 KiB
Dart
72 lines
2.0 KiB
Dart
/// Modelo de preset de ecualizador.
|
|
/// 5 bandas: 60Hz, 250Hz, 1kHz, 4kHz, 16kHz
|
|
class PresetEcualizador {
|
|
final String nombre;
|
|
final List<double> bandas; // 5 valores entre -12.0 y +12.0 dB
|
|
|
|
const PresetEcualizador({required this.nombre, required this.bandas})
|
|
: assert(bandas.length == 5);
|
|
|
|
static final flat = PresetEcualizador(
|
|
nombre: 'Flat',
|
|
bandas: [0.0, 0.0, 0.0, 0.0, 0.0],
|
|
);
|
|
static final rock = PresetEcualizador(
|
|
nombre: 'Rock',
|
|
bandas: [2.0, 1.0, -1.0, 2.0, 3.0],
|
|
);
|
|
static final pop = PresetEcualizador(
|
|
nombre: 'Pop',
|
|
bandas: [1.0, 1.5, 0.5, 1.0, 1.5],
|
|
);
|
|
static final bassBoost = PresetEcualizador(
|
|
nombre: 'Bass Boost',
|
|
bandas: [5.0, 3.0, -1.0, 0.5, 0.0],
|
|
);
|
|
static final jazz = PresetEcualizador(
|
|
nombre: 'Jazz',
|
|
bandas: [3.0, -1.0, -1.5, 2.0, 4.0],
|
|
);
|
|
static final voz = PresetEcualizador(
|
|
nombre: 'Voz',
|
|
bandas: [-2.0, -1.0, 2.0, 3.0, 1.0],
|
|
);
|
|
|
|
static final presets = [flat, rock, pop, bassBoost, jazz, voz];
|
|
|
|
factory PresetEcualizador.desdeJson(Map<String, dynamic> json) {
|
|
final raw =
|
|
(json['bandas'] as List?)?.map((e) => (e as num).toDouble()).toList() ??
|
|
<double>[];
|
|
final bandas = List<double>.generate(
|
|
5,
|
|
(i) => i < raw.length ? raw[i] : 0.0,
|
|
);
|
|
return PresetEcualizador(
|
|
nombre: json['nombre'] as String? ?? 'Personalizado',
|
|
bandas: bandas,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {'nombre': nombre, 'bandas': bandas};
|
|
|
|
PresetEcualizador copyWithBandas(List<double> bandas) =>
|
|
PresetEcualizador(nombre: 'Personalizado', bandas: bandas);
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) return true;
|
|
if (other is! PresetEcualizador) return false;
|
|
if (nombre != other.nombre || bandas.length != other.bandas.length) {
|
|
return false;
|
|
}
|
|
for (int i = 0; i < bandas.length; i++) {
|
|
if (bandas[i] != other.bandas[i]) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => Object.hash(nombre, Object.hashAll(bandas));
|
|
}
|