Esempio n. 1
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" );
        }
    }
Esempio n. 2
0
    void UpdateTiming()
    {
        isNowChanged_  = false;
        isJustChanged_ = false;

        if (SectionIndex < 0 || sections.Count <= SectionIndex)
        {
            Debug.LogWarning("Music:" + name + " has invalid SectionIndex = " + SectionIndex + ", sections.Count = " + sections.Count);
            return;
        }
        long numSamples = MusicSource.GetTimeSamples();


        int NewIndex = -1;

        for (int i = SectionIndex; i < sections.Count; i++)
        {
            if (sections[i].StartTimeSamples_ <= numSamples && (sections.Count <= i + 1 || numSamples < sections[i + 1].StartTimeSamples_))
            {
                NewIndex = i;
                break;
            }
        }
        if (NewIndex < 0)
        {
            if (0 <= numSamples && numSamples < delayTimeSamples)
            {
                NewIndex = 0;
                Initialize();
                OnSectionChanged();
            }
            else
            {
                for (int i = 0; i < SectionIndex; i++)
                {
                    if (sections[i].StartTimeSamples_ <= numSamples && numSamples < sections[i + 1].StartTimeSamples_)
                    {
                        NewIndex = i;
                    }
                }
            }
        }

        if (NewIndex != SectionIndex)
        {
            SectionIndex = NewIndex;
            OnSectionChanged();
        }

        numSamples -= CurrentSection_.StartTimeSamples_;
        if (numSamples >= 0)
        {
            Just_.bar  = (int)(numSamples / SamplesPerBar) + CurrentSection_.StartTiming_.bar;
            Just_.beat = (int)((numSamples % SamplesPerBar) / SamplesPerBeat) + CurrentSection_.StartTiming_.beat;
            Just_.unit = (int)(((numSamples % SamplesPerBar) % SamplesPerBeat) / SamplesPerUnit) + CurrentSection_.StartTiming_.unit;
            if (Just_.unit >= CurrentSection_.mtBeat_)
            {
                Just_.beat += (int)(Just_.unit / CurrentSection_.mtBeat_);
                Just_.unit %= CurrentSection_.mtBeat_;
            }
            int barUnit = Just_.beat * CurrentSection_.mtBeat_ + Just_.unit;
            if (barUnit >= CurrentSection_.mtBar_)
            {
                Just_.bar += (int)(barUnit / CurrentSection_.mtBar_);
                Just_.beat = 0;
                Just_.unit = (barUnit % CurrentSection_.mtBar_);
                if (Just_.unit >= CurrentSection_.mtBeat_)
                {
                    Just_.beat += (int)(Just_.unit / CurrentSection_.mtBeat_);
                    Just_.unit %= CurrentSection_.mtBeat_;
                }
            }
            if (NumLoopBar > 0)
            {
                Just_.bar %= NumLoopBar;
            }

            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" );
        }

        DebugUpdateText();
    }