Skip to content

Commit

Permalink
add drum tones to mighty lite mk2
Browse files Browse the repository at this point in the history
  • Loading branch information
Diyan committed Nov 14, 2023
1 parent cd51913 commit 491fbc6
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 39 deletions.
1 change: 0 additions & 1 deletion lib/UI/pages/device_specific_settings/LiteMk2Settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 12 additions & 13 deletions lib/UI/pages/drum_editor/drumEditor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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';
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 }

Expand All @@ -31,7 +31,7 @@ class DrumEditor extends StatefulWidget {
class _DrumEditorState extends State<DrumEditor>
with AutomaticKeepAliveClientMixin<DrumEditor> {
late dynamic _drumStyles;
DrumEditorLayout _layout = DrumEditorLayout.Standard;
DrumEditorLayout _layout = DrumEditorLayout.standard;
DrumEditorMode _mode = DrumEditorMode.regular;
int _selectedDrumPattern = 0;
late NuxDevice device;
Expand Down Expand Up @@ -195,8 +195,8 @@ class _DrumEditorState extends State<DrumEditor>
}

List<Widget> _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,
Expand All @@ -208,7 +208,7 @@ class _DrumEditorState extends State<DrumEditor>
value: dev.drumsBass,
labelFormatter: (val) => "${dev.drumsBass.round()} %",
onChanged: (val, skip) {
dev.setDrumsTone(val, DrumsToneControl.Bass, !skip);
dev.setDrumsTone(val, DrumsToneControl.bass, !skip);
setState(() {});
},
),
Expand All @@ -222,7 +222,7 @@ class _DrumEditorState extends State<DrumEditor>
value: dev.drumsMiddle,
labelFormatter: (val) => "${dev.drumsMiddle.round()} %",
onChanged: (val, skip) {
dev.setDrumsTone(val, DrumsToneControl.Middle, !skip);
dev.setDrumsTone(val, DrumsToneControl.middle, !skip);
setState(() {});
},
),
Expand All @@ -236,7 +236,7 @@ class _DrumEditorState extends State<DrumEditor>
value: dev.drumsTreble,
labelFormatter: (val) => "${dev.drumsTreble.round()} %",
onChanged: (val, skip) {
dev.setDrumsTone(val, DrumsToneControl.Treble, !skip);
dev.setDrumsTone(val, DrumsToneControl.treble, !skip);
setState(() {});
},
)
Expand Down Expand Up @@ -268,8 +268,8 @@ class _DrumEditorState extends State<DrumEditor>
final bool hasLooper = device is Looper;
final bool looperEnabled = hasLooper && (device as Looper).loopState != 0;
_layout = _drumStyles is List<String>
? DrumEditorLayout.Standard
: DrumEditorLayout.PlugPro;
? DrumEditorLayout.standard
: DrumEditorLayout.extendedToneControls;

_selectedDrumPattern = device.selectedDrumStyle;

Expand Down Expand Up @@ -304,8 +304,7 @@ class _DrumEditorState extends State<DrumEditor>
_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(
Expand Down Expand Up @@ -348,7 +347,7 @@ class _DrumEditorState extends State<DrumEditor>
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (device.drumToneControls)
if (device is DrumsTone)
CircularButton(
icon: Icons.equalizer,
backgroundColor: Colors.blue,
Expand Down
11 changes: 5 additions & 6 deletions lib/UI/pages/drum_editor/drum_eq_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,7 +13,7 @@ class DrumEQBottomSheet extends StatefulWidget {
class _DrumEQBottomSheetState extends State<DrumEQBottomSheet> {
@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: [
Expand All @@ -29,7 +28,7 @@ class _DrumEQBottomSheetState extends State<DrumEQBottomSheet> {
handleVerticalDrag: false,
labelFormatter: (val) => "${dev.drumsBass.round()} %",
onChanged: (val, skip) {
dev.setDrumsTone(val, DrumsToneControl.Bass, !skip);
dev.setDrumsTone(val, DrumsToneControl.bass, !skip);
setState(() {});
},
),
Expand All @@ -44,7 +43,7 @@ class _DrumEQBottomSheetState extends State<DrumEQBottomSheet> {
handleVerticalDrag: false,
labelFormatter: (val) => "${dev.drumsMiddle.round()} %",
onChanged: (val, skip) {
dev.setDrumsTone(val, DrumsToneControl.Middle, !skip);
dev.setDrumsTone(val, DrumsToneControl.middle, !skip);
setState(() {});
},
),
Expand All @@ -59,7 +58,7 @@ class _DrumEQBottomSheetState extends State<DrumEQBottomSheet> {
handleVerticalDrag: false,
labelFormatter: (val) => "${dev.drumsTreble.round()} %",
onChanged: (val, skip) {
dev.setDrumsTone(val, DrumsToneControl.Treble, !skip);
dev.setDrumsTone(val, DrumsToneControl.treble, !skip);
setState(() {});
},
),
Expand Down
4 changes: 2 additions & 2 deletions lib/UI/pages/drum_editor/drumstyle_scroll_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/bluetooth/NuxDeviceControl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ class NuxDeviceControl extends ChangeNotifier {
sendFullEffectSettings(i, false);
}

device.communication.sendSlotOrder();
if (device.reorderableFXChain) {
device.communication.sendSlotOrder();
}
}

void resetToChannelDefaults() {
Expand Down
1 change: 0 additions & 1 deletion lib/bluetooth/devices/NuxDevice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 30 additions & 2 deletions lib/bluetooth/devices/NuxMightyLiteMk2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ 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';
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++) {
Expand All @@ -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<String> get productBLENames => ["NUX NGA-3BT"];

Expand Down Expand Up @@ -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<ProcessorInfo> get processorList => ProcessorsList.liteMk2List;
final _tunerController = StreamController<TunerData>.broadcast();
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions lib/bluetooth/devices/NuxMightyPlugPro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -58,7 +57,7 @@ class NuxPlugProConfiguration extends NuxDeviceConfiguration {
}

class NuxMightyPlugPro extends NuxReorderableDevice<PlugProPreset>
implements Tuner, ProUsbSettings {
implements Tuner, ProUsbSettings, DrumsTone {
@override
int get productVID => 48;
late final PlugProCommunication _communication =
Expand Down Expand Up @@ -132,12 +131,12 @@ class NuxMightyPlugPro extends NuxReorderableDevice<PlugProPreset>
@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;
Expand Down Expand Up @@ -247,15 +246,16 @@ class NuxMightyPlugPro extends NuxReorderableDevice<PlugProPreset>
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;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/bluetooth/devices/communication/plugProCommunication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/bluetooth/devices/features/drumsTone.dart
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 491fbc6

Please sign in to comment.