I Use Wpf.
I parse a midi file and use midioutshortmsg to send message in a For Loop,
and sleep for delay Delta Time;
My playback is lagging ,But, when i open other midi software at the same time
(include WindowMediaPlayer) ,All the Problem is sloved,My Program work fine.
When I close the other opened software.Problem is come back.
My program stuck in here.
I have already try send in midistreamout,MidiOutProc,or midioutlongmsg,etc.but my problem still can't solve.
What I have tried:
Some Code Here:
[DllImport("winmm.dll")]
private extern static int midiOutOpen(out int lphMidiOut, int uDeviceID, int dwCallback, int dwInstance, int dwFlags);
[DllImport("winmm.dll")]
public extern static int midiOutShortMsg(int lphMidiOut, int dwMsg);
public int midiOut;
private void Play_Click(object sender, RoutedEventArgs e)
{
midiOutOpen(out midiOut, 0, 0, 0, 0);
InstanceCaller = new Thread(new ThreadStart(SendMessage));
InstanceCaller.Start();
}
private void SendMessage()
{
for (int i = 0; i < melodyList.Count; i++)
{
var messgae = Convert.ToInt32(melodyList[i], 16);
midiOutShortMsg(midiOut, messgae);
Thread.Sleep(Convert.ToInt32(durationList[i]));
}
}