Beispiel #1
0
    /// <summary>
    /// What timing option for the current beat/subdivision is valid for the input time?
    /// Will throw an exception if the timing option couldn't be found.
    /// Ya gotta configure your options correctly bud.
    /// </summary>
    /// <param name="theTime">The input time that you want to get the option for.</param>
    /// <param name="currentBeat">The current time of the beat</param>
    /// <returns>the timing option that is for the input time</returns>
    private TimingOption GetTimingOption(double theTime, double currentBeat)
    {
        double timeMinusLatency = GetLatencyTime(theTime);
        double beatToCompareTo;
        double beatTimeFrame = secsPerBeat;

        if (timingCalculation.Equals(TimingCalculations.Subdivision) && subdivisionsPerBeat > 1)
        {
            // if we should use subdivisions
            beatToCompareTo = GetCurrentSubdivision(timeMinusLatency, currentBeat, secsPerBeat);
            beatTimeFrame   = TempoUtils.GetSubdivisionWindow(secsPerBeat, subdivisionsPerBeat);
        }
        else if (timingCalculation.Equals(TimingCalculations.Pattern))
        {
            // if we should use the pattern given
            beatToCompareTo = TempoUtils.GetBeatToCompareTo(timeMinusLatency, currentBeat, secsPerBeat);

            /*
             * so we need to find out the subdivisions per beat
             * then we can map that to the beat of the song
             */
        }
        else if (timingCalculation.Equals(TimingCalculations.Song))
        {
            // if we should return the timing option of the song
            // man this means we'll have to keep track of where we are in the song
            beatToCompareTo = TempoUtils.GetBeatToCompareTo(timeMinusLatency, currentBeat, secsPerBeat);
        }
        else
        {
            // if we should use the beat
            beatToCompareTo = TempoUtils.GetBeatToCompareTo(timeMinusLatency, currentBeat, secsPerBeat);
        }

        foreach (TimingOption option in timingOptions)
        {
            foreach (TimingWindow window in option.windows)
            {
                if (TempoUtils.IsInWindow(timeMinusLatency, beatToCompareTo,
                                          window.window * beatTimeFrame,
                                          window.beatOffset * beatTimeFrame))
                {
                    return(option);
                }
            }
        }

        throw new System.Exception("Timing Option was not found for beat! Please ensure that your timing options cover the entire beat!");
    }
Beispiel #2
0
    /// <summary>
    /// Will retrieve all of the times of the subdivision of the current beat,
    /// and loop through them to find the one that is closest to the input time.
    /// </summary>
    /// <param name="currentBeat">The current beat to retrieve subdivisions from</param>
    /// <returns>the time of the subdivision that the input time is closest to</returns>
    private double GetCurrentSubdivision(double inputTime, double currentBeat, double secondsPerBeat)
    {
        List <double> subdivTimes = TempoUtils.GetSubdivisionTimes(currentBeat, secsPerBeat, subdivisionsPerBeat);

        for (int i = 0; i < subdivTimes.Count - 1; i++)
        {
            if (TempoUtils.IsInWindow(inputTime, subdivTimes[i], subdivTimes[i + 1]))
            {
                return(TempoUtils.GetBeatToCompareTo(inputTime, subdivTimes[i], TempoUtils.GetSubdivisionWindow(secondsPerBeat, subdivisionsPerBeat)));
            }
        }

        string errorMsg = "Can't find the subdivision! Input Time was: " + inputTime;

        errorMsg += "\n subdivisions were: ";
        foreach (double subdiv in subdivTimes)
        {
            errorMsg += "\n" + subdiv;
        }

        Debug.LogError(errorMsg);
        return(0);
        // throw new System.Exception(errorMsg);
    }