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.
54 lines
1.9 KiB
54 lines
1.9 KiB
// Author: Gockner, Simon
|
|
// Created: 2021-04-09
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Lib.Audio.Factories;
|
|
using Lib.Audio.Interfaces;
|
|
using Lib.Driver.Factories;
|
|
using Lib.Driver.Interfaces;
|
|
|
|
namespace Mystify
|
|
{
|
|
public class MainModel : IDisposable
|
|
{
|
|
private readonly IDriverLoader _driverLoader;
|
|
private readonly IDeviceFactory _deviceFactory;
|
|
private readonly IControllableCollectorFactory _controllableCollectorFactory;
|
|
|
|
private IDevice? _device;
|
|
private IControllableCollector? _controllableCollector;
|
|
|
|
public MainModel(IDriverLoaderFactory driverLoaderFactory, IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory, IControllableFactory controllableFactory)
|
|
{
|
|
_driverLoader = driverLoaderFactory.Create();
|
|
_deviceFactory = deviceFactory;
|
|
_controllableCollectorFactory = controllableCollectorFactory;
|
|
ControllableFactory = controllableFactory;
|
|
}
|
|
|
|
public string? DeviceName => _device?.Name;
|
|
public List<IChannel>? Channels => _device?.Channels;
|
|
public List<IControllable>? Controllables => _controllableCollector?.Controllables;
|
|
|
|
public bool UseMidiView { get; set; }
|
|
|
|
public IControllableFactory ControllableFactory { get; }
|
|
|
|
public void LoadDriverAndDevice(string driverPath)
|
|
{
|
|
IDriver? driver = _driverLoader.Load(driverPath);
|
|
|
|
if (driver == null)
|
|
throw new Exception("Driver could not be loaded.");
|
|
|
|
_controllableCollector = _controllableCollectorFactory.Create();
|
|
_device = _deviceFactory.Create(driver, _controllableCollector);
|
|
|
|
_device.StartCommunication(UseMidiView);
|
|
}
|
|
|
|
public void Dispose() => _device?.Dispose();
|
|
}
|
|
} |