コード例 #1
0
        protected override async Task <int> InvokeAsync(InvocationContext context, IStandardStreamWriter console, RolandMidiClient client)
        {
            using (var device = new DeviceController(client))
            {
                var schema    = device.Schema;
                var channel   = context.ParseResult.ValueForOption <int>("channel");
                var keys      = context.ParseResult.ValueForOption <string>("keys");
                var targetKit = context.ParseResult.ValueForOption <int>("kit");
                if (targetKit < 1 || targetKit + 1 > schema.Kits)
                {
                    console.WriteLine($"Kit {targetKit} is out of range for {schema.Identifier.Name} for this command.");
                    console.WriteLine("Note that one extra kit is required after the specified one.");
                    return(1);
                }

                // Detect the current kit
                var currentKit = await device.GetCurrentKitAsync(CancellationToken.None);

                // Copy current kit to target kit and target kit + 1
                var kit = await device.LoadKitAsync(currentKit, progressHandler : null, CreateCancellationToken());

                var dataNode = new DataTreeNode(kit.Data, kit.KitRoot);
                await device.SaveDescendants(dataNode, schema.GetKitRoot(targetKit).Container.Address, progressHandler : null, CreateCancellationToken());

                await device.SaveDescendants(dataNode, schema.GetKitRoot(targetKit + 1).Container.Address, progressHandler : null, CreateCancellationToken());

                await device.SetCurrentKitAsync(targetKit, CancellationToken.None);

                var programChangeCommand = (byte)(0xc0 | (channel - 1));

                // Now listen for the foot switch...
                client.MessageReceived += async(sender, message) =>
                {
                    if (message.Data.Length == 2 && message.Data[0] == programChangeCommand)
                    {
                        console.WriteLine("Turning the page...");
                        SendKeysUtilities.SendWait(keys);
                        await device.SetCurrentKitAsync(targetKit, CancellationToken.None);
                    }
                };
                console.WriteLine("Listening for foot switch");
                await Task.Delay(TimeSpan.FromHours(1));
            }
            return(0);

            CancellationToken CreateCancellationToken() => new CancellationTokenSource(10000).Token;
        }
コード例 #2
0
        public async Task <int> InvokeAsync(InvocationContext context)
        {
            var console = context.Console.Out;

            if (!SendKeysUtilities.HasSendKeys)
            {
                console.WriteLine($"SendKeys not detected; this command can only be run on Windows.");
                return(1);
            }

            var client = await MidiDevices.DetectSingleRolandMidiClientAsync(new ConsoleLogger(console), SchemaRegistry.KnownSchemas.Keys);

            if (client is null)
            {
                return(1);
            }
            var schema = SchemaRegistry.KnownSchemas[client.Identifier].Value;

            using (client)
            {
                var channel  = context.ParseResult.ValueForOption <int>("channel");
                var keys     = context.ParseResult.ValueForOption <string>("keys");
                var midiNote = context.ParseResult.ValueForOption <int>("note");

                var noteOn = (byte)(0x90 | (channel - 1));

                // Now listen for the foot switch...
                client.MessageReceived += (sender, message) =>
                {
                    if (message.Data.Length == 3 && message.Data[0] == noteOn && message.Data[1] == midiNote)
                    {
                        console.WriteLine("Turning the page...");
                        SendKeysUtilities.SendWait(keys);
                    }
                };
                console.WriteLine("Listening for MIDI note");
                await Task.Delay(TimeSpan.FromHours(1));
            }
            return(0);
        }
コード例 #3
0
        protected override async Task <int> InvokeAsync(InvocationContext context, IStandardStreamWriter console, RolandMidiClient client)
        {
            var channel  = context.ParseResult.ValueForOption <int>("channel");
            var keys     = context.ParseResult.ValueForOption <string>("keys");
            var midiNote = context.ParseResult.ValueForOption <int>("note");

            var noteOn = (byte)(0x90 | (channel - 1));

            // Now listen for the foot switch...
            client.MessageReceived += (sender, message) =>
            {
                if (message.Data.Length == 3 && message.Data[0] == noteOn && message.Data[1] == midiNote)
                {
                    console.WriteLine("Turning the page...");
                    SendKeysUtilities.SendWait(keys);
                }
            };
            console.WriteLine("Listening for MIDI note");
            await Task.Delay(TimeSpan.FromHours(1));

            return(0);
        }
コード例 #4
0
        public async Task <int> InvokeAsync(InvocationContext context)
        {
            var console = context.Console.Out;

            if (!SendKeysUtilities.HasSendKeys)
            {
                console.WriteLine($"SendKeys not detected; this command can only be run on Windows.");
                return(1);
            }

            var(client, schema) = await DeviceDetection.DetectDeviceAsync(console);

            if (client is null)
            {
                return(1);
            }

            using (client)
            {
                var channel   = context.ParseResult.ValueForOption <int>("channel");
                var keys      = context.ParseResult.ValueForOption <string>("keys");
                var targetKit = context.ParseResult.ValueForOption <int>("kit");
                if (targetKit < 1 || targetKit + 1 > schema.KitRoots.Count)
                {
                    console.WriteLine($"Kit {targetKit} is out of range for {schema.Identifier.Name} for this command.");
                    console.WriteLine("Note that one extra kit is required after the specified one.");
                    return(1);
                }

                // Detect the current kit
                // TODO: Stop assuming current kit is at address 0, although it is for TD-17, TD-50 and TD-27...
                var data = await client.RequestDataAsync(0, 1, new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token);

                var currentKit = data[0] + 1;

                // Copy current kit to target kit and target kit + 1
                var kit = await KitUtilities.ReadKit(schema, client, currentKit, console);

                await KitUtilities.WriteKit(client, kit, targetKit, console);

                await KitUtilities.WriteKit(client, kit, targetKit + 1, console);

                SetCurrentKit(targetKit);
                var programChangeCommand = (byte)(0xc0 | (channel - 1));

                // Now listen for the foot switch...
                client.MessageReceived += (sender, message) =>
                {
                    if (message.Data.Length == 2 && message.Data[0] == programChangeCommand)
                    {
                        console.WriteLine("Turning the page...");
                        SendKeysUtilities.SendWait(keys);
                        SetCurrentKit(targetKit);
                    }
                };
                console.WriteLine("Listening for foot switch");
                await Task.Delay(TimeSpan.FromHours(1));
            }
            return(0);

            void SetCurrentKit(int newKitNumber) => client.SendData(0, new[] { (byte)(newKitNumber - 1) });
        }