コード例 #1
0
        private void menuButton_Click(object sender, RoutedEventArgs e)
        {
            // show file dialog
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();

            // file type filter
            dialog.DefaultExt = ".wav";
            dialog.Filter     = "Audo Files (*.wav, *.mp3)|*.wav;*.mp3";


            var result = dialog.ShowDialog();

            // if we got a file
            if (result == true)
            {
                buddy.SetFile(dialog.FileName);
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: lot224/SoundBoard
        private void CreatePageContent(MetroTabItem tab, List <Tuple <string, string> > buttons = null)
        {
            Grid parentGrid = new Grid();

            ColumnDefinition col1 = new ColumnDefinition();

            col1.Width = new GridLength(1, GridUnitType.Star);
            parentGrid.ColumnDefinitions.Add(col1);

            ColumnDefinition col2 = new ColumnDefinition();

            col2.Width = new GridLength(1, GridUnitType.Star);
            parentGrid.ColumnDefinitions.Add(col2);

            RowDefinition row;

            for (int i = 0; i < 5; ++i)
            {
                row        = new RowDefinition();
                row.Height = new GridLength(1, GridUnitType.Star);
                parentGrid.RowDefinitions.Add(row);

                // sound button
                SoundButton soundButton = new SoundButton();

                Grid.SetColumn(soundButton, 0);
                Grid.SetRow(soundButton, i);
                parentGrid.Children.Add(soundButton);

                if (buttons != null)
                {
                    soundButton.SetFile(buttons[i].Item2, buttons[i].Item1);
                }

                // menu button
                MenuButton menuButton = new MenuButton(soundButton);

                Grid.SetColumn(menuButton, 0);
                Grid.SetRow(menuButton, i);
                parentGrid.Children.Add(menuButton);

                // progress bar
                SoundProgressBar progressBar = new SoundProgressBar();

                Grid.SetColumn(progressBar, 0);
                Grid.SetRow(progressBar, i);
                parentGrid.Children.Add(progressBar);

                soundButton.SetSoundProgressBar(progressBar);
            }

            for (int i = 0; i < 5; ++i)
            {
                // only have to add the rows once (above)

                // sound button
                SoundButton soundButton = new SoundButton();

                Grid.SetColumn(soundButton, 1);
                Grid.SetRow(soundButton, i);
                parentGrid.Children.Add(soundButton);

                if (buttons != null)
                {
                    soundButton.SetFile(buttons[i + 5].Item2, buttons[i + 5].Item1);
                }

                // menu button
                MenuButton menuButton = new MenuButton(soundButton);

                Grid.SetColumn(menuButton, 1);
                Grid.SetRow(menuButton, i);
                parentGrid.Children.Add(menuButton);

                // progress bar
                SoundProgressBar progressBar = new SoundProgressBar();

                Grid.SetColumn(progressBar, 1);
                Grid.SetRow(progressBar, i);
                parentGrid.Children.Add(progressBar);

                soundButton.SetSoundProgressBar(progressBar);
            }

            tab.Content = parentGrid;
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: lot224/SoundBoard
        private void KeyDownHandler(object sender, KeyEventArgs e)
        {
            Mouse.Capture(null);

            char c = GetCharFromKey(e.Key);

            if (char.IsLetter(c) || char.IsPunctuation(c) || char.IsNumber(c))
            {
                searchString += c;
            }
            else if (e.Key == Key.Space)
            {
                searchString += ' ';
            }
            else if (e.Key == Key.Back && searchString.Length > 0)
            {
                searchString = searchString.Substring(0, searchString.Length - 1);
            }
            else if (e.Key == Key.Escape)
            {
                // if the search bar is open, close it
                if (Search.IsOpen)
                {
                    searchString  = ""; // don'even wait for it to close to clear the query
                    Search.IsOpen = false;
                }
                // otherwise, stop any playing sounds
                else
                {
                    ButtonAutomationPeer peer       = new ButtonAutomationPeer(Silence);
                    IInvokeProvider      invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                    invokeProv.Invoke();
                }
                return;
            }
            else if (e.Key == Key.Down)
            {
                bool foundFocused = false;
                // loop through the buttons and focus the next one
                foreach (var child in ResultsPanel.Children)
                {
                    if (child is SoundButton)
                    {
                        if (foundFocused)
                        {
                            // we found the last focused button, so focus this one
                            ((SoundButton)child).Focus();
                            focusedButton = ((SoundButton)child);
                            break;
                        }
                        if (((SoundButton)child).IsFocused)
                        {
                            // we found the focused button! focus the next one
                            foundFocused = true;
                        }
                    }
                }
                return;
            }
            else if (e.Key == Key.Up)
            {
                SoundButton previousButton = null;
                // loop through the buttons and focus the previous one
                foreach (var child in ResultsPanel.Children)
                {
                    if (child is SoundButton)
                    {
                        if (((SoundButton)child).IsFocused)
                        {
                            // focus the previous one!
                            if (previousButton != null)
                            {
                                previousButton.Focus();
                                focusedButton = previousButton;
                                break;
                            }
                        }
                        previousButton = (SoundButton)child;
                    }
                }
                return;
            }
            else if (e.Key == Key.Enter)
            {
                // play the sound!
                foreach (var child in ResultsPanel.Children)
                {
                    if (child is SoundButton && ((SoundButton)child).IsFocused)
                    {
                        ButtonAutomationPeer peer       = new ButtonAutomationPeer((SoundButton)child);
                        IInvokeProvider      invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                        invokeProv.Invoke();
                    }
                }
                return;
            }
            else
            {
                return;
            }

            Query.Text       = searchString;
            Query.CaretIndex = Query.Text.Length;

            Search.IsOpen = true;

            // get rid of any previous buttons / do reverse iteration to prevent weird bugs
            for (int i = ResultsPanel.Children.Count - 1; i >= 0; --i)
            {
                if (ResultsPanel.Children[i] is SoundButton)
                {
                    ResultsPanel.Children.Remove((SoundButton)ResultsPanel.Children[i]);
                }
            }

            // perform search
            if (searchString != "")
            {
                foreach (KeyValuePair <string, string> entry in sounds)
                {
                    if (entry.Key.ToLower().Contains(searchString.ToLower()))
                    {
                        SoundButton button = new SoundButton(true);
                        button.SetFile(entry.Value, entry.Key, false);

                        ResultsPanel.Children.Add(button);
                    }
                }

                // if we've added at least one button, focus the first one
                if (ResultsPanel.Children.Count > 0)
                {
                    ((SoundButton)ResultsPanel.Children[0]).Focus();
                    focusedButton = ((SoundButton)ResultsPanel.Children[0]);
                }
            }
        }