✨ Implement port connection dialog
Implements: - Viewing connections (routes) - Creating and deleting connections - Changing volume of connectons - Muting / unmuting connections
This commit is contained in:
@ -1,13 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gomix_flutter/mixer_state.dart' as mixer;
|
||||
import 'package:gomix_flutter/port_connection_dialog.dart';
|
||||
import 'package:gomix_flutter/utils.dart';
|
||||
|
||||
class MixingCard extends StatefulWidget {
|
||||
final mixer.Port port;
|
||||
final Function sendAction;
|
||||
final mixer.MixerState mixerState;
|
||||
final Function(Map<String, Object> data) sendAction;
|
||||
final bool isOutput;
|
||||
const MixingCard(
|
||||
{super.key,
|
||||
required this.port,
|
||||
required this.mixerState,
|
||||
required this.sendAction,
|
||||
this.isOutput = false});
|
||||
|
||||
@ -15,20 +19,55 @@ class MixingCard extends StatefulWidget {
|
||||
State<MixingCard> createState() => _MixingCardState();
|
||||
}
|
||||
|
||||
class DialogDataModel extends ChangeNotifier {
|
||||
String? portUUID;
|
||||
|
||||
late mixer.MixerState mixerState;
|
||||
late mixer.Port port;
|
||||
|
||||
void updatePort(bool force) {
|
||||
if (portUUID == null) {
|
||||
return;
|
||||
}
|
||||
// Only update port reference if it is actually outdated
|
||||
if (force ||
|
||||
(!mixerState.inputs.contains(port) &&
|
||||
!mixerState.outputs.contains(port))) {
|
||||
mixer.Port? newPort = findPort(mixerState, portUUID!);
|
||||
if (newPort != null) port = newPort;
|
||||
}
|
||||
}
|
||||
|
||||
void setPortUUID(String uuid) {
|
||||
portUUID = uuid;
|
||||
updatePort(true);
|
||||
}
|
||||
|
||||
void setMixerState(mixer.MixerState state) {
|
||||
mixerState = state;
|
||||
updatePort(false);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class _MixingCardState extends State<MixingCard> {
|
||||
double _sliderValue = 0;
|
||||
int _debounceTimer = 0;
|
||||
bool _sliderActive = false;
|
||||
|
||||
DialogDataModel dataModel = DialogDataModel();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
dataModel.setMixerState(widget.mixerState);
|
||||
_sliderValue = widget.port.state.volume;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(MixingCard oldWidget) {
|
||||
if (_sliderActive) return;
|
||||
dataModel.setMixerState(widget.mixerState);
|
||||
_sliderValue = widget.port.state.volume;
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
@ -78,7 +117,16 @@ class _MixingCardState extends State<MixingCard> {
|
||||
child: IconButton.outlined(
|
||||
iconSize: 20,
|
||||
isSelected: false,
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
dataModel.setPortUUID(widget.port.uuid);
|
||||
PortConnectionDialog(
|
||||
sendAction: widget.sendAction,
|
||||
port: widget.port,
|
||||
isOutput: widget.isOutput,
|
||||
dataModel: dataModel,
|
||||
mixerState: widget.mixerState)
|
||||
.show(context);
|
||||
},
|
||||
icon: const Icon(Icons.unfold_more)))
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user