From 8f90b394a7751d00ecf15789c0d8bf1b576b2bfd Mon Sep 17 00:00:00 2001 From: Simon G Date: Thu, 8 Apr 2021 19:25:57 +0200 Subject: [PATCH] - add channel number --- Lib.Audio/Channel.cs | 8 ++++- Lib.Audio/Factories/IChannelFactory.cs | 2 +- Mystify/App.axaml.cs | 4 ++- Mystify/ViewModels/MainWindowViewModel.cs | 36 +++++++++++++++++++++++ Mystify/Views/MainWindow.axaml | 22 ++++++++++++-- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/Lib.Audio/Channel.cs b/Lib.Audio/Channel.cs index ad91bde..3fbef69 100644 --- a/Lib.Audio/Channel.cs +++ b/Lib.Audio/Channel.cs @@ -13,11 +13,15 @@ namespace Lib.Audio { public class Channel : IChannel { - public Channel(IDeviceButtonConfiguration buttonConfiguration, + private readonly uint _channelNumber; + + public Channel(uint channelNumber, + IDeviceButtonConfiguration buttonConfiguration, IFaderFactory faderFactory, IKnobFactory knobFactory, IButtonFactory buttonFactory) { + _channelNumber = channelNumber; Fader = faderFactory.Create(); Knob = knobFactory.Create(); Buttons = InitializeButtons(buttonConfiguration, buttonFactory); @@ -43,5 +47,7 @@ namespace Lib.Audio } private void OnFaderPositionChanged(object? sender, float position) => Controllable?.SetVolume(position); + + public override string ToString() => $"Channel {_channelNumber}"; } } \ No newline at end of file diff --git a/Lib.Audio/Factories/IChannelFactory.cs b/Lib.Audio/Factories/IChannelFactory.cs index 802f3c4..feb2cfb 100644 --- a/Lib.Audio/Factories/IChannelFactory.cs +++ b/Lib.Audio/Factories/IChannelFactory.cs @@ -8,6 +8,6 @@ namespace Lib.Audio.Factories { public interface IChannelFactory { - IChannel Create(IDeviceButtonConfiguration deviceButtonConfiguration); + IChannel Create(uint channelNumber, IDeviceButtonConfiguration deviceButtonConfiguration); } } \ No newline at end of file diff --git a/Mystify/App.axaml.cs b/Mystify/App.axaml.cs index 1a7bd91..4f881d5 100644 --- a/Mystify/App.axaml.cs +++ b/Mystify/App.axaml.cs @@ -7,6 +7,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Lib.Audio.Factories; using Lib.NotifyIcon; using LightweightIocContainer.Interfaces; using Mystify.ViewModels; @@ -30,9 +31,10 @@ namespace Mystify Bootstrapper bootstrapper = new(); _kernel = bootstrapper.BootstrapKernel(); + //FixMe _mainWindow = new MainWindow { - DataContext = new MainWindowViewModel() + DataContext = new MainWindowViewModel(_kernel.Resolve(), _kernel.Resolve()) }; if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime) diff --git a/Mystify/ViewModels/MainWindowViewModel.cs b/Mystify/ViewModels/MainWindowViewModel.cs index f332900..5b490b5 100644 --- a/Mystify/ViewModels/MainWindowViewModel.cs +++ b/Mystify/ViewModels/MainWindowViewModel.cs @@ -2,10 +2,46 @@ // Created: 2021-04-06 // Copyright(c) 2021 SimonG. All Rights Reserved. +using System; +using System.Collections.Generic; +using System.Windows.Input; +using Lib.Audio.Factories; +using Lib.Audio.Interfaces; +using ReactiveUI; + namespace Mystify.ViewModels { public class MainWindowViewModel : ViewModelBase { + public MainWindowViewModel() + { + if (!IsInDesignMode) + throw new InvalidOperationException("Constructor is for design time usage only."); + + Channels = new List(); + Controllables = new List(); + } + public MainWindowViewModel(IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory) + { + IDevice device = deviceFactory.Create(); + IControllableCollector controllableCollector = controllableCollectorFactory.Create(); + + Channels = device.Channels; + Controllables = controllableCollector.Controllables; + } + + public List Channels { get; } + public List Controllables { get; } + + public IChannel? SelectedChannel { get; set; } + public IControllable? SelectedControllable { get; set; } + + public ICommand AllocateControllableCommand => + ReactiveCommand.Create(() => + { + if (SelectedControllable != null) + SelectedChannel?.AllocateControllable(SelectedControllable); + }); } } diff --git a/Mystify/Views/MainWindow.axaml b/Mystify/Views/MainWindow.axaml index fbb935e..d79e60f 100644 --- a/Mystify/Views/MainWindow.axaml +++ b/Mystify/Views/MainWindow.axaml @@ -7,12 +7,28 @@ x:Class="Mystify.Views.MainWindow" Icon="/Resources/TestIcon.ico" Title="Mystify" - Background="#FFFFFFFF"> + Background="#FF3F3F3F" + Foreground="#FFF0F0F0"> - - + + + + + + + + + + + +