diff options
author | Scott Murray <scott.murray@konsulko.com> | 2023-12-17 15:48:21 -0500 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2023-12-18 13:28:28 +0000 |
commit | 4ae68f5be11d110f2df10d54377d970921e30a21 (patch) | |
tree | b37b5cb3c6964fbaeaa95edc1edeb44d615912e9 /lib/data/data_providers/audio_notifier.dart | |
parent | dda6c8502a3fa1e50654c4cca934b4b846bbca98 (diff) |
Implement audio settings
Changes:
- Rework KUKSA.val "VAL" gRPC API implementation to separate it
from the vehicle model + notifier, and more easily allow using
it from other notifiers.
- Move volume handling from the vehicle model + notifier to the
audio set for clarity.
- Wire up the new VSS audio signals in the audio notifier. The
"rearFront" variable naming has been changed to "fade" in
several places to match expected terminology.
- Add a balance slider to the audio settings page.
- Change the min/max labels on the fade slider to be Text instead
of Icon's since we do not have the equivalent to use with the
balance slider, and text seems like it'd be what you would want
for any potential future internationalization.
- Rework configuration file to be usable from anywhere via a
RiverPod Provider instead of tied to the vehicle notifier code,
and shifted the background and hybrid animation flags to be handled
with it. This change removes the built-in asset with defaults in
favor of maintaining the defaults for the ICS environment in the
AppConfig and KuksaConfig classes, with a goal of avoiding the need
for using async methods in the config provider.
- Change some notifiers from using StateNotifier to the RiverPod
2.0 Notifier class for improved flexibility. The other notifiers
will be updated in future work.
- Added select's to several ref.watches in the new hybrid animation
code to avoid unnecessary repaints.
- Fix several spelling issues in method and parameter names
across the codebase.
Bug-AGL: SPEC-5001
Change-Id: Iefae417fa870405d659303497d96e519e6b6d1de
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'lib/data/data_providers/audio_notifier.dart')
-rw-r--r-- | lib/data/data_providers/audio_notifier.dart | 129 |
1 files changed, 119 insertions, 10 deletions
diff --git a/lib/data/data_providers/audio_notifier.dart b/lib/data/data_providers/audio_notifier.dart index 1f8c1a9..32ab409 100644 --- a/lib/data/data_providers/audio_notifier.dart +++ b/lib/data/data_providers/audio_notifier.dart @@ -1,22 +1,131 @@ import 'package:flutter_ics_homescreen/export.dart'; +import 'package:protos/protos.dart'; -class AudioNotifier extends StateNotifier<Audio> { - AudioNotifier(super.state); +class AudioNotifier extends Notifier<Audio> { + @override + Audio build() { + return Audio.initial(); + } void resetToDefaults() { - state = state.copyWith(treble: 5.0, bass: 5.0, rearFront: 5.0); + state = state.copyWith(balance: 5.0, fade: 5.0, treble: 5.0, bass: 5.0); + var valClient = ref.read(valClientProvider); + int value = (state.balance * 20).toInt() - 100; + valClient.setInt32( + VSSPath.vehicleMediaBalance, + value, + true, + ); + value = (state.fade * 20).toInt() - 100; + valClient.setInt32( + VSSPath.vehicleMediaFade, + value, + true, + ); + value = (state.treble * 20).toInt() - 100; + valClient.setInt32( + VSSPath.vehicleMediaTreble, + value, + true, + ); + value = (state.bass * 20).toInt() - 100; + valClient.setInt32( + VSSPath.vehicleMediaBass, + value, + true, + ); } - void setTreble(double newVal) { - state = state.copyWith(treble: newVal); + bool handleSignalsUpdate(EntryUpdate update) { + bool handled = true; + switch (update.entry.path) { + case VSSPath.vehicleMediaVolume: + if (update.entry.value.hasUint32()) { + double value = update.entry.value.uint32.toDouble(); + state = state.copyWith(volume: value); + } + break; + case VSSPath.vehicleMediaBalance: + if (update.entry.value.hasInt32()) { + double value = (update.entry.value.int32 + 100) / 20.0; + state = state.copyWith(balance: value); + } + break; + case VSSPath.vehicleMediaFade: + if (update.entry.value.hasInt32()) { + double value = (update.entry.value.int32 + 100) / 20.0; + state = state.copyWith(fade: value); + } + break; + case VSSPath.vehicleMediaTreble: + if (update.entry.value.hasInt32()) { + double value = (update.entry.value.int32 + 100) / 20.0; + state = state.copyWith(treble: value); + } + break; + case VSSPath.vehicleMediaBass: + if (update.entry.value.hasInt32()) { + double value = (update.entry.value.int32 + 100) / 20.0; + state = state.copyWith(bass: value); + } + break; + default: + handled = false; + } + return handled; } - void setBass(double newVal) { - state = state.copyWith(bass: newVal); + void setVolume(double newValue) { + state = state.copyWith(volume: newValue); + var valClient = ref.read(valClientProvider); + valClient.setUint32( + VSSPath.vehicleMediaVolume, + newValue.toInt(), + true, + ); } - void setRearFront(double newVal) { - state = state.copyWith(rearFront: newVal); + void setBalance(double newValue) { + state = state.copyWith(balance: newValue); + int value = (newValue * 20).toInt() - 100; + var valClient = ref.read(valClientProvider); + valClient.setInt32( + VSSPath.vehicleMediaBalance, + value, + true, + ); + } + + void setFade(double newValue) { + state = state.copyWith(fade: newValue); + int value = (newValue * 20).toInt() - 100; + var valClient = ref.read(valClientProvider); + valClient.setInt32( + VSSPath.vehicleMediaFade, + value, + true, + ); } -} + void setTreble(double newValue) { + state = state.copyWith(treble: newValue); + int value = (newValue * 20).toInt() - 100; + var valClient = ref.read(valClientProvider); + valClient.setInt32( + VSSPath.vehicleMediaTreble, + value, + true, + ); + } + + void setBass(double newValue) { + state = state.copyWith(bass: newValue); + int value = (newValue * 20).toInt() - 100; + var valClient = ref.read(valClientProvider); + valClient.setInt32( + VSSPath.vehicleMediaBass, + value, + true, + ); + } +} |