Esempio n. 1
0
        private async void playButton_Click(object sender, RoutedEventArgs e)
        {
            await ThreadPool.RunAsync((s) =>
            {
                if (!player.IsPlaying)
                {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    ThreadPool.RunAsync((s1) =>
                    {
                        player.Play();
                        Debug.WriteLine("Stopped playing.");
                    }, WorkItemPriority.High);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                }
                else
                {
                    displayStatus("Stopping...");

                    player.Stop();
                    resetAllMotors();
                }

                updateUI();
            }, WorkItemPriority.High);
        }
Esempio n. 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            long tps = TimeSpan.TicksPerSecond; //getTps();

            motors = new List <StepperMotor>()
            {
                new StepperMotor(3, 2, tps),
                new StepperMotor(17, 4, tps),
                new StepperMotor(22, 27, tps),
                new StepperMotor(9, 10, tps),
                new StepperMotor(5, 11, tps),
                new StepperMotor(13, 6, tps),
                new StepperMotor(26, 19, tps),
                new StepperMotor(21, 20, tps),
            };

            //motorListView.ItemsSource = motors;

            int count = 0;

            foreach (StepperMotor motor in motors)
            {
                motor.Name         = "Drive " + (++count);
                motor.OctaveOffset = -1;    // adjust octave

                var stackPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal
                };

                var textblock = new TextBlock()
                {
                    Text              = motor.Name,
                    Margin            = new Thickness(10),
                    VerticalAlignment = VerticalAlignment.Center,
                    FontSize          = 28,
                    FontWeight        = FontWeights.Light
                };

                var testButton = new Button()
                {
                    Content = "Test",
                    Margin  = new Thickness(10),
                    Width   = 100,
                };
                testButton.Click += async(s, args) =>
                {
                    await ThreadPool.RunAsync(async (s1) =>
                    {
                        MidiPlayer scalePlayer = await MidiPlayer.LoadConfig("Scales", new StepperMotor[] { motor });
                        scalePlayer.Play();
                    }, WorkItemPriority.Normal);
                };
                testButtons.Add(testButton);

                var muteToggle = new ToggleSwitch()
                {
                    IsOn   = true,
                    Margin = new Thickness(10)
                };
                muteToggle.Toggled += (s, args) =>
                {
                    motor.Mute = !muteToggle.IsOn;
                };

                motor.MuteChanged += async(s, args) =>
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        muteToggle.IsOn = !motor.Mute;
                    });
                };

                var octaveSlider = new Slider()
                {
                    Maximum = 5,
                    Minimum = -5,
                    Value   = motor.OctaveOffset,
                    Margin  = new Thickness(10),
                    Width   = 150,
                    Header  = "Octave Adjust"
                };
                octaveSlider.ValueChanged += (s, args) =>
                {
                    motor.OctaveOffset = (int)octaveSlider.Value;
                };
                sliders.Add(octaveSlider);

                motor.OctaveOffsetChanged += async(s, args) =>
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        octaveSlider.Value = motor.OctaveOffset;
                    });
                };

                stackPanel.Children.Add(textblock);
                stackPanel.Children.Add(testButton);
                stackPanel.Children.Add(muteToggle);
                stackPanel.Children.Add(octaveSlider);

                driveStackPanel.Children.Add(stackPanel);
            }

            resetAllMotors();

            songs = new ObservableCollection <string>(MidiConfig.Configs.Keys.ToArray());
            songListView.ItemsSource = songs;

            songListView.SelectedIndex = 0;
        }