/// <summary> /// Collects title, time, and key signature information from the Create New Score popup /// and uses them to create a new Score object and load it in the viewer. /// Called when the 'Start' button is clicked on the popup. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createNew(object sender, RoutedEventArgs e) { // Close the popup Loaded = false; KeyCover.Visibility = Visibility.Hidden; ScoreCreationWindow.Visibility = Visibility.Hidden; //make keys, music sheet, notes and keyboard control visible Print.Visibility = Visibility.Visible; Piano_KeyBoard_layout.Visibility = Visibility.Visible; Piano_White_Keys.Visibility = Visibility.Visible; Piano_Black_Keys.Visibility = Visibility.Visible; MusicSheet.Visibility = Visibility.Visible; Notes_Rest.Visibility = Visibility.Visible; Keyboard_Controls.Visibility = Visibility.Visible; WorkingButtons.Visibility = Visibility.Visible; // Calculate key signature based on selected value from array // If selected index < 13, keyIndex - seleted index -1, else keyIndex = selected index Console.WriteLine(MusicTitle); MusicNameLabel.Content = MusicTitle; // Calculate key signature int keyIndex = (KeySignatureCombo.SelectedIndex < 13) ? KeySignatureCombo.SelectedIndex - 1 : 12 - KeySignatureCombo.SelectedIndex; Manufaktura.Controls.Model.Key key = new Manufaktura.Controls.Model.Key(keyIndex); model.KeySig = new Manufaktura.Controls.Model.Key(keyIndex); // Calculate time signature TimeSignature timeSig = new TimeSignature(TimeSignatureType.Numbers, beatsPerMeasure, beatLength); model.TimeSig = new TimeSignature(TimeSignatureType.Numbers, beatsPerMeasure, beatLength); // **** GRAND STAFF ON HOLD -- SWITCHING TO SINGLE STAFF TO GET BUGS OUT **** // Build grand staff for now -- later may add options for more or fewer staves //Staff treble = new Staff(); //MusicalSymbol[] elements = { Clef.Treble, key, timeSig }; // Add treble clef, key sig, time sig //for (int i = 0; i < 3; i++) //{ // treble.Elements.Add(elements[i]); //} //Staff bass = new Staff(); //elements[0] = Clef.Bass; // Add bass clef, key sig, time sig //for (int i = 0; i < 3; i++) //{ // bass.Elements.Add(elements[i]); //} //Staff[] staves = { treble, bass }; //// Pass the title and the treble and bass staves to createNew //model.createNew(TitleBox.Text, staves); // Create a single staff score model.createNew(key, timeSig); }
/// <summary> /// Collects title, time, and key signature information from the Create New Score popup /// and uses them to create a new Score object and load it in the viewer. /// Called when the 'Start' button is clicked on the popup. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createNew(object sender, RoutedEventArgs e) { // Close the popup isLoaded = false; KeyCover.Visibility = Visibility.Hidden; ScoreCreationWindow.Visibility = Visibility.Hidden; //make keys, music sheet, notes and keyboard control visible Print.Visibility = Visibility.Visible; Piano_KeyBoard_layout.Visibility = Visibility.Visible; Piano_White_Keys.Visibility = Visibility.Visible; Piano_Black_Keys.Visibility = Visibility.Visible; MusicSheet.Visibility = Visibility.Visible; Notes_Rest.Visibility = Visibility.Visible; Keyboard_Controls.Visibility = Visibility.Hidden; WorkingButtons.Visibility = Visibility.Visible; //reset note selection to quarter note NoteSelectionReset(); // Calculate key signature based on selected value from array Console.WriteLine(MusicTitle); MusicNameLabel.Content = MusicTitle; // Calculate key signature int keyIndex = (KeySignatureCombo.SelectedIndex < 13) ? KeySignatureCombo.SelectedIndex - 1 : 12 - KeySignatureCombo.SelectedIndex; Manufaktura.Controls.Model.Key key = new Manufaktura.Controls.Model.Key(keyIndex); model.KeySig = new Manufaktura.Controls.Model.Key(keyIndex); // Calculate time signature TimeSignature timeSig = new TimeSignature(TimeSignatureType.Numbers, beatsPerMeasure, beatLength); model.TimeSig = new TimeSignature(TimeSignatureType.Numbers, beatsPerMeasure, beatLength); // Create a single staff score model.FileName = ""; model.createNew(key, timeSig); Viewer.ScoreSource = model.Data; model.ResetPlayer(); }
/// <summary> /// Parses the name of the piano key to determine pitch and creates a new Noe object with /// the specified pitch and current note value. /// </summary> /// <param name="keyName">The name of the piano key from which to derive the pitch</param> /// <returns></returns> private Note parseNoteFromInput(string keyName) { // Start with a Pich object Pitch p; if (keyName.Length == 2) // If it's a white key... // Note name is the first letter, octave number is the second letter. Pass both to the Pitch constructor { p = new Pitch(keyName.Substring(0, 1), 0, int.Parse(keyName.Substring(1, 1))); } else { // black key... // Determine if the current key uses sharps or flats (may be able to simplify this) Manufaktura.Controls.Model.Key key = null; foreach (var item in model.Data.FirstStaff.Elements) { if (item.GetType() == typeof(Manufaktura.Controls.Model.Key)) { key = (Manufaktura.Controls.Model.Key)item; break; } } string letter; int mod; // sharp or flat if (key.Fifths > 0) // if sharp key, use the first letter and add a sharp { letter = keyName.Substring(1, 1); mod = 1; } else { // flat key -- use the second letter and add a flat letter = keyName.Substring(0, 1); mod = -1; } p = new Pitch(letter, mod, int.Parse(keyName.Substring(2, 1))); // Third argument is octave } return(new Note(p, noteLength)); }