From 46af4cdec4d881a80ce13f5316815e6183659a48 Mon Sep 17 00:00:00 2001 From: Simon G Date: Wed, 14 Apr 2021 10:23:49 +0200 Subject: [PATCH] - add more information to model - rename allocate to map --- Lib.Audio/Channel.cs | 2 +- Lib.Audio/Interfaces/IChannel.cs | 2 +- Mystify/MainModel.cs | 12 ++++++- Mystify/ViewModels/MainWindowViewModel.cs | 40 ++++++++++++++++++----- Mystify/Views/MainWindow.axaml | 2 +- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Lib.Audio/Channel.cs b/Lib.Audio/Channel.cs index f33af90..a58fed9 100644 --- a/Lib.Audio/Channel.cs +++ b/Lib.Audio/Channel.cs @@ -50,7 +50,7 @@ namespace Lib.Audio public List? Buttons { get; } public IControllable? Controllable { get; private set; } - public void AllocateControllable(IControllable controllable) => Controllable = controllable; + public void MapControllable(IControllable controllable) => Controllable = controllable; public void HandleMessage(IMidiMessage message) { if (message is NoteOnMessage noteOnMessage) diff --git a/Lib.Audio/Interfaces/IChannel.cs b/Lib.Audio/Interfaces/IChannel.cs index a7dff6f..8a0aa0f 100644 --- a/Lib.Audio/Interfaces/IChannel.cs +++ b/Lib.Audio/Interfaces/IChannel.cs @@ -18,7 +18,7 @@ namespace Lib.Audio.Interfaces IControllable? Controllable { get; } - void AllocateControllable(IControllable controllable); + void MapControllable(IControllable controllable); void HandleMessage(IMidiMessage message); void SendAcknowledge(IMidiCommunication midiCommunication); } diff --git a/Mystify/MainModel.cs b/Mystify/MainModel.cs index df4e1df..fdc0ff2 100644 --- a/Mystify/MainModel.cs +++ b/Mystify/MainModel.cs @@ -27,9 +27,13 @@ namespace Mystify _controllableCollectorFactory = controllableCollectorFactory; } + public string? DeviceName => _device?.Name; public List? Channels => _device?.Channels; public List? Controllables => _controllableCollector?.Controllables; - public string? DeviceName => _device?.Name; + public IChannel? SelectedChannel { get; set; } + public IControllable? SelectedControllable { get; set; } + + public bool UseMidiView { get; set; } public void LoadDriverAndDevice(string driverPath, bool useMidiView) { @@ -43,5 +47,11 @@ namespace Mystify _device.StartCommunication(useMidiView); } + + public void MapControllable() + { + if (SelectedControllable != null) + SelectedChannel?.MapControllable(SelectedControllable); + } } } \ No newline at end of file diff --git a/Mystify/ViewModels/MainWindowViewModel.cs b/Mystify/ViewModels/MainWindowViewModel.cs index df8cf8c..bb251c5 100644 --- a/Mystify/ViewModels/MainWindowViewModel.cs +++ b/Mystify/ViewModels/MainWindowViewModel.cs @@ -32,10 +32,36 @@ namespace Mystify.ViewModels public List? Channels => _mainModel?.Channels; public List? Controllables => _mainModel?.Controllables; - - public IChannel? SelectedChannel { get; set; } - public IControllable? SelectedControllable { get; set; } - public bool UseMidiView { get; set; } + + public IChannel? SelectedChannel + { + get => _mainModel?.SelectedChannel; + set + { + if (_mainModel != null) + _mainModel.SelectedChannel = value; + } + } + + public IControllable? SelectedControllable + { + get => _mainModel?.SelectedControllable; + set + { + if (_mainModel != null) + _mainModel.SelectedControllable = value; + } + } + + public bool UseMidiView + { + get => _mainModel is {UseMidiView: true}; + set + { + if (_mainModel != null) + _mainModel.UseMidiView = value; + } + } public string SelectedDeviceText => $"Selected Device: {_mainModel?.DeviceName ?? "-"}"; @@ -55,11 +81,7 @@ namespace Mystify.ViewModels RaisePropertyChanged(() => Controllables); }); - public ICommand AllocateControllableCommand => ReactiveCommand.Create(() => - { - if (SelectedControllable != null) - SelectedChannel?.AllocateControllable(SelectedControllable); - }); + public ICommand MapControllableCommand => ReactiveCommand.Create(() => _mainModel?.MapControllable()); public void UpdateChannelsAndControllables() { diff --git a/Mystify/Views/MainWindow.axaml b/Mystify/Views/MainWindow.axaml index 25710d9..3badd02 100644 --- a/Mystify/Views/MainWindow.axaml +++ b/Mystify/Views/MainWindow.axaml @@ -35,6 +35,6 @@ Margin="5"/> -