예제 #1
0
        private static void B_Click(object sender, RoutedEventArgs e)
        {
            Button b = (Button)sender;
            ToPlay p = (ToPlay)b.Tag;

            p.Play();
        }
예제 #2
0
        internal static void Test2()
        {
            var g = Enum.GetValues(typeof(NoteName));

            // CancellationTokenSource cts = new CancellationTokenSource();

            using (var outputDevice = OutputDevice.GetByName("Microsoft GS Wavetable Synth"))
            {
                Grid grid = new Grid();
                grid.Background          = new SolidColorBrush(Colors.DarkGreen);
                grid.HorizontalAlignment = HorizontalAlignment.Stretch;
                grid.VerticalAlignment   = VerticalAlignment.Stretch;
                MetroWindow w = new MetroWindow();
                w.TitleCharacterCasing = CharacterCasing.Normal;
                w.Width   = 600;
                w.Height  = 400;
                w.Content = grid;

                for (int o = 0; o < 6; o++)
                {
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(57, GridUnitType.Star)
                    });
                }
                for (int i = 0; i < g.Length; i++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(48, GridUnitType.Star)
                    });
                }


                // List<Task> L = new List<Task>();
                for (int o = 1; o < 7; o++)
                {
                    for (int i = 0; i < g.Length; i++)
                    {
                        NoteName n  = (NoteName)g.GetValue(i);
                        var      nn = n.ToString().Replace("Sharp", "#") + o;
                        var      b  = new Button {
                            Content = nn
                        };
                        if (nn.Contains("#"))
                        {
                            b.Background = new SolidColorBrush(Colors.LimeGreen);
                        }
                        b.BorderThickness = new Thickness(0);
                        b.Margin          = new Thickness(1);

                        Grid.SetRow(b, o - 1);
                        Grid.SetColumn(b, i);
                        var tp = new ToPlay {
                            Note = n, Octave = o, Device = outputDevice
                        };
                        tp.InitPlay();
                        b.Tag = tp;

                        b.Click += B_Click;;
                        grid.Children.Add(b);

                        // MessageBox.Show(n.ToString());
                    }
                }

                w.ShowDialog();

                /*  List<Task> L = new List<Task>();
                 * for (int i = 0; i < g.Length; i++)
                 * {
                 *    NoteName n = (NoteName)g.GetValue(i);
                 *    L.Add(Task.Run(() => PlayNote(outputDevice, n, 2)));//);
                 *    MessageBox.Show(n.ToString());
                 * }
                 * // cts.Cancel();
                 */

                // Task.WaitAll(L.ToArray());
            }
        }