Created
September 6, 2009 16:50
-
-
Save atsushieno/181869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/samples/WebMidiPlayer.cs b/samples/WebMidiPlayer.cs | |
index 2eb8b7c..1ad8293 100644 | |
--- a/samples/WebMidiPlayer.cs | |
+++ b/samples/WebMidiPlayer.cs | |
@@ -1,5 +1,6 @@ | |
using System; | |
using System.ServiceModel; | |
+using System.Threading; | |
namespace Commons.Music.Midi.Player | |
{ | |
@@ -9,22 +10,19 @@ namespace Commons.Music.Midi.Player | |
public WebMidiPlayer (Uri uri, SmfMusic music) | |
: base (music) | |
{ | |
- client = ChannelFactory<IMidiDeviceClient>.CreateChannel (new BasicHttpBinding (), new EndpointAddress (uri)); | |
+ client = new ChannelFactory<IMidiDeviceClient> (new BasicHttpBinding (), new EndpointAddress (uri)).CreateChannel (); | |
client.Open (); | |
+ AutoResetEvent wait = null; | |
MessageReceived += delegate (SmfMessage msg) { | |
- switch (msg.StatusByte) { | |
- case 0xF0: | |
- case 0xF7: | |
- client.ProcessSysExMessage (msg.Data); | |
- break; | |
- case 0xFF: | |
- // do nothing | |
- break; | |
- default: | |
- client.ProcessMessage (msg.Value); | |
- break; | |
- } | |
+ if (wait == null) | |
+ wait = new AutoResetEvent (false); | |
+ else | |
+ wait.WaitOne (); // skip wait on the first one | |
+ if (msg.Data != null) | |
+ client.BeginProcessSysExMessage (msg.Data, delegate (IAsyncResult result) { client.EndProcessSysExMessage (result); wait.Set (); }, null); | |
+ else | |
+ client.BeginProcessMessage (msg.Value, delegate (IAsyncResult result) { client.EndProcessMessage (result); wait.Set (); }, null); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment