// Use this for initialization void Start() { song = GetComponent <AudioSource> (); outro.end = song.clip.length; sections.Add(intro); sections.AddRange(loopMarkers); sections.Add(outro); currentSection = sections[currentSectionIndex]; start = intro.start; song.time = start; }
void SongControls() { if (song.time <= 0.03f) { song.time = start; } if (Input.GetKeyDown(KeyCode.Comma)) { rewind = true; } if (Input.GetKeyDown(KeyCode.Period)) { fastforward = true; } if (rewind) { song.pitch = Mathf.Lerp(song.pitch, -3, Time.deltaTime * 2); if (song.pitch <= -2.9f) { if ((currentSectionIndex > 0)) { currentSectionIndex--; } currentSection = sections [currentSectionIndex]; song.time = currentSection.start; song.pitch = 1; rewind = false; } } if (fastforward) { song.pitch = Mathf.Lerp(song.pitch, 3, Time.deltaTime * 2); if (song.pitch >= 2.9f) { if ((currentSectionIndex < sections.Count)) { currentSectionIndex++; } currentSection = sections [currentSectionIndex]; song.time = currentSection.end; song.pitch = 1; fastforward = false; } } }
public void TriggerMusicSequence(LoopSequenceTrigger aTrigger) { LoopSequence loopSequence = loopSequences.Find(x => x.sequences.Exists(y => y.trigger == aTrigger)); if (loopSequences == null) { return; } List <MusicLooper.PlayingTrack> playingTracks = musicLooper.activeTracks; currentTracksForSequence.Clear(); currentTracksToRemove.Clear(); AddSequenceTracks(loopSequence, aTrigger); musicLooper.SetBaseTrack(loopSequence.baseLoop); currentLoopSequence = loopSequence; for (int i = playingTracks.Count - 1; i >= 0; --i) { MusicLooper.PlayingTrack playingTrack = playingTracks[i]; if (!currentTracksForSequence.Exists(x => x == playingTrack.loopTrack)) { if (playingTrack.isPlaying && !playingTrack.isChanging) { currentTracksToRemove.Add(playingTrack.loopTrack); musicLooper.StopTrack(playingTrack.loopTrack); } else { musicLooper.RemoveTrack(playingTrack.loopTrack); } } } if (currentTracksToRemove.Count == 0) { PlaySequenceTracks(); } else { musicLooper.onLoopStopped += OnLoopStopped; } }
void AddSequenceTracks(LoopSequence aSequence, LoopSequenceTrigger aTrigger) { List <MusicLooper.PlayingTrack> playingTracks = musicLooper.activeTracks; foreach (LoopSequence.Sequence sequence in aSequence.sequences) { foreach (LoopTrack track in sequence.loops) { if (!playingTracks.Exists(x => x.loopTrack == track)) { musicLooper.AddTrack(track); } currentTracksForSequence.Add(track); } if (sequence.trigger == aTrigger) { break; } } }