/// <summary> /// Event handler for individual miniGrid (holding 1-4 sounds) in mastergrid /// </summary> void OnMiniGridTapped(MiniGrid miniGrid) { Instrument selectedInstrument = selectedInstrButton.Instrument; // Changes UI represenation and returns new set of colors on this grid bool added = miniGrid.ToggleColor(selectedInstrument.color); // If sidebar color isn't part of button's new set of colors, remove it Instrument.Note toggledNote = selectedInstrument.AtPitch(miniGrid.semitoneShift); //If sidebar button color = clicked button color if (added) { song.AddNote(toggledNote, Grid.GetColumn(miniGrid)); // Add the note if (!player.IsPlaying) { SingleNotePlayer.PlayNote(selectedInstrument.AtPitch(miniGrid.semitoneShift)); // Play note so long as not already playing a song } } else { song.RemoveNote(toggledNote, Grid.GetColumn(miniGrid)); } //Undo clear stops woking when user adds stuff to grid so they don't accidentally undo clear clearedSong = null; loadedSongChanged = true; // If song is empty, no need to worry about changes, otherwise }
/// <summary> /// Method to make a new, empty stepGrid /// </summary> private void MakeStepGrid() { //Set up grid of note squares stepgrid = new Grid { ColumnSpacing = stepGridSpacing, RowSpacing = stepGridSpacing }; //Initialize the number of rows and columns for the stepgrid for (int i = 0; i < NumRows; i++) { stepgrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(miniGridHeight, GridUnitType.Absolute) }); } for (int i = 0; i < NumColumns; i++) { stepgrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(miniGridWidth, GridUnitType.Absolute) }); } //Add grids to the stepgrid, and give each 2 columns, two rows and a BoxView for (int i = 0; i < NumRows; i++) { for (int j = 0; j < NumColumns; j++) { int semitoneShift = RowWithSemitoneShiftOfZero - i; MiniGrid miniGrid = new MiniGrid(semitoneShift); miniGrid.Tap += OnMiniGridTapped; stepgrid.Children.Add(miniGrid, j, i); if (j % 8 == 0) { Label noteLabel = MakeTextlessLabel(); noteLabel.Text = Instrument.SemitoneShiftToString(semitoneShift); stepgrid.Children.Add(noteLabel, j, i); } //Measure labels appear every 6 rows, 4 columns if ((i % 6 == 0) && (j % 4 == 3)) //See if this works { Label measureLabel = MakeTextlessLabel(); measureLabel.Text = (j + 1).ToString(); stepgrid.Children.Add(measureLabel, j, i); } } } }