From 491fbc64ce8440dec6fe7e020d92ee107981b162 Mon Sep 17 00:00:00 2001 From: Diyan Date: Tue, 14 Nov 2023 23:36:14 +0200 Subject: [PATCH] add drum tones to mighty lite mk2 --- .../LiteMk2Settings.dart | 1 - lib/UI/pages/drum_editor/drumEditor.dart | 25 +++++++-------- .../drum_editor/drum_eq_bottom_sheet.dart | 11 +++---- .../drum_editor/drumstyle_scroll_picker.dart | 4 +-- lib/bluetooth/NuxDeviceControl.dart | 4 ++- lib/bluetooth/devices/NuxDevice.dart | 1 - lib/bluetooth/devices/NuxMightyLiteMk2.dart | 32 +++++++++++++++++-- lib/bluetooth/devices/NuxMightyPlugPro.dart | 18 +++++------ .../communication/plugProCommunication.dart | 9 +++--- lib/bluetooth/devices/features/drumsTone.dart | 9 ++++++ 10 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 lib/bluetooth/devices/features/drumsTone.dart diff --git a/lib/UI/pages/device_specific_settings/LiteMk2Settings.dart b/lib/UI/pages/device_specific_settings/LiteMk2Settings.dart index 4165683e..02fd674d 100644 --- a/lib/UI/pages/device_specific_settings/LiteMk2Settings.dart +++ b/lib/UI/pages/device_specific_settings/LiteMk2Settings.dart @@ -5,7 +5,6 @@ import '../../../bluetooth/bleMidiHandler.dart'; import '../../../bluetooth/devices/NuxDevice.dart'; import '../../popups/alertDialogs.dart'; import 'PlugProUsbSettings.dart'; -import 'eq/PlugProEQSettings.dart'; class LiteMk2Settings extends StatefulWidget { final NuxDevice device; diff --git a/lib/UI/pages/drum_editor/drumEditor.dart b/lib/UI/pages/drum_editor/drumEditor.dart index c75f69f6..c89a2399 100644 --- a/lib/UI/pages/drum_editor/drumEditor.dart +++ b/lib/UI/pages/drum_editor/drumEditor.dart @@ -8,7 +8,7 @@ import 'package:mighty_plug_manager/UI/pages/drum_editor/tap_buttons.dart'; import 'package:mighty_plug_manager/UI/widgets/circular_button.dart'; import 'package:mighty_plug_manager/UI/widgets/common/modeControlRegular.dart'; import 'package:mighty_plug_manager/UI/pages/drum_editor/tempoTrainerSheet.dart'; -import 'package:mighty_plug_manager/bluetooth/devices/NuxMightyPlugPro.dart'; +import 'package:mighty_plug_manager/bluetooth/devices/features/drumsTone.dart'; import '../../../bluetooth/devices/NuxDevice.dart'; import '../../../bluetooth/NuxDeviceControl.dart'; import '../../../bluetooth/devices/features/looper.dart'; @@ -16,7 +16,7 @@ import '../../../modules/tempo_trainer.dart'; import '../../widgets/thickSlider.dart'; import 'looperPage.dart'; -enum DrumEditorLayout { Standard, PlugPro } +enum DrumEditorLayout { standard, extendedToneControls } enum DrumEditorMode { regular, trainer, looper } @@ -31,7 +31,7 @@ class DrumEditor extends StatefulWidget { class _DrumEditorState extends State with AutomaticKeepAliveClientMixin { late dynamic _drumStyles; - DrumEditorLayout _layout = DrumEditorLayout.Standard; + DrumEditorLayout _layout = DrumEditorLayout.standard; DrumEditorMode _mode = DrumEditorMode.regular; int _selectedDrumPattern = 0; late NuxDevice device; @@ -195,8 +195,8 @@ class _DrumEditorState extends State } List _toneSliders(bool small) { - if (!device.drumToneControls) return []; - var dev = device as NuxMightyPlugPro; + if (device is! DrumsTone) return []; + var dev = device as DrumsTone; return [ ThickSlider( min: 0, @@ -208,7 +208,7 @@ class _DrumEditorState extends State value: dev.drumsBass, labelFormatter: (val) => "${dev.drumsBass.round()} %", onChanged: (val, skip) { - dev.setDrumsTone(val, DrumsToneControl.Bass, !skip); + dev.setDrumsTone(val, DrumsToneControl.bass, !skip); setState(() {}); }, ), @@ -222,7 +222,7 @@ class _DrumEditorState extends State value: dev.drumsMiddle, labelFormatter: (val) => "${dev.drumsMiddle.round()} %", onChanged: (val, skip) { - dev.setDrumsTone(val, DrumsToneControl.Middle, !skip); + dev.setDrumsTone(val, DrumsToneControl.middle, !skip); setState(() {}); }, ), @@ -236,7 +236,7 @@ class _DrumEditorState extends State value: dev.drumsTreble, labelFormatter: (val) => "${dev.drumsTreble.round()} %", onChanged: (val, skip) { - dev.setDrumsTone(val, DrumsToneControl.Treble, !skip); + dev.setDrumsTone(val, DrumsToneControl.treble, !skip); setState(() {}); }, ) @@ -268,8 +268,8 @@ class _DrumEditorState extends State final bool hasLooper = device is Looper; final bool looperEnabled = hasLooper && (device as Looper).loopState != 0; _layout = _drumStyles is List - ? DrumEditorLayout.Standard - : DrumEditorLayout.PlugPro; + ? DrumEditorLayout.standard + : DrumEditorLayout.extendedToneControls; _selectedDrumPattern = device.selectedDrumStyle; @@ -304,8 +304,7 @@ class _DrumEditorState extends State _tempoSlider(smallControls, false), if (_mode == DrumEditorMode.regular) _tapButton(smallControls), - if (_mode == DrumEditorMode.regular && - device.drumToneControls) + if (_mode == DrumEditorMode.regular && device is DrumsTone) ..._toneSliders(smallControls), if (_mode == DrumEditorMode.trainer) TempoTrainerSheet( @@ -348,7 +347,7 @@ class _DrumEditorState extends State child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - if (device.drumToneControls) + if (device is DrumsTone) CircularButton( icon: Icons.equalizer, backgroundColor: Colors.blue, diff --git a/lib/UI/pages/drum_editor/drum_eq_bottom_sheet.dart b/lib/UI/pages/drum_editor/drum_eq_bottom_sheet.dart index b165df3b..d9704bde 100644 --- a/lib/UI/pages/drum_editor/drum_eq_bottom_sheet.dart +++ b/lib/UI/pages/drum_editor/drum_eq_bottom_sheet.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mighty_plug_manager/bluetooth/NuxDeviceControl.dart'; - -import '../../../bluetooth/devices/NuxMightyPlugPro.dart'; +import '../../../bluetooth/devices/features/drumsTone.dart'; import '../../widgets/thickSlider.dart'; class DrumEQBottomSheet extends StatefulWidget { @@ -14,7 +13,7 @@ class DrumEQBottomSheet extends StatefulWidget { class _DrumEQBottomSheetState extends State { @override Widget build(BuildContext context) { - var dev = NuxDeviceControl.instance().device as NuxMightyPlugPro; + var dev = NuxDeviceControl.instance().device as DrumsTone; return Column( mainAxisSize: MainAxisSize.min, children: [ @@ -29,7 +28,7 @@ class _DrumEQBottomSheetState extends State { handleVerticalDrag: false, labelFormatter: (val) => "${dev.drumsBass.round()} %", onChanged: (val, skip) { - dev.setDrumsTone(val, DrumsToneControl.Bass, !skip); + dev.setDrumsTone(val, DrumsToneControl.bass, !skip); setState(() {}); }, ), @@ -44,7 +43,7 @@ class _DrumEQBottomSheetState extends State { handleVerticalDrag: false, labelFormatter: (val) => "${dev.drumsMiddle.round()} %", onChanged: (val, skip) { - dev.setDrumsTone(val, DrumsToneControl.Middle, !skip); + dev.setDrumsTone(val, DrumsToneControl.middle, !skip); setState(() {}); }, ), @@ -59,7 +58,7 @@ class _DrumEQBottomSheetState extends State { handleVerticalDrag: false, labelFormatter: (val) => "${dev.drumsTreble.round()} %", onChanged: (val, skip) { - dev.setDrumsTone(val, DrumsToneControl.Treble, !skip); + dev.setDrumsTone(val, DrumsToneControl.treble, !skip); setState(() {}); }, ), diff --git a/lib/UI/pages/drum_editor/drumstyle_scroll_picker.dart b/lib/UI/pages/drum_editor/drumstyle_scroll_picker.dart index 6540986a..1b952164 100644 --- a/lib/UI/pages/drum_editor/drumstyle_scroll_picker.dart +++ b/lib/UI/pages/drum_editor/drumstyle_scroll_picker.dart @@ -48,7 +48,7 @@ class DrumStyleScrollPicker extends StatelessWidget { borderRadius: BorderRadius.circular(5), side: const BorderSide(width: 1, color: Colors.white)), title: Text( - layout == DrumEditorLayout.PlugPro + layout == DrumEditorLayout.extendedToneControls ? _getComplexListStyle(drumStyles) : drumStyles[selectedDrumPattern], style: _fontStyle, @@ -60,7 +60,7 @@ class DrumStyleScrollPicker extends StatelessWidget { builder: (context) { return DrumStyleBottomSheet( styleMap: drumStyles, - mode: layout == DrumEditorLayout.PlugPro + mode: layout == DrumEditorLayout.extendedToneControls ? DrumStyleMode.categorized : DrumStyleMode.flat, selected: selectedDrumPattern, diff --git a/lib/bluetooth/NuxDeviceControl.dart b/lib/bluetooth/NuxDeviceControl.dart index 70749d84..b6f0c7da 100644 --- a/lib/bluetooth/NuxDeviceControl.dart +++ b/lib/bluetooth/NuxDeviceControl.dart @@ -465,7 +465,9 @@ class NuxDeviceControl extends ChangeNotifier { sendFullEffectSettings(i, false); } - device.communication.sendSlotOrder(); + if (device.reorderableFXChain) { + device.communication.sendSlotOrder(); + } } void resetToChannelDefaults() { diff --git a/lib/bluetooth/devices/NuxDevice.dart b/lib/bluetooth/devices/NuxDevice.dart index 462071b9..eca92a19 100644 --- a/lib/bluetooth/devices/NuxDevice.dart +++ b/lib/bluetooth/devices/NuxDevice.dart @@ -200,7 +200,6 @@ abstract class NuxDevice extends ChangeNotifier { //drum stuff double get drumsMinTempo => 40; double get drumsMaxTempo => 240; - bool get drumToneControls => false; bool get drumsEnabled => config.drumsEnabled; int get selectedDrumStyle => config.selectedDrumStyle; double get drumsVolume => config.drumsVolume; diff --git a/lib/bluetooth/devices/NuxMightyLiteMk2.dart b/lib/bluetooth/devices/NuxMightyLiteMk2.dart index fb429cff..e819a9b2 100644 --- a/lib/bluetooth/devices/NuxMightyLiteMk2.dart +++ b/lib/bluetooth/devices/NuxMightyLiteMk2.dart @@ -11,6 +11,7 @@ import 'NuxMightyPlugPro.dart'; import 'communication/liteMk2Communication.dart'; import 'device_data/drumstyles.dart'; import 'device_data/processors_list.dart'; +import 'features/drumsTone.dart'; import 'features/proUsbSettings.dart'; import 'features/tuner.dart'; import 'presets/MightyMk2Preset.dart'; @@ -18,7 +19,8 @@ import 'value_formatters/ValueFormatter.dart'; enum LiteMK2Version { LiteMK2v1 } -class NuxMightyLiteMk2 extends NuxDevice implements Tuner, ProUsbSettings { +class NuxMightyLiteMk2 extends NuxDevice + implements Tuner, ProUsbSettings, DrumsTone { NuxMightyLiteMk2(super.devControl) { //get channel names for (int i = 0; i < channelsCount; i++) { @@ -44,7 +46,7 @@ class NuxMightyLiteMk2 extends NuxDevice implements Tuner, ProUsbSettings { @override int get productVersion => version.index; @override - String get productIconLabel => "LITE MK2|-|8BT MK2"; + String get productIconLabel => "LITE II|-|8BT II"; @override List get productBLENames => ["NUX NGA-3BT"]; @@ -112,6 +114,16 @@ class NuxMightyLiteMk2 extends NuxDevice implements Tuner, ProUsbSettings { @override bool get presetSaveSupport => true; + @override + double get drumsBass => _config.drumsBass; + @override + double get drumsMiddle => _config.drumsMiddle; + @override + double get drumsTreble => _config.drumsTreble; + + @override + double get drumsMaxTempo => 300; + @override List get processorList => ProcessorsList.liteMk2List; final _tunerController = StreamController.broadcast(); @@ -159,6 +171,22 @@ class NuxMightyLiteMk2 extends NuxDevice implements Tuner, ProUsbSettings { return preset; } + @override + void setDrumsTone(double value, DrumsToneControl control, bool send) { + switch (control) { + case DrumsToneControl.bass: + _config.drumsBass = value; + break; + case DrumsToneControl.middle: + _config.drumsMiddle = value; + break; + case DrumsToneControl.treble: + _config.drumsTreble = value; + break; + } + if (send) _communication.setDrumsTone(value, control); + } + @override bool get tunerAvailable { return deviceControl.isConnected; diff --git a/lib/bluetooth/devices/NuxMightyPlugPro.dart b/lib/bluetooth/devices/NuxMightyPlugPro.dart index d2bae73e..7104f40c 100644 --- a/lib/bluetooth/devices/NuxMightyPlugPro.dart +++ b/lib/bluetooth/devices/NuxMightyPlugPro.dart @@ -16,6 +16,7 @@ import 'NuxDevice.dart'; import 'device_data/drumstyles.dart'; import 'effects/Processor.dart'; import 'effects/plug_pro/EQ.dart'; +import 'features/drumsTone.dart'; import 'features/looper.dart'; import 'features/proUsbSettings.dart'; import 'features/tuner.dart'; @@ -26,8 +27,6 @@ enum PlugProChannel { Clean, Overdrive, Distortion, AGSim, Pop, Rock, Funk } enum PlugProVersion { PlugPro1 } -enum DrumsToneControl { Bass, Middle, Treble } - class NuxPlugProConfiguration extends NuxDeviceConfiguration { static const bluetoothEQCount = 4; @@ -58,7 +57,7 @@ class NuxPlugProConfiguration extends NuxDeviceConfiguration { } class NuxMightyPlugPro extends NuxReorderableDevice - implements Tuner, ProUsbSettings { + implements Tuner, ProUsbSettings, DrumsTone { @override int get productVID => 48; late final PlugProCommunication _communication = @@ -132,12 +131,12 @@ class NuxMightyPlugPro extends NuxReorderableDevice @override int get deviceQRVersion => 1; + @override double get drumsBass => config.drumsBass; + @override double get drumsMiddle => config.drumsMiddle; - double get drumsTreble => config.drumsTreble; - @override - bool get drumToneControls => true; + double get drumsTreble => config.drumsTreble; @override double get drumsMaxTempo => 300; @@ -247,15 +246,16 @@ class NuxMightyPlugPro extends NuxReorderableDevice return deviceId == deviceQRId && ver == 1; } + @override void setDrumsTone(double value, DrumsToneControl control, bool send) { switch (control) { - case DrumsToneControl.Bass: + case DrumsToneControl.bass: config.drumsBass = value; break; - case DrumsToneControl.Middle: + case DrumsToneControl.middle: config.drumsMiddle = value; break; - case DrumsToneControl.Treble: + case DrumsToneControl.treble: config.drumsTreble = value; break; } diff --git a/lib/bluetooth/devices/communication/plugProCommunication.dart b/lib/bluetooth/devices/communication/plugProCommunication.dart index bf100600..994dc1ea 100644 --- a/lib/bluetooth/devices/communication/plugProCommunication.dart +++ b/lib/bluetooth/devices/communication/plugProCommunication.dart @@ -7,6 +7,7 @@ import '../NuxDevice.dart'; import '../NuxFXID.dart'; import '../NuxMightySpace.dart'; import '../effects/plug_pro/Cabinet.dart'; +import '../features/drumsTone.dart'; import '../features/tuner.dart'; import '../presets/PlugProPreset.dart'; @@ -280,13 +281,13 @@ class PlugProCommunication extends DeviceCommunication { if (!device.deviceControl.isConnected) return; int cc = 0; switch (control) { - case DrumsToneControl.Bass: + case DrumsToneControl.bass: cc = MidiCCValuesPro.DRUM_BASS; break; - case DrumsToneControl.Middle: + case DrumsToneControl.middle: cc = MidiCCValuesPro.DRUM_MIDDLE; break; - case DrumsToneControl.Treble: + case DrumsToneControl.treble: cc = MidiCCValuesPro.DRUM_TREBLE; break; } @@ -749,7 +750,7 @@ class PlugProCommunication extends DeviceCommunication { config.tunerData.mode = TunerMode.getByMode(data[2]) ?? TunerMode.chromatic; config.tunerData.referencePitch = data[3]; config.tunerData.muted = data[4] == 1; - (device as NuxMightyPlugPro).notifyTunerListeners(); + (device as Tuner).notifyTunerListeners(); } //Info: in plugProDataObject.js in the beginning there are few const enums diff --git a/lib/bluetooth/devices/features/drumsTone.dart b/lib/bluetooth/devices/features/drumsTone.dart new file mode 100644 index 00000000..1000715d --- /dev/null +++ b/lib/bluetooth/devices/features/drumsTone.dart @@ -0,0 +1,9 @@ +enum DrumsToneControl { bass, middle, treble } + +abstract class DrumsTone { + double get drumsBass; + double get drumsMiddle; + double get drumsTreble; + + void setDrumsTone(double value, DrumsToneControl control, bool send); +}