public void Init(string p_clip) { SetNextLoop(p_clip); if (Metronome.Instance.ready) { Debug.Log("Error: cannot call StartMusic when metro is already ticking, call StopMusic first"); return; } Metronome.Instance.SetBPM(100.0f); Metronome.Instance.ready = true; nextPlay = new NotationTime(Metronome.Instance.currentTime); nextPlay.AddTick(); HandleTickChange(Metronome.Instance.currentTime); Metronome.tickChangeDelegate += HandleTickChange; }
public void PlayCircleDestroy() { NotationTime nextPlay = new NotationTime(Metronome.Instance.currentTime); nextPlay.AddTick(); double nextPlayTime = Metronome.Instance.GetFutureTime(nextPlay); sources[currentSource].clip = explosions[0]; sources[currentSource].volume = 0.1f; sources[currentSource].pitch = 1.122462f; //up one tone sources[currentSource].PlayScheduled(nextPlayTime); currentSource++; if (currentSource == sources.Length) { currentSource = 0; } }
public void PlayCircleStart() { NotationTime nextPlay = new NotationTime(Metronome.Instance.currentTime); nextPlay.AddTick(); double nextPlayTime = Metronome.Instance.GetFutureTime(nextPlay); NoteChoice(); sources[currentSource].volume = 0.4f; sources[currentSource].pitch = 1.0f; sources[currentSource].PlayScheduled(nextPlayTime); currentSource++; if (currentSource == sources.Length) { currentSource = 0; } }
void Update() { // BPM++; samplesPerBar = (int)(sampleRate / (BPM / 60.0f)) * 4; samplesPerQuarter = samplesPerBar / 4; samplesPerTick = samplesPerQuarter / ticksPerQuarter; secondsPerTick = (double)samplesPerTick / (double)sampleRate; while (AudioSettings.dspTime > nextTickTime) { lastTickTime = nextTickTime; nextTickTime = lastTickTime + secondsPerTick; currentTick++; currentTime.AddTick(); if (tickChangeDelegate != null) { tickChangeDelegate(currentTime); } if (currentTick == ticksPerQuarter - 1) { if (quarterChangeDelegate != null) { quarterChangeDelegate(currentTime); } if (currentQuarter == quartersPerBar - 1) { if (barChangeDelegate != null) { barChangeDelegate(currentTime); } } } if (currentTick == ticksPerQuarter) { currentTick = 0; currentQuarter++; } if (currentQuarter == quartersPerBar) { currentQuarter = 0; currentBar++; } } }