-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMidiInputChannel.cs
66 lines (64 loc) · 1.75 KB
/
MidiInputChannel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using org.dmxc.lumos.Kernel.Input;
using System;
namespace MidiPlugin
{
public abstract class MidiInputChannel : AbstractInputChannel
{
protected DeviceRule rule;
public MidiInputChannel(IInputLayer parent, DeviceRule rule, bool registerValueChange = true, bool registerFB = true) : base(rule.GUID, parent)
{
base.AutofireChangedEvent = true;
rule.NameChanged += new EventHandler(this.HandleNameChanged);
base.Name = rule.Name;
if (registerValueChange)
{
rule.ValueChanged += new EventHandler<ValueChangedEventArgs>(this.HandleValueChanged);
}
if (registerFB)
{
this.FeedbackCB = new InputLayerChangedCallback(this.HandleFeedback);
}
this.rule = rule;
this.Changed += HandleChanged;
}
protected virtual void HandleChanged(IInputChannel sender, object newValue)
{
if(newValue is double)
{
this.rule.Value = (double)newValue;
}
}
protected virtual void HandleNameChanged(object s, EventArgs e)
{
base.Name = this.rule.Name;
}
protected virtual void HandleValueChanged(object sender, ValueChangedEventArgs e)
{
if(!bBacktrack)
this.ChannelValue = e.newValue;
}
protected virtual bool HandleFeedback(InputChannelID id, object newValue)
{
bool result;
if (newValue is double)
{
this.rule.Value = (double)newValue;
result = true;
}
else
{
result = false;
}
return result;
}
public void UpdateBacktrackValue(double val)
{
this.AutofireChangedEvent = false;
bBacktrack = true;
this.rule.Value = val;
bBacktrack = false;
this.AutofireChangedEvent = true;
}
private bool bBacktrack = false;
}
}