void UpdateTiming() { long numSamples; int tempOut; if (!playback_.GetNumPlayedSamples(out numSamples, out tempOut)) { numSamples = -1; } isNearChanged_ = false; isJustChanged_ = false; currentSample_ = (int)numSamples; if (currentSample_ >= 0) { just_.Bar = (int)(currentSample_ / samplesPerBar_); just_.Beat = (int)((currentSample_ - just_.Bar * samplesPerBar_) / samplesPerBeat_); just_.Unit = (int)((currentSample_ - just_.Bar * samplesPerBar_ - just_.Beat * samplesPerBeat_) / samplesPerUnit_); just_.Fix(); if (numBlockBar_ > 0) { while (just_.Bar >= numBlockBar_) { just_--; } } timeSecFromJust_ = (double)(currentSample_ - just_.Bar * samplesPerBar_ - just_.Beat * samplesPerBeat_ - just_.Unit * samplesPerUnit_) / (double)SamplingRate; isFormerHalf_ = (timeSecFromJust_ * SamplingRate) < samplesPerUnit_ / 2; near_.Copy(just_); if (!isFormerHalf_) { near_++; near_.LoopBack(numBlockBar_); } isJustChanged_ = (just_.Equals(oldJust_) == false); isNearChanged_ = (near_.Equals(oldNear_) == false); CallEvents(); oldNear_.Copy(near_); oldJust_.Copy(just_); } if (DebugText != null) { DebugText.text = "Just = " + Just.ToString() + ", MusicalTime = " + MusicalTime_; if (BlockInfos.Count > 0) { DebugText.text += System.Environment.NewLine + "block[" + currentBlockIndex_ + "] = " + CurrentBlock_.BlockName + "(" + numBlockBar_ + "bar)"; } } }
void UpdateTiming() { // find section index int newIndex = sectionIndex_; if (CreateSectionClips) { newIndex = sectionSources_.IndexOf(musicSource_); currentSample_ = musicSource_.timeSamples; } else { int oldSample = currentSample_; currentSample_ = musicSource_.timeSamples; if (sectionIndex_ + 1 >= Sections.Count) { if (currentSample_ < oldSample) { newIndex = 0; } } else { if (Sections[sectionIndex_ + 1].StartTimeSamples <= currentSample_) { newIndex = sectionIndex_ + 1; } } } if (newIndex != sectionIndex_) { sectionIndex_ = newIndex; OnSectionChanged(); } // calc current timing isNearChanged_ = false; isJustChanged_ = false; int sectionSample = currentSample_ - (CreateSectionClips ? 0 : CurrentSection_.StartTimeSamples); if (sectionSample >= 0) { just_.Bar = (int)(sectionSample / samplesPerBar_) + CurrentSection_.StartBar; just_.Beat = (int)((sectionSample % samplesPerBar_) / samplesPerBeat_); just_.Unit = (int)(((sectionSample % samplesPerBar_) % samplesPerBeat_) / samplesPerUnit_); just_.Fix(CurrentSection_); if (CreateSectionClips) { if (CurrentSection_.LoopType == Section.ClipType.Loop && numLoopBar_ > 0) { just_.Bar -= CurrentSection_.StartBar; while (just_.Bar >= numLoopBar_) { just_.Decrement(CurrentSection_); } just_.Bar += CurrentSection_.StartBar; } if (isTransitioning_ && just_.Equals(transitionTiming_)) { if (CurrentSection_.LoopType == Section.ClipType.Loop && just_.Bar == CurrentSection_.StartBar) { just_.Bar = CurrentSection_.StartBar + numLoopBar_; } just_.Decrement(CurrentSection_); } } else { if (sectionIndex_ + 1 >= Sections.Count) { if (numLoopBar_ > 0) { while (just_.Bar >= numLoopBar_) { just_.Decrement(CurrentSection_); } } } else { while (just_.Bar >= Sections[sectionIndex_ + 1].StartBar) { just_.Decrement(CurrentSection_); } } } just_.Bar -= CurrentSection_.StartBar; timeSecFromJust_ = (double)(sectionSample - just_.Bar * samplesPerBar_ - just_.Beat * samplesPerBeat_ - just_.Unit * samplesPerUnit_) / (double)samplingRate_; isFormerHalf_ = (timeSecFromJust_ * samplingRate_) < samplesPerUnit_ / 2; just_.Bar += CurrentSection_.StartBar; near_.Copy(just_); if (!isFormerHalf_) { near_.Increment(CurrentSection_); } if (samplesInLoop_ != 0 && currentSample_ + samplesPerUnit_ / 2 >= samplesInLoop_) { near_.Init(); } isNearChanged_ = (near_.Equals(oldNear_) == false); isJustChanged_ = (just_.Equals(oldJust_) == false); CallEvents(); oldNear_.Copy(near_); oldJust_.Copy(just_); } if (DebugText != null) { DebugText.text = "Just = " + Just.ToString() + ", MusicalTime = " + MusicalTime_; if (Sections.Count > 0) { DebugText.text += System.Environment.NewLine + "section[" + sectionIndex_ + "] = " + CurrentSection_.ToString(); } } else if (DebugPrint) { string text = "Just = " + Just.ToString() + ", MusicalTime = " + MusicalTime_; if (Sections.Count > 0) { text += System.Environment.NewLine + "section[" + sectionIndex_ + "] = " + CurrentSection_.ToString(); } Debug.Log(text); } }
void UpdateTiming() { // find section index int newIndex = sectionIndex_; int oldSample = currentSample_; currentSample_ = musicSource_.timeSamples; if (sectionIndex_ + 1 >= Sections.Count) { if (currentSample_ < oldSample) { newIndex = 0; } } else { if (Sections[sectionIndex_ + 1].StartTimeSamples <= currentSample_) { newIndex = sectionIndex_ + 1; } } if (newIndex != sectionIndex_) { sectionIndex_ = newIndex; OnSectionChanged(); } // calc current timing isNearChanged_ = false; isJustChanged_ = false; int sectionSample = currentSample_ - CurrentSection_.StartTimeSamples; if (sectionSample >= 0) { just_.Bar = (int)(sectionSample / samplesPerBar_) + CurrentSection_.StartTiming.Bar; just_.Beat = (int)((sectionSample % samplesPerBar_) / samplesPerBeat_) + CurrentSection_.StartTiming.Beat; just_.Unit = (int)(((sectionSample % samplesPerBar_) % samplesPerBeat_) / samplesPerUnit_) + CurrentSection_.StartTiming.Unit; just_.Fix(CurrentSection_); if (sectionIndex_ + 1 >= Sections.Count) { if (numLoopBar_ > 0) { while (just_.Bar >= numLoopBar_) { just_.Decrement(CurrentSection_); } } } else { while (just_ >= Sections[sectionIndex_ + 1].StartTiming) { just_.Decrement(CurrentSection_); } } just_.Subtract(CurrentSection_.StartTiming, CurrentSection_); timeSecFromJust_ = (double)(sectionSample - just_.Bar * samplesPerBar_ - just_.Beat * samplesPerBeat_ - just_.Unit * samplesPerUnit_) / (double)samplingRate_; isFormerHalf_ = (timeSecFromJust_ * samplingRate_) < samplesPerUnit_ / 2; just_.Add(CurrentSection_.StartTiming, CurrentSection_); near_.Copy(just_); if (!isFormerHalf_) { near_.Increment(CurrentSection_); } if (samplesInLoop_ != 0 && currentSample_ + samplesPerUnit_ / 2 >= samplesInLoop_) { near_.Init(); } isNearChanged_ = (near_.Equals(oldNear_) == false); isJustChanged_ = (just_.Equals(oldJust_) == false); CallEvents(); oldNear_.Copy(near_); oldJust_.Copy(just_); } if (DebugText != null) { DebugText.text = "Just = " + Just.ToString() + ", MusicalTime = " + MusicalTime_; if (Sections.Count > 0) { DebugText.text += System.Environment.NewLine + "section[" + sectionIndex_ + "] = " + CurrentSection_.ToString(); } } }