コード例 #1
0
ファイル: MidiDevices.cs プロジェクト: xiulolz/DemoCode
        public static async Task <IReadOnlyList <DeviceIdentity> > ListDeviceIdentities(MidiInputDevice input, MidiOutputDevice output, TimeSpan timeout)
        {
            List <DeviceIdentity> identities = new List <DeviceIdentity>();

            using (var client = await RawMidiClient.CreateAsync(input, output, HandleMessage))
            {
                // Identity request message for all devices IDs.
                client.Send(new RawMidiMessage(new byte[] { 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7 }));
                await Task.Delay(timeout);
            }
            return(identities.AsReadOnly());

            void HandleMessage(RawMidiMessage message)
            {
                // TODO: Handle 17-byte messages for "long" manufacturer IDs
                var data = message.Data;

                if (data.Length == 15 &&
                    data[0] == 0xf0 && // SysEx
                    data[1] == 0x7e && // Universal non-realtime message
                    data[3] == 0x06 && // General information
                    data[4] == 0x02)   // Identity reply
                {
                    byte rawDeviceId      = data[2];
                    var  manufacturerId   = (ManufacturerId)data[5];
                    int  familyCode       = data[6] + (data[7] << 8);
                    int  familyNumberCode = data[8] + (data[9] << 8);
                    int  revision         = data[10] + (data[11] << 8) + (data[12] << 16) + (data[13] << 24);
                    identities.Add(new DeviceIdentity(rawDeviceId, manufacturerId, familyCode, familyNumberCode, revision));
                }
            }
        }
コード例 #2
0
ファイル: RolandMidiClient.cs プロジェクト: xiulolz/DemoCode
        internal static async Task <RolandMidiClient> CreateAsync(MidiInputDevice inputDevice, MidiOutputDevice outputDevice, byte rawDeviceId, int modelId)
        {
            // This is all a bit nasty... we can't create a RolandMidiClient instance until we have the raw client, and we can't
            // create the raw client until we've got a method to call. LocalHandleMessage acts as a sort of trampoline.
            // If we could make the constructor asynchronous, it wouldn't be a problem.
            RolandMidiClient ret = null;
            var rawClient        = await RawMidiClient.CreateAsync(inputDevice, outputDevice, LocalHandleMessage);

            ret = new RolandMidiClient(rawClient, rawDeviceId, modelId);
            return(ret);

            void LocalHandleMessage(RawMidiMessage message) => ret?.HandleMessage(message);
        }
コード例 #3
0
ファイル: RolandMidiClient.cs プロジェクト: xiulolz/DemoCode
 private RolandMidiClient(RawMidiClient rawClient, byte rawDeviceId, int modelId)
 {
     this.rawClient   = rawClient;
     this.rawDeviceId = rawDeviceId;
     this.modelId     = modelId;
 }
コード例 #4
0
 private RolandMidiClient(RawMidiClient rawClient, byte rawDeviceId, ModuleIdentifier identifier)
 {
     this.rawClient   = rawClient;
     this.rawDeviceId = rawDeviceId;
     this.Identifier  = identifier;
 }