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.
42 lines
1.2 KiB
42 lines
1.2 KiB
// Author: Gockner, Simon
|
|
// Created: 2021-04-07
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved.
|
|
|
|
using Lib.Audio.Controls.Buttons.Interfaces;
|
|
using Lib.Audio.Interfaces;
|
|
using Lib.Midi.Messages;
|
|
using Lib.Midi.Messages.Interfaces;
|
|
|
|
namespace Lib.Audio.Controls.Buttons
|
|
{
|
|
public class Button : IButton //TODO: Make abstract?
|
|
{
|
|
private readonly int _channelNumber;
|
|
|
|
public Button(int noteNumber, int channelNumber)
|
|
{
|
|
NoteNumber = noteNumber;
|
|
_channelNumber = channelNumber;
|
|
}
|
|
|
|
public int NoteNumber { get; }
|
|
protected bool IsActive { get; private set; }
|
|
|
|
public virtual IMidiMessage? Handle(IControllable? controllable, Velocity velocity)
|
|
{
|
|
if (velocity != Velocity.On)
|
|
return null;
|
|
|
|
IsActive = !IsActive;
|
|
Handle(controllable);
|
|
|
|
return IsActive ? new NoteOnMessage(0, _channelNumber, NoteNumber, (int) Velocity.On, 0)
|
|
: new NoteMessage(0, _channelNumber, NoteNumber, (int) Velocity.Off);
|
|
}
|
|
|
|
protected virtual void Handle(IControllable? controllable)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |