You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.1 KiB
94 lines
3.1 KiB
// Author: Gockner, Simon
|
|
// Created: 2021-04-06
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows.Input;
|
|
using Avalonia.Controls;
|
|
using Lib.Audio.Interfaces;
|
|
using Lib.Driver;
|
|
using Mystify.Views;
|
|
using ReactiveUI;
|
|
|
|
namespace Mystify.ViewModels
|
|
{
|
|
public class MainWindowViewModel : ViewModelBase
|
|
{
|
|
private readonly MainModel? _mainModel;
|
|
private readonly MainWindow? _mainWindow;
|
|
|
|
public MainWindowViewModel()
|
|
{
|
|
if (!IsInDesignMode)
|
|
throw new InvalidOperationException("Constructor is for design time usage only.");
|
|
}
|
|
|
|
public MainWindowViewModel(MainModel mainModel, MainWindow? mainWindow)
|
|
{
|
|
_mainModel = mainModel;
|
|
_mainWindow = mainWindow;
|
|
}
|
|
|
|
public ObservableCollection<ChannelViewModel>? Channels => _mainModel?.Channels?.Select(c => new ChannelViewModel(c, _mainWindow, _mainModel)).ToObservableCollection();
|
|
public List<IControllable>? Controllables => _mainModel?.Controllables;
|
|
|
|
public ChannelViewModel? SelectedChannel
|
|
{
|
|
get => _mainModel?.SelectedChannel == null ? null : new ChannelViewModel(_mainModel.SelectedChannel, _mainWindow, _mainModel);
|
|
set
|
|
{
|
|
if (_mainModel != null)
|
|
_mainModel.SelectedChannel = value?.Channel;
|
|
}
|
|
}
|
|
|
|
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 ?? "-"}";
|
|
|
|
public ICommand SelectDriverCommand => ReactiveCommand.CreateFromTask(async () =>
|
|
{
|
|
OpenFileDialog openFileDialog = new()
|
|
{
|
|
Filters = new List<FileDialogFilter> {new() {Extensions = new List<string> {DriverLoader.DRIVER_FILE_EXTENSION}, Name = "Mystify Driver"}}
|
|
};
|
|
|
|
string driverPath = (await openFileDialog.ShowAsync(_mainWindow))[0];
|
|
|
|
_mainModel?.LoadDriverAndDevice(driverPath);
|
|
|
|
RaisePropertyChanged(() => SelectedDeviceText);
|
|
RaisePropertyChanged(() => Channels);
|
|
RaisePropertyChanged(() => Controllables);
|
|
});
|
|
|
|
public ICommand MapControllableCommand => ReactiveCommand.Create(() => _mainModel?.MapControllable());
|
|
|
|
public void UpdateChannelsAndControllables()
|
|
{
|
|
RaisePropertyChanged(() => Channels);
|
|
RaisePropertyChanged(() => Controllables);
|
|
}
|
|
}
|
|
}
|
|
|