Exemple #1
0
 void PickUpBar()
 {
     state = State.PickUpBar;
     if (pickUpBarCounter > 0)
     {
         if (!onPickupBarBeginFired && OnPickupBarBegin != null)
         {
             OnPickupBarBegin(bar);
             onPickupBarBeginFired = true;
         }
         pickUpBarCounter--;
         TimeKeeper.BeatEvent(timeSignatureNumerator - pickUpBarCounter, timeSignatureNumerator, timeSignatureDenominator);
         pickUpCoroutine = this.FireAction(60f / bars [bar].tempo / (timeSignatureDenominator / 4f) / speed, PickUpBar);
     }
     else
     {
         CancelPickUpBarCounting();
         if (OnPickupBarEnd != null)
         {
             OnPickupBarEnd();
         }
         if (music && audioMusic)
         {
             audioMusic.Play();
         }
         if (vocals && audioVocals)
         {
             audioVocals.Play();
         }
         state = State.Playing;
     }
 }
    void UpdateTime()
    {
        deltaTime = deltaTimeResolution;

        periodResolution = PPQN * 1000f * deltaTime * MicrosecondsPerMillisecond;
        //ticksPerClock = PPQN / PPQNMinValue;
        deltaTicks       = (fractionalTicks + periodResolution) / tempoTicks;
        fractionalTicks += periodResolution - deltaTicks * tempoTicks;

        if (repeatBarSelection)
        {
            barTmp = bar;

            if (beatCount != (int)((ticks + deltaTicks) / PPQN / (4f / timeSignatureDenominator)) + 1)
            {
                if (beatCount % (int)timeSignatureNumerator + 1 == 1)
                {
                    barTmp++;
                }
            }

            if (barTmp > endBar + 1)
            {
                if (OnRepeat != null)
                {
                    OnRepeat(startBar);
                }

                cancelUpdate = true;
                SetBar(startBar, true, pickUpBarOnRepeat);
                return;
            }
        }

        if (beatCount != (int)(ticks / PPQN / (4f / timeSignatureDenominator)) + 1)
        {
            beat = beatCount % (int)timeSignatureNumerator + 1;

            if (beat == 1)
            {
                bar++;
            }

            beatCount = (int)(ticks / PPQN / (4f / timeSignatureDenominator)) + 1;

            if (metronome)
            {
                TimeKeeper.BeatEvent(beat, timeSignatureNumerator, timeSignatureDenominator);
            }
        }

        ticks += deltaTicks;
        time  += deltaTime;

        lastTime       = time;
        lastDeltaTime  = deltaTime;
        lastDeltaTicks = deltaTicks;
    }