Skip to content

Commit

Permalink
MIDI入力が死んでいた問題の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Ojii committed Dec 6, 2024
1 parent bec97ac commit 9c0d395
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions FDK19/src/02.Input/CInputMIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ public class CInputMIDI : IInputDevice, IDisposable

// コンストラクタ

public CInputMIDI(uint nID)
public CInputMIDI(int nID, string GUID)
{
this.hMidiIn = IntPtr.Zero;
this.listEventBuffer = new ConcurrentQueue<STInputEvent>();
this.listInputEvents = new List<STInputEvent>();
this.eInputDeviceType = EInputDeviceType.MidiIn;
this.GUID = "";
this.ID = (int)nID;
this.GUID = GUID;
this.ID = nID;
this.strDeviceName = ""; // CInputManagerで初期化する
}

// メソッド

public unsafe void tメッセージからMIDI信号のみ受信(int dev, long time, byte[] buf, int count)
public unsafe void tメッセージからMIDI信号のみ受信(string dev, long time, byte[] buf, int count)
{
if (this.ID == dev)
if (this.GUID == dev)
{
int nMIDIevent = buf[count * 3];
int nPara1 = buf[count * 3 + 1];
int nPara2 = buf[count * 3 + 2];

if ((nMIDIevent == 0x90) && (nPara2 != 0)) // Note ON
if ((nMIDIevent >= 0x90) && (nMIDIevent <= 0x9f) && (nPara2 != 0)) // Note ON
{
STInputEvent item = new STInputEvent()
{
Expand Down
10 changes: 7 additions & 3 deletions FDK19/src/02.Input/CInputManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Commons.Music.Midi;
using CoreMidi;

namespace FDK;

Expand Down Expand Up @@ -52,7 +53,7 @@ public CInputManager()
var midiintmp = MidiAccessManager.Default.OpenInputAsync(midiinlisttmp[i].Id).Result;
midiintmp.MessageReceived += onMessageRecevied;
this.midiInputs.Add(midiintmp);
CInputMIDI item = new CInputMIDI(uint.Parse(midiinlisttmp[i].Id));
CInputMIDI item = new CInputMIDI(i, midiinlisttmp[i].Id);
this.listInputDevices.Add(item);
}
}
Expand Down Expand Up @@ -198,16 +199,19 @@ private void onMessageRecevied(object? sender, MidiReceivedEventArgs? e)
if (CSoundManager.rc演奏用タイマ is not null)
time = CSoundManager.rc演奏用タイマ.nシステム時刻ms; // lock前に取得。演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。

int dev = int.Parse(((IMidiInput)sender).Details.Id);
string dev = ((IMidiInput)sender).Details.Id;

lock (this.objMidiIn排他用)
{
if ((this.listInputDevices is not null) && (this.listInputDevices.Count != 0))
{
foreach (IInputDevice device in this.listInputDevices)
{
if (device.eInputDeviceType != EInputDeviceType.MidiIn)
continue;

CInputMIDI tmidi = (CInputMIDI)device;
if ((tmidi is not null) && (tmidi.ID == dev))
if ((tmidi is not null) && (tmidi.GUID == dev))
{
for (int i = 0; i < e.Length / 3; i++)
tmidi.tメッセージからMIDI信号のみ受信(dev, time, e.Data, i);
Expand Down

0 comments on commit 9c0d395

Please sign in to comment.