Ejemplo n.º 1
0
        /// <summary>
        /// Called when the user clicks the 'Load' button.
        /// Opens the selected MusicXML file, converts it to a Score object, and loads it in the viewer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            MusicNameLabel.Content = "";

            // Close the score creation window if open
            ScoreCreationWindow.Visibility = Visibility.Hidden;

            string fileName;
            // Use an OpenFile dilaog to get the file name
            Nullable <bool> result;
            OpenFileDialog  dialog = new OpenFileDialog();

            try
            {
                result = dialog.ShowDialog();
            }

            catch (Exception ex)
            {
                MessageBox.Show("Could not open file dialog. " + ex.Message);
                OpenScoreCreationWindow();
                return;
            }

            if (result == true)
            {
                fileName = dialog.FileName;
            }

            else
            {
                MessageBox.Show("File could not be opened.");
                OpenScoreCreationWindow();
                return;
            }

            // Load the file
            try
            {
                model.loadFile(fileName);
                Loaded = true;


                //hide key cover
                KeyCover.Visibility = Visibility.Hidden;

                //make music sheet, keys, notes, keyboard settings visible
                Print.Visibility                 = Visibility.Visible;
                MusicSheet.Visibility            = Visibility.Visible;
                Notes_Rest.Visibility            = Visibility.Visible;
                Keyboard_Controls.Visibility     = Visibility.Visible;
                Piano_KeyBoard_layout.Visibility = Visibility.Visible;
                Piano_White_Keys.Visibility      = Visibility.Visible;
                Piano_Black_Keys.Visibility      = Visibility.Visible;
                WorkingButtons.Visibility        = Visibility.Visible;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Could not parse file: " + ex.Message);
                OpenScoreCreationWindow();
            }
        }