2021-02-19 16:42:37 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MassiveKnob.Hardware
|
|
|
|
|
{
|
|
|
|
|
public abstract class AbstractMassiveKnobHardware : IMassiveKnobHardware
|
|
|
|
|
{
|
|
|
|
|
protected ObserverProxy Observers = new ObserverProxy();
|
|
|
|
|
|
|
|
|
|
public void AttachObserver(IMassiveKnobHardwareObserver observer)
|
|
|
|
|
{
|
|
|
|
|
Observers.AttachObserver(observer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DetachObserver(IMassiveKnobHardwareObserver observer)
|
|
|
|
|
{
|
|
|
|
|
Observers.DetachObserver(observer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract Task TryConnect();
|
|
|
|
|
public abstract Task Disconnect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ObserverProxy : IMassiveKnobHardwareObserver
|
|
|
|
|
{
|
|
|
|
|
private readonly List<IMassiveKnobHardwareObserver> observers = new List<IMassiveKnobHardwareObserver>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void AttachObserver(IMassiveKnobHardwareObserver observer)
|
|
|
|
|
{
|
|
|
|
|
observers.Add(observer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DetachObserver(IMassiveKnobHardwareObserver observer)
|
|
|
|
|
{
|
|
|
|
|
observers.Remove(observer);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-20 11:16:18 +00:00
|
|
|
|
|
|
|
|
|
public void Connecting()
|
|
|
|
|
{
|
|
|
|
|
foreach (var observer in observers)
|
|
|
|
|
observer.Connecting();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-02-19 16:42:37 +00:00
|
|
|
|
public void Connected(int knobCount)
|
|
|
|
|
{
|
|
|
|
|
foreach (var observer in observers)
|
|
|
|
|
observer.Connected(knobCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Disconnected()
|
|
|
|
|
{
|
|
|
|
|
foreach (var observer in observers)
|
|
|
|
|
observer.Disconnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void VolumeChanged(int knob, int volume)
|
|
|
|
|
{
|
|
|
|
|
foreach (var observer in observers)
|
|
|
|
|
observer.VolumeChanged(knob, volume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|