Example #1
0
        private long GetNoteLengthInRawTime(MarkablePlaybackEvent markablePlaybackEvent)
        {
            if (markablePlaybackEvent != null && markablePlaybackEvent.RelatedEvents.Count > 0)
            {
                var noteOff = markablePlaybackEvent.RelatedEvents.Find(note =>
                                                                       note?.Event?.EventType == MidiEventType.NoteOff);
                var noteOn = markablePlaybackEvent.RelatedEvents.Find(note =>
                                                                      note?.Event?.EventType == MidiEventType.NoteOn);
                long noteRawTime = -1;
                if (noteOff != null && noteOn != null)
                {
                    noteRawTime = noteOff.RawTime < noteOn.RawTime ? noteOff.RawTime : noteOn.RawTime;
                }
                else if (noteOff != null)
                {
                    noteRawTime = noteOff.RawTime;
                }
                else if (noteOn != null)
                {
                    noteRawTime = noteOn.RawTime;
                }

                return(noteRawTime - markablePlaybackEvent.RawTime);
            }

            return(-1);
        }
Example #2
0
        private void RenderTimeToNextNote(TimeSpan currentTime)
        {
            MarkablePlaybackEvent lastNoteOnScreen = null;

            if (this.notesOnScreen.Values.Count > 0)
            {
                lastNoteOnScreen = this.notesOnScreen.Values.Aggregate((a, b) => a.MarkablePlaybackEvent.RawTime > b.MarkablePlaybackEvent.RawTime ? a : b).MarkablePlaybackEvent;
            }

            TimeSpan lastNoteOffScreenTime = default(TimeSpan);

            if (lastNoteOnScreen != null && lastNoteOnScreen.Time.TotalMilliseconds > 0)
            {
                lastNoteOffScreenTime = lastNoteOnScreen.Time + noteDuration;
            }

            long nextNoteTime = GetNextNoteTime((long)currentTime.TotalMilliseconds);

            if (nextNoteTime < 0)
            {
                return;
            }

            long timeToNextNote = nextNoteTime - (long)currentTime.TotalMilliseconds;

            long timeToNextNoteAfterLastNote = timeToNextNote -
                                               // Subtract note duration because it will show up earlier
                                               (long)noteDuration.TotalMilliseconds +
                                               // Subtract currentTime to get the difference
                                               (long)currentTime.TotalMilliseconds;

            // No point of showing this if the next note is less than 3 second away
            if ((lastNoteOffScreenTime.TotalMilliseconds == 0 || currentTime.TotalMilliseconds - lastNoteOffScreenTime.TotalMilliseconds > msInASecond) &&
                (timeToNextNoteAfterLastNote > 3 * msInASecond || previousTimeToNote >= msInASecond) &&
                timeToNextNote >= msInASecond &&
                (lastPlayedNoteTimeIndex < this.noteTimes.Count - 1 ||
                 (lastPlayedNoteTimeIndex == this.noteTimes.Count - 1 && nextNoteTime > currentTime.TotalMilliseconds)))
            {
                previousTimeToNote = timeToNextNote;
                this.dotCounter    = 0;
                var seconds = timeToNextNote / msInASecond;
                this.InputControl.SetTimeToNextNote(string.Format(timeToNextNoteResource, seconds));
            }
            else
            {
                this.InputControl.SetTimeToNextNote($"{playingIndicatorResource}{new string('.', (this.dotCounter / 5) + 1)}");
                this.dotCounter++;
                if (this.dotCounter == 15)
                {
                    this.dotCounter = 0;
                }
            }
        }