Ejemplo n.º 1
0
        private async void songListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (player == null || !player.IsPlaying)
            {
                var sel = songListView.SelectedItem as string;
                if (sel != null)
                {
                    displayStatus("Loading...");

                    resetOctaveOffsets();
                    resetMute();
                    resetPlayer();

                    player = await MidiPlayer.LoadConfig(sel, motors.ToArray());

                    if (player != null)
                    {
                        player.StateChanged += (s, args) =>
                        {
                            updateUI();
                        };
                        player.SpeedChanged += (s, args) =>
                        {
                            updateUI();
                        };

                        updateUI();

                        statusTextBlock.Text = (player != null) ? "Loaded: " + sel : "";
                    }
                    else
                    {
                        statusTextBlock.Text = "Error loading " + sel;
                    }
                }
                else
                {
                    displayStatus("No song selected.");
                }
            }
            playButton.IsEnabled = true;
        }
Ejemplo 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;
        }