private void PickNextNote() { base.Stop(); chosenPitch = (new Random().Next(maximumPitch - minimumPitch)) + minimumPitch; // If flats and sharps are disabled, and the chosen pitch is either, drop it by 1 to the nearest natural if (!GameConfiguration.Sharps && !GameConfiguration.Flats) { var position = chosenPitch.PositionInOctave(); if (SharpOctavePositions.Contains(position)) { chosenPitch--; } } var viewModel = new NoteTrainerViewModel(); viewModel.DisplayNotes.Add(new DisplayNote { MidiPitch = chosenPitch, State = DisplayNoteState.Neutral }); ViewModelChangedEvent?.Invoke(this, viewModel); gameState = GameState.WaitingForInput; base.Resume(); }
internal void UpdateDisplay(NoteTrainerViewModel trainerViewModel) { ClearMusicScore(); var translationMode = Pitch.MidiPitchTranslationMode.Auto; if (gameConfiguration.Flats && !gameConfiguration.Sharps) { translationMode = Pitch.MidiPitchTranslationMode.Flats; } else if (gameConfiguration.Sharps && !gameConfiguration.Flats) { translationMode = Pitch.MidiPitchTranslationMode.Sharps; } foreach (var displayNote in trainerViewModel.DisplayNotes) { var staff = (displayNote.MidiPitch >= Midi.Pitch.C4) ? musicScore.FirstStaff : musicScore.SecondStaff; var scoreNote = new Note(Pitch.FromMidiPitch((int)displayNote.MidiPitch, translationMode), RhythmicDuration.Quarter) { IsUpperMemberOfChord = (staff.Elements.Count > 2) }; switch (displayNote.State) { case DisplayNoteState.Correct: scoreNote.CustomColor = new Color(0, 255, 0, 255); break; case DisplayNoteState.Incorrect: scoreNote.CustomColor = Color.Red; break; } staff.Add(scoreNote); } if (musicScore.FirstStaff.Elements.Count == 2) { musicScore.FirstStaff.Elements.Add(new Rest(RhythmicDuration.Quarter)); } if (musicScore.SecondStaff.Elements.Count == 2) { musicScore.SecondStaff.Elements.Add(new Rest(RhythmicDuration.Quarter)); } }
private void CheckPressedKeys() { bool correctKeyPressed = false; int incorrectKeys = 0; var viewModel = new NoteTrainerViewModel(); foreach (KeyboardKey key in keyboardState.DepressedKeys) { if (key.MidiPitch.Equals(chosenPitch)) { viewModel.DisplayNotes.Add(new DisplayNote { MidiPitch = key.MidiPitch, State = DisplayNoteState.Correct }); correctKeyPressed = true; } else { viewModel.DisplayNotes.Add(new DisplayNote { MidiPitch = key.MidiPitch, State = DisplayNoteState.Incorrect }); incorrectKeys++; } } if (!correctKeyPressed) { viewModel.DisplayNotes.Insert(0, new DisplayNote { MidiPitch = chosenPitch, State = DisplayNoteState.Neutral }); } ViewModelChangedEvent?.Invoke(this, viewModel); if (correctKeyPressed && incorrectKeys == 0) { gameState = GameState.ProceedToNext; ResetTimer(); } }
private void Game_ViewModelChangedEvent(object sender, NoteTrainerViewModel trainerViewModel) { Dispatcher.Invoke(new Action <NoteTrainerViewModel>(UpdateDisplay), trainerViewModel); }