Example #1
0
        /// <summary>
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            if (!AudioEngine.Track.IsPlaying || Qua.TimingPoints.Count == 0)
            {
                return;
            }

            var time = AudioEngine.Track.Time + ConfigManager.GlobalAudioOffset.Value;

            var point = Qua.GetTimingPointAt(time);

            if (time < point.StartTime)
            {
                LastBeat = -1;
                return;
            }

            // Get the total amount of beats that'll be played for the timing point.
            // This can depend on if the user wants 8 beats or 4.
            var totalBeats = (time - point.StartTime) / (point.MillisecondsPerBeat / (ConfigManager.EditorMetronomePlayHalfBeats.Value ? 2 : 1));

            CurrentTotalBeats = (int)Math.Floor(totalBeats);
            CurrentBeat       = (int)totalBeats % 4;

            // Play samples
            if (CurrentTotalBeats == 0 && LastTotalBeats < 0 || CurrentBeat != LastBeat)
            {
                if (CurrentBeat == 0)
                {
                    MeasureTickSample.CreateChannel().Play();
                }
                else
                {
                    BeatTickSample.CreateChannel().Play();
                }
            }

            // Keep track of the last beat & last total beats in the current frame, so we know when to play
            // the next sample.
            LastBeat       = CurrentBeat;
            LastTotalBeats = CurrentTotalBeats;
        }
Example #2
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 public void Dispose()
 {
     BeatTickSample?.Dispose();
     MeasureTickSample?.Dispose();
 }