public MidiControlAdaptor(MidiControlType controlType, int controlId, Field field, FsConnection fsConnection) { ControlType = controlType; ControlId = controlId; Field = field; FsConnection = fsConnection; UnitType = FsConnection.FieldDefinition(field).UnitType; FsConnection.Subscribe(field).Subscribe(p => HandleValueChange(p)); // TODO: Make sure the lights are initialised }
public MainWindow() { InitializeComponent(); handle = new WindowInteropHelper(this).EnsureHandle(); // Get handle of main WPF Window handleSource = HwndSource.FromHwnd(handle); // Get source of handle in order to add event handlers to it handleSource.AddHook(HandleSimConnectEvents); fsConnection = new FsConnection(handle); midiConnection = new MidiConnection(); SetupControls(); }
public void HandleEvent(MidiEvent evt) { Console.WriteLine($"Got event: {evt.EventType}"); switch (evt.EventType) { case MidiEventType.PitchBend: var pitchBend = (PitchBendEvent)evt; var value = MidiUnitConverter.ConvertFromPitch(UnitType, pitchBend.PitchValue); Console.WriteLine($"Pitch bend value: {pitchBend.PitchValue} -> {value}"); FsConnection.SetValue(Field, value); break; case MidiEventType.ControlChange: // TODO: How to control the sensitivity? var cc = (ControlChangeEvent)evt; var sensitivity = encoderSensitivity[UnitType]; var ccValue = FsConnection.GetValue(Field) + MidiUnitConverter.ConvertFromControlChange(UnitType, cc.ControlValue) * sensitivity; Console.WriteLine($"ccValue: {ccValue}"); FsConnection.SetValue(Field, ccValue); break; } }
public MidiControlAdaptor CreateAdaptor(MidiControlType controlType, int controlId, Field field, FsConnection fsConnection) { var adaptor = new MidiControlAdaptor(controlType, controlId, field, fsConnection); controlAdaptors.Add(adaptor); adaptor.LightControl.Subscribe(HandleLightControl); return(adaptor); }