public void ReceiveTempoInMiliseconds(double interval) { tempoFound = true; tempo.SetTempo(interval); tempo.SetLatencyMilliseconds(50); tempo.StartTempo(); Debug.Log("BPM: " + TempoUtils.FlipBpmInterval(interval)); TempoStartInformer.GetInstance().ReceiveTempo(interval); }
private void Start() { if (beat == null) { beat = new UnityEvent(); } SetTempo(TempoUtils.FlipBpmInterval(BPM)); StartTempo(); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } bpm = audioSource.GetComponent <BeatSynchronizer>().bpm; }
private void PlayMusic() { // do calculations and set everything up double bpm = TempoUtils.FlipBpmInterval(secsPerBeat); MusicClip clip = GetClip(bpm); currentSong.clip = clip.clip; currentSong.pitch = (float)TempoUtils.GetPitchModifierFromBpm(bpm, clip.bpm); currentSong = SoundUtils.MakeSource(currentSong, GetAudioSource()); currentSong.source.PlayDelayed((float)(AudioSettings.dspTime - (manager.GetCurrentBeatTime() + secsPerBeat))); }
private bool IsTappingUniform() { // .1 each side of the avg double avg = GetSecondsInterval(); bool uniform = true; double upperWindow = TempoUtils.FlipBpmInterval(TempoUtils.FlipBpmInterval(avg) + TAP_WINDOW); double lowerWindow = TempoUtils.FlipBpmInterval(TempoUtils.FlipBpmInterval(avg) - TAP_WINDOW); foreach (double i in tapIntervals) { uniform = uniform && (i <lowerWindow && i> upperWindow); } return(uniform); }
/// <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!"); }
/// <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); }
/// <summary> /// Sets the latency of the tempo in milliseconds. For calculating the timing options. /// </summary> /// <param name="theLatency">the latency in milliseconds</param> public void SetLatencyMilliseconds(double theLatency) { latency = TempoUtils.GetSecondsFromMilliseconds(theLatency); }
private void UpdateText(bool hasBpm) { text.text = BPM_DISPLAY + (hasBpm ? UNKNOWN : System.Math.Round(TempoUtils.FlipBpmInterval(secondsPerBeat), 1).ToString()); }