void DoUpdate() { double updateStartTime = AudioSettings.dspTime; UpdatePosition(); if (AudioHelmClock.GetGlobalPause()) { return; } double position = GetSequencerTime(); float sixteenthTime = GetSixteenthTime(); double currentTime = GetSequencerPosition() * sixteenthTime; double sequencerTime = length * sixteenthTime; double windowMax = position + lookaheadTime / sixteenthTime; if (windowMax <= lastWindowTime) { lastWindowTime = windowMax; return; } if (WaitingForNextCycle()) { lastWindowTime = windowMax; return; } double internalLastWindowMax = Mathf.Repeat((float)lastWindowTime, length); double internalWindowMax = Mathf.Repeat((float)windowMax, length); float startSearch = (float)internalLastWindowMax; float endSearch = (float)internalWindowMax; List <Note> notes = GetAllNoteOnsInRange(startSearch, endSearch); foreach (Note note in notes) { double startTime = sixteenthTime * note.start; // Check if we wrapped around. if (startTime < currentTime) { startTime += sequencerTime; } double endTime = startTime + sixteenthTime * (note.end - note.start); double timeToStart = startTime - currentTime + updateStartTime; double timeToEnd = endTime - currentTime + updateStartTime; GetComponent <Sampler>().NoteOnScheduled(note.note, note.velocity, timeToStart, timeToEnd); } lastWindowTime = windowMax; }
/// <summary> /// Update the position of the sequencer and fire any events that have occurred. /// </summary> protected void UpdatePosition() { if (AudioHelmClock.GetGlobalPause()) { if (!paused) { AllNotesOff(); } paused = true; return; } paused = false; UpdateBeatTime(); UpdateIndex(); float nextPosition = (float)GetSequencerPosition(); if (nextPosition < 0.0f || nextPosition < lastSequencerPosition) { lastSequencerPosition = nextPosition; return; } List <Note> noteOns = GetAllNoteOnsInRange(lastSequencerPosition, nextPosition); List <Note> noteOffs = GetAllNoteOffsInRange(lastSequencerPosition, nextPosition); int noteOnIndex = 0; int noteOffIndex = 0; while (noteOnIndex < noteOns.Count && noteOffIndex < noteOffs.Count) { if (noteOns[noteOnIndex].start < noteOffs[noteOffIndex].end) { SendNoteOn(noteOns[noteOnIndex++]); } else { SendNoteOff(noteOffs[noteOffIndex++]); } } for (; noteOnIndex < noteOns.Count; ++noteOnIndex) { SendNoteOn(noteOns[noteOnIndex]); } for (; noteOffIndex < noteOffs.Count; ++noteOffIndex) { SendNoteOff(noteOffs[noteOffIndex]); } lastSequencerPosition = nextPosition; }
/// <summary> /// Update the position of the sequencer and fire any events that have occurred. /// </summary> protected void UpdatePosition(bool sendEvents = true) { if (AudioHelmClock.GetGlobalPause()) { if (!paused) { AllNotesOff(); } paused = true; return; } paused = false; UpdateBeatTime(); UpdateIndex(); float nextPosition = (float)GetSequencerPosition(); int cycles = Mathf.FloorToInt((float)GetSequencerTime() / length); if (nextPosition < 0.0f || cycles < numCycles) { lastSequencerPosition = nextPosition; numCycles = cycles; return; } if (cycles > numCycles) { numCycles = cycles; waitTillNextCycle = false; } if (waitTillNextCycle || !sendEvents) { lastSequencerPosition = nextPosition; return; } List <Note> noteOns = GetAllNoteOnsInRange(lastSequencerPosition, nextPosition); List <Note> noteOffs = GetAllNoteOffsInRange(lastSequencerPosition, nextPosition); int noteOnIndex = 0; int noteOffIndex = 0; while (noteOnIndex < noteOns.Count && noteOffIndex < noteOffs.Count) { if (noteOns[noteOnIndex].start < noteOffs[noteOffIndex].end) { SendNoteOn(noteOns[noteOnIndex++]); } else { SendNoteOff(noteOffs[noteOffIndex++]); } } for (; noteOnIndex < noteOns.Count; ++noteOnIndex) { SendNoteOn(noteOns[noteOnIndex]); } for (; noteOffIndex < noteOffs.Count; ++noteOffIndex) { SendNoteOff(noteOffs[noteOffIndex]); } lastSequencerPosition = nextPosition; }