-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMidiCCAction.cs
36 lines (32 loc) · 1.17 KB
/
MidiCCAction.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
using System.Threading.Tasks;
using RtMidi.Core.Enums;
using RtMidi.Core.Messages;
using Serilog;
using StreamDeckLib;
using StreamDeckLib.Messages;
using StreamDeckMidiPlugin2.Models;
namespace StreamDeckMidiPlugin2
{
[ActionUuid(Uuid = "com.sorskoot.midicc.action")]
public class MidiCCAction : BaseMidiAction<MidiCCModel>
{
public override Task OnKeyDown(StreamDeckEventPayload args)
{
Log.Information("OnKeyDown");
this.MidiCC(this.SettingsModel.Channel, this.SettingsModel.Control, this.SettingsModel.Value);
return Task.CompletedTask;
}
public void MidiCC(int channel, int control, int value)
{
var midiChannel = (Channel)(channel - 1);
if (MidiDevice.OutputDevices[this.GetSelectedDeviceName(this.SettingsModel.SelectedDevice)].IsOpen)
{
MidiDevice.OutputDevices[this.GetSelectedDeviceName(this.SettingsModel.SelectedDevice)].Send(new ControlChangeMessage(midiChannel, control, value));
}
else
{
Log.Warning("midi output device not connected");
}
}
}
}