private void HandleMessage(RawMidiMessage message) { // For the moment, we only care about SysEx Data Set messages if (!DataSetMessage.TryParse(message, out var result)) { return; } if (result.RawDeviceId != rawDeviceId || result.ModelId != modelId) { return; } HandleDataSetMessage(result); }
private void HandleMessage(RawMidiMessage message) { // If it's a Data Set message aimed at this device, handle it... if (DataSetMessage.TryParse(message, out var result) && result.RawDeviceId == rawDeviceId && result.ModelId == modelId) { HandleDataSetMessage(result); } // Otherwise, delegate to any other event handlers that have been set up. else { MessageReceived?.Invoke(this, message); } }
private void HandleDataSetMessage(DataSetMessage message) { LinkedList <TaskCompletionSource <byte[]> > sourcesToComplete = new LinkedList <TaskCompletionSource <byte[]> >(); lock (sync) { var node = consumers.First; while (node != null) { var consumer = node.Value; if (consumer.ExpectedAddress == message.Address && consumer.ExpectedSize == message.Length) { sourcesToComplete.AddLast(consumer.TaskCompletionSource); consumers.Remove(node); } node = node.Next; } } foreach (var source in sourcesToComplete) { source.TrySetResult(message.Data); } }