Exemplo n.º 1
0
    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)";
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        long numSamples;

        isNowChanged_  = false;
        isJustChanged_ = false;
#if ADX
        if (playback.GetStatus() != CriAtomExPlayback.Status.Playing)
        {
            return;
        }
        int tempOut;
        if (!playback.GetNumPlayedSamples(out numSamples, out tempOut))
        {
            numSamples = -1;
        }
#else
        if (!MusicSource.IsPlaying())
        {
            return;
        }
        numSamples = MusicSource.source.timeSamples;
#endif
        if (numSamples >= 0)
        {
            Just_.bar = (int)(numSamples / SamplesPerBar);
#if ADX
            UpdateNumBlockBar(numSamples);
            if (NumBlockBar != 0)
            {
                Just_.bar %= NumBlockBar;
            }
#else
            if (NumBar != 0)
            {
                Just_.bar %= NumBar;
            }
#endif
            Just_.beat    = (int)((numSamples % SamplesPerBar) / SamplesPerBeat);
            Just_.unit    = (int)((numSamples % SamplesPerBeat) / SamplesPerUnit);
            isFormerHalf_ = (numSamples % SamplesPerUnit) < SamplesPerUnit / 2;
            dtFromJust_   = (double)(numSamples % SamplesPerUnit) / (double)SamplingRate;

            Now_.Copy(Just_);
            if (!isFormerHalf_)
            {
                Now_.Increment();
            }
            if (SamplesInLoop != 0 && numSamples + SamplesPerUnit / 2 >= SamplesInLoop)
            {
                Now_.Init();
            }

            isNowChanged_  = Now_.totalUnit != OldNow.totalUnit;
            isJustChanged_ = Just_.totalUnit != OldJust.totalUnit;

            CallEvents();

            OldNow.Copy(Now_);
            OldJust.Copy(Just_);
        }
        else
        {
            //Debug.LogWarning( "Warning!! Failed to GetNumPlayedSamples" );
        }
    }