示例#1
0
    void UpdateTiming()
    {
        oldNear_.Set(near_);
        oldJust_.Set(just_);
        isNearChanged_ = false;
        isJustChanged_ = false;
        isJustLooped_  = false;
        isNearLooped_  = false;

        int oldSequenceIndex = SequenceIndex;

        UpdateTimingInternal();
        CalcTimingAndFraction(ref just_, out fractionFromJust_);

        if (currentMeter_ != null)
        {
            while (sequenceEndTiming_ != null && just_ >= sequenceEndTiming_)
            {
                just_.Decrement(currentMeter_);
                fractionFromJust_ = 1.0f;
            }

            isFormerHalf_ = fractionFromJust_ < 0.5f;

            near_.Set(just_);
            if (!isFormerHalf_)
            {
                near_.Increment(currentMeter_);
            }
            if (sequenceEndTiming_ != null && near_ >= sequenceEndTiming_)
            {
                near_.Reset();
            }

            isJustChanged_ = (just_.Equals(oldJust_) == false);
            isNearChanged_ = (near_.Equals(oldNear_) == false);
            isJustLooped_  = isJustChanged_ && just_ < oldJust_;
            isNearLooped_  = isNearChanged_ && near_ < oldNear_;

            if (isJustLooped_)
            {
                if (oldSequenceIndex != SequenceIndex)
                {
                    OnHorizontalSequenceChanged();
                }
                else if (SequenceIndex != -1)
                {
                    OnRepeated();
                }
            }
        }
    }
示例#2
0
    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);
        }
    }
示例#3
0
    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();
            }
        }
    }