/// <summary> /// Main loop that updates the currently elapsed time and fires the event for any missed notes /// </summary> private void playSong() { Console.WriteLine("In playSong"); _waveOut.Play(); long songStart = (long)_waveOut.GetPositionTimeSpan().TotalMilliseconds; Console.WriteLine("Start time: " + songStart); bool wasPaused = false; Console.WriteLine("Remaining notes: " + remainingNotes.Count); while (remainingNotes.Count > 0) { long elapsed = (long)_waveOut.GetPositionTimeSpan().TotalMilliseconds - songStart; CurrentTime = elapsed; if (State.Equals(GameState.PAUSED)) { if (!wasPaused) { Console.WriteLine("Game paused"); wasPaused = true; _waveOut.Pause(); } continue; } if (wasPaused && State.Equals(GameState.IN_GAME)) { Console.WriteLine("Was paused, resuming..."); _waveOut.Play(); wasPaused = false; } Note current; while (remainingNotes.Any() && (current = remainingNotes.First()).StartTime() <= elapsed - 200) { Console.WriteLine("Missed note at " + current.Position()); OnRaiseGameEvent(new GameEventArgs(current, Accuracy.MISS, 0)); remainingNotes.Remove(current); Console.WriteLine("Removed a note."); if (remainingNotes.Count == 0) { break; } foreach (Note n in toRemove) { remainingNotes.Remove(n); } } } Console.WriteLine("After loop"); }
private void PlaybackTimer_Tick(object sender, EventArgs e) { if (playback.PlaybackState == PlaybackState.Playing) { labelPlayback.Text = playback.GetPositionTimeSpan().ToString("mm") + ":" + playback.GetPositionTimeSpan().Add(new TimeSpan(0, 0, 1)).ToString("ss"); barPlayback.Value = Math.Min((int)playback.GetPositionTimeSpan().TotalMilliseconds / 10, barPlayback.Maximum); } else { ResetAudio(); } }