public void PlayMusic(MusicClip clip) { Debug.Log("Index:" + (int)clip + " name:" + clip.ToString()); Debug.Log("Array length" + _musicArray.Length); musicSource.clip = _musicArray[(int)clip]; musicSource.Play(); }
private void GenerateTutorialClips() { ChordProgression chordProgression = chordProgressionLibrary.GetFirstChordProgression(); Rhythm rhythm = GetRandomEnum <Rhythm>(); Tempo tempo = GetRandomEnum <Tempo>(); Key key = GetRandomEnum <Key>(); for (int i = 0; i < loopCount; i++) { for (int j = 0; j < 2; j++) { MusicalChange change = GetRandomMusicalChange(); if (change == MusicalChange.Tempo) { tempo = GetRandomEnumOtherThan(tempo); } else { rhythm = GetRandomEnumOtherThan(rhythm); } int chordIndex = 0; for (int k = 0; k < 4; k++) { PercussionMusicClip percussionClip = percussionClipLibrary.GetRandomClipWithRhythmAndTempo(rhythm, tempo); InputMusicClip inputClip = inputClipLibrary.GetClipWithInstrumentAndChord( Instrument.ElectricGuitar, KeyNotationToChordHelper.GetChord(key, chordProgression.chords[chordIndex])); MusicClip clip = new MusicClip(percussionClip, inputClip, null); musicMixer.QueueClip(clip); chordIndex++; } } } }
public MusicClip Play(string musicName, float startTime = -1.0f) { if (string.IsNullOrEmpty(musicName)) { return(null); } MusicClip music = null; foreach (var c in clips) { if (ClipsMatch(musicName, c.name)) { music = c; break; } } if (music == null) { Debug.LogWarning("Couldn't find music " + musicName); return(null); } return(Play(music, startTime)); }
public void Play(MusicClip clip, float fadeTime = 0f, float delay = 0f, float volume = 1f, float startTime = 0f) { if (!enabled) { return; } _gameAudio.Play(clip, fadeTime, delay, volume, startTime); }
public bool CheckPlay(MusicClip m) { bool play = true; if(this.currentMusic != null && m.realID == this.currentMusic.realID && this.currentPlaying > 0 && !this.currentMusic.fadeOut) { play = false; } return play; }
void OnTriggerExit2D(Collider2D collision) { if (!collision.CompareTag("Player")) { return; } MusicClip mc = new MusicClip(previousTheme, exitRandom); Audio.Play(mc); }
void OnTriggerEnter2D(Collider2D collision) { if (!collision.CompareTag("Player")) { return; } previousTheme = Audio.currentMusic; MusicClip mc = new MusicClip(localTheme, enterRandom); Audio.Play(mc); }
public void FadeMusicClip(MusicClip music, float fadeTime = -1f) { if (fadeTime < 0f) { fadeTime = defaultFadeTime; } music.fadeInc = 0f - (Mathf.Max(0.01f, fadeTime) / Time.unscaledDeltaTime); if (music.volume < music.fadeInc && music.fadeInc > 0f) { music.volume = music.fadeInc; } }
public void PlayMainMenuMusic() { if (_currentSong == MusicClip.MainMenuTheme) { return; } _currentSong = MusicClip.MainMenuTheme; musicPlayer.clip = mainMenuMusic; musicPlayer.loop = true; musicPlayer.Play(); }
private IEnumerator ChangeChord(MusicClip scheduledClip, double startingTime) { while (AudioSettings.dspTime < startingTime) { yield return(null); } string newChordName = CHORD + scheduledClip.InputClip.Chord.ToString(); animator.SetTrigger(Animator.StringToHash(newChordName)); animator.SetFloat(ROCK_SPEED_HASH, TempoToBPMHelper.GetBPM(scheduledClip.PercussionClip.Tempo) / TempoToBPMHelper.GetBPM(BASE_TEMPO)); }
public void QueueClip(MusicClip musicClip) { if (clipQueue.Count == 0) { SetStartTime(); } clipQueue.Enqueue(musicClip); double queuedClipStartTime = CalculateQueuedClipStartTime(); ClipQueuedEvent?.Invoke(musicClip, queuedClipStartTime); }
public void PlayCinematicMusic() { if (_currentSong == MusicClip.OpeningTheme) { return; } _currentSong = MusicClip.OpeningTheme; musicPlayer.clip = cinematicMusic; musicPlayer.loop = true; musicPlayer.Play(); }
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))); }
public void ChangeMusic(MusicClip input) { if (input == currentMusic) { return; } currentMusic = input; if (musicTransition != null) { StopCoroutine(musicTransition); } musicTransition = FadeTracks(input); StartCoroutine(musicTransition); }
public void Load(MusicClip musicClip, Playable owner, PlayableGraph graph) { Clip = musicClip; owner.SetInputCount(1); mixer = AudioMixerPlayable.Create(graph, musicClip.ClipLayers.Length); graph.Connect(mixer, 0, owner, 0); owner.SetInputWeight(0, 1); inputPlayables = new AudioClipPlayable[musicClip.ClipLayers.Length]; for (int i = 0; i < musicClip.ClipLayers.Length; i++) { inputPlayables[i] = AudioClipPlayable.Create(graph, musicClip.ClipLayers[i].Clip, false); graph.Connect(inputPlayables[i], 0, mixer, i); mixer.SetInputWeight(i, i == 0 ? 1f : 0f); } }
public void FadeTo(MusicClip m, float time, EaseType type) { if(this.currentPlaying == 0) { this.FadeIn(m, time, type); } else if(this.CheckPlay(m)) { if(this.currentPlaying == 3) { this.sourceA.Stop(); this.currentPlaying = 2; } else if(this.currentPlaying == 4) { this.sourceB.Stop(); this.currentPlaying = 1; } this.lastMusic = this.currentMusic; this.currentMusic = m; this.lastMusic.FadeOut(time, type); this.currentMusic.FadeIn(time, type); if(this.currentPlaying == 1) { this.sourceB.clip = this.currentMusic.GetClip(); this.sourceB.volume = 0; this.sourceB.loop = this.currentMusic.loop; this.sourceB.Play(); this.currentPlaying = 3; } else if(this.currentPlaying == 2) { this.sourceA.clip = this.currentMusic.GetClip(); this.sourceA.volume = 0; this.sourceA.loop = this.currentMusic.loop; this.sourceA.Play(); this.currentPlaying = 4; } if(this.currentMusic.HasLoops()) { this.ticking = true; this.DoTick(); } } }
public MusicClip GetCopy(int index) { MusicClip m = new MusicClip(); m.realID = index; m.clipName = music[index].clipName; m.maxVolume = music[index].maxVolume; m.loop = music[index].loop; m.checkTime = new float[music[index].checkTime.Length]; m.setTime = new float[music[index].setTime.Length]; for(int i=0; i<m.checkTime.Length; i++) { m.checkTime[i] = music[index].checkTime[i]; m.setTime[i] = music[index].setTime[i]; } return m; }
private void OnClipScheduledEvent(MusicClip scheduledClip, double startingTime) { nextInputWindows.Clear(); nextId = scheduledClip.ID; if (scheduledClip.PercussionClip.ButtonTimings != null) { foreach (ButtonTiming buttonTiming in scheduledClip.PercussionClip.ButtonTimings) { double min = startingTime + (scheduledClip.Duration * buttonTiming.Timing) - inputWindowLeniency; double max = Mathf.Min((float)(startingTime + (scheduledClip.Duration * buttonTiming.Timing) + inputWindowLeniency), (float)(startingTime + scheduledClip.Duration)); nextInputWindows.Add(new InputWindow(min, max, buttonTiming.ButtonID)); } } StartCoroutine(ClipStarting(scheduledClip, startingTime)); }
public void OnBeatUpdate() { MusicClip clip = MusicBox.CurrentClip; if (clip != lastClip) { lastClip = clip; } int numBeats = clip.Endings.Last().InBeats(clip.BeatsPerBar); MusicClip.MusicLocation musicLocation = MusicBox.MusicLocation; var timeView = new StringBuilder(); var beatView = new StringBuilder(); var alignView = new StringBuilder(); var loopView = new StringBuilder(); int beginningBeat = clip.Beginning.InBeats(clip.BeatsPerBar) - 1; int[] endingBeats = clip.Endings.Select(e => e.InBeats(clip.BeatsPerBar) - 1).ToArray(); int introBeat = clip.IntroEnd.InBeats(clip.BeatsPerBar) - 1; int vampBeat = clip.VampEnd.InBeats(clip.BeatsPerBar) - 1; var beatIndex = musicLocation.InBeats(clip.BeatsPerBar) - 1; for (int i = 0; i <= numBeats; ++i) { if (i < numBeats) { timeView.Append(i == beatIndex ? '*' : '.'); beatView.Append(i % clip.BeatsPerBar == 0 ? '|' : '-'); } alignView.Append(beginningBeat == i ? 'B' : endingBeats.Contains(i) ? 'E' : ' '); loopView.Append(introBeat == i ? 'I' : vampBeat == i ? 'V' : ' '); } var result = new StringBuilder() .Append(" Time: ").AppendLine(timeView.ToString()) .Append(" Clip: ").AppendLine(string.IsNullOrWhiteSpace(clip.Name) ? "(unnamed)" : clip.Name) .Append($"Channel: ").AppendLine(beatView.ToString()) .Append(" align: ").AppendLine(alignView.ToString()) .Append(" loop: ").AppendLine(loopView.ToString()) .AppendLine($" bar: {musicLocation.Bar}") .AppendLine($" beat: {musicLocation.Beat}") .AppendLine($"index: {beatIndex}") ; TextToUpdate.text = result.ToString(); }
private void OnClipScheduledEvent(MusicClip scheduledClip, double startingTime) { if (!gameObject.activeSelf) { return; } if (!isRocking) { StartCoroutine(Rock(startingTime)); } if (scheduledClip.InputClip != null) { StartCoroutine(ChangeChord(scheduledClip, startingTime)); } }
// Update is called once per frame void Update() { if (!isPlaying) { return; } double time = AudioSettings.dspTime; if (time + 1.0F > nextEventTime) { MusicClip musicClip = track.GetNextClip(); audioSources[flip].clip = musicClip.Clip; audioSources[flip].PlayScheduled(nextEventTime); nextEventTime += musicClip.LengthInSeconds; flip = 1 - flip; } }
private void HandleMusicalChange(MusicClip nextClip, double time) { if (cachedClip == null) { return; } if (cachedClip.PercussionClip.Tempo != nextClip.PercussionClip.Tempo) { colorFlip = !colorFlip; InstantiateChangeIndicator(colorFlip ? noteColor1 : noteColor2, $"Tempo Change", time); } else if (cachedClip.PercussionClip.Rhythm != nextClip.PercussionClip.Rhythm) { colorFlip = !colorFlip; InstantiateChangeIndicator(colorFlip ? noteColor1 : noteColor2, $"Rhythm Change", time); } }
public void Play(MusicClip clip, float fadeTime = 0f, float delay = 0f, float volume = 1f, float startTime = 0f) { if (!enabled) { return; } var audioClip = MusicClips[(uint)clip]; var audioSource = LeanAudio.play(audioClip, 0f, delay, true, startTime); LeanTween.value(0f, volume, fadeTime) .setDelay(delay) .setEase(LeanTweenType.easeInOutSine) .setOnUpdate(v => { audioSource.volume = v; }); }
private void OnClipQueuedEvent(MusicClip queuedClip, double startingTime) { if (!firstClipQueued) { firstClipQueued = true; } HandleMusicalChange(queuedClip, startingTime); AddBar(startingTime, queuedClip.Duration); if (cachedClip != null) { InstantiateSeparatorLine(startingTime); } cachedClip = queuedClip; }
private IEnumerator ClipStarting(MusicClip scheduledClip, double scheduledTime) { while (AudioSettings.dspTime < scheduledTime - CLIP_CHANGE_WINDOW) { yield return(null); } if (activeClipResults != null) { ClipFinishedCleanup(); } activeClipResults = new MusicClipResults(scheduledTime, scheduledClip.PercussionClip.Rhythm, scheduledClip.PercussionClip.Tempo); currentInputWindows = nextInputWindows; if (scheduledClip.InputClip != null) { middleButton.SetInstrumentSounds(scheduledClip.InputClip.AudioClips); } }
MusicClip FindMusic(StageGame stage) { List <MusicClip> clips = new List <MusicClip>(); clips.AddRange(MusicList.ToArray()); while (clips.Count > 0) { MusicClip clip = clips[UnityEngine.Random.Range(0, clips.Count)]; if (clip.stage == stage) { return(clip); } else { clips.Remove(clip); } } return(new MusicClip()); }
public IEnumerator PlayBattleTheme() { if (_currentSong == MusicClip.BattleTheme) { yield break; } _currentSong = MusicClip.BattleTheme; musicPlayer.clip = battleIntroMusic; musicPlayer.loop = false; musicPlayer.Play(); while (musicPlayer.isPlaying) { yield return(null); } musicPlayer.clip = battleMusic; musicPlayer.loop = true; musicPlayer.Play(); }
public void FadeIn(MusicClip m, float time, EaseType type) { if(this.CheckPlay(m)) { this.sourceA.Stop(); this.sourceB.Stop(); this.lastMusic = this.currentMusic; this.currentMusic = m; this.sourceA.clip = this.currentMusic.GetClip(); this.sourceA.volume = 0; this.sourceA.loop = this.currentMusic.loop; this.currentMusic.FadeIn(time, type); this.sourceA.Play(); this.currentPlaying = 1; if(this.currentMusic.HasLoops()) { this.ticking = true; this.DoTick(); } } }
IEnumerator FadeTracks(MusicClip input) { AudioSource ads = GetComponent <AudioSource>(); // Fade out; if (!ads.isPlaying) { ads.volume = 0; } while (ads.volume > 0) { ads.volume -= Time.deltaTime * Audio.fadeSpeed; if (ads.volume < 0) { ads.volume = 0; } yield return(null); } if (input == null) { ads.Pause(); yield break; } // Transition and fade in ads.pitch = input.pitch; ads.clip = AudioDB.GetClip(input).GetClip(); ads.time = input.startRandom ? Random.Range(0, ads.clip.length) : 0; ads.Play(); while (ads.volume < input.volume) { ads.volume += Time.deltaTime * Audio.fadeSpeed; if (ads.volume > input.volume) { ads.volume = input.volume; } yield return(null); } }
private void ScheduleNextClipPlay() { MusicClip nextClip = clipQueue.Dequeue(); if (nextClip.PercussionClip.AudioClip == null) { percussionAudioSources[flip].clip = null; } else { percussionAudioSources[flip].clip = nextClip.PercussionClip.AudioClip; percussionAudioSources[flip].PlayScheduled(nextEventTime); } for (int i = 0; i < nextClip.LayerClips?.Length; i++) { if (i >= MAX_LAYERED_CLIPS) { Debug.LogError($"Too many Layered Clips"); break; } if (flip == 0) { layerAudioSources[i].clip = nextClip.LayerClips[i].AudioClip; layerAudioSources[i].PlayScheduled(nextEventTime); } else { layerAudioSourcesFlipped[i].clip = nextClip.LayerClips[i].AudioClip; layerAudioSourcesFlipped[i].PlayScheduled(nextEventTime); } } ClipScheduledEvent?.Invoke(nextClip, nextEventTime); nextEventTime += nextClip.Duration; flip = 1 - flip; }
public MusicClip Play(MusicClip music, float startTime = -1.0f) { int playingIndex = musicStack.IndexOf(music); if (music == activeMusic && music.isPlaying) { if (startTime >= 0f) { music.source.time = startTime; } return(music); } if (music.source == null) { music.source = GetNextSource(); music.source.loop = true; } if (music.source.isPlaying) { music.source.Stop(); } music.source.clip = music.clip; music.source.time = startTime >= 0.0f ? startTime : 0.0f; music.fadeInc = 0f; music.volume = 1f; music.pauseTime = 0f; music.source.Play(); foreach (var m in musicStack) { FadeMusicClip(m, 0.5f); } musicStack.Add(music); return(music); }
public void LoadAndPlay(MusicClip musicClip, Playable owner, PlayableGraph graph) { owner.SetInputCount(1); mixer = AudioMixerPlayable.Create(graph, musicClip.ClipLayers.Length); mixer.SetInputCount(musicChannels.Count + 1); var nextMusicChannelPlayable = ScriptPlayable <MusicChannel> .Create(graph); var nextMusicChannel = nextMusicChannelPlayable.GetBehaviour(); currentTime = 0; var leadTime = musicClip.Beginning.InSeconds(musicClip.BeatsPerBar, musicClip.BPM); channelCutOverTime = musicChannels.Count == 0 ? double.MinValue : musicChannels.First.Value.NextEnding(leadTime); channelPlayTime = musicChannels.Count == 0 ? double.MinValue : channelCutOverTime - leadTime; musicChannels.AddLast(nextMusicChannel); for (int i = 0; i < musicChannels.Count + 1; i++) { graph.Connect(mixer, 0, owner, 0); graph.Connect(nextMusicChannelPlayable, 0, mixer, i); mixer.SetInputWeight(i, 1); } }
public static void PlayMusic(MusicClip clip) { switch (clip) { case MusicClip.MenuLoop: { s_Instance.m_MusicSource.clip = s_Instance.m_MenuLoop; break; } case MusicClip.InGameLoop: { s_Instance.m_MusicSource.clip = s_Instance.m_InGameLoop; break; } default: break; } s_Instance.m_MusicSource.Play(); }
public void LoadClip(MusicClip clip) { MusicClip = clip; // ensure there are enough audiosources for the music clip while (audioSources.Count < clip.ClipLayers.Length) { var audioSource = parent.gameObject.AddComponent <AudioSource>(); audioSources.Add(audioSource); audioSource.loop = false; audioSource.outputAudioMixerGroup = audioMixerGroup; audioSource.playOnAwake = false; } // set all audiosources to the correct audio clips, or null if it's an extra audiosource for (int i = 0; i < audioSources.Count; ++i) { audioSources[i].Stop(); // for safety audioSources[i].clip = clip.ClipLayers.Length > i ? clip.ClipLayers[i].Clip : null; } // notify parent.OnClipScheduled.Invoke(); }
public void LoadData() { ArrayList data = XMLHandler.LoadXML(dir+filename); if(data.Count > 0) { foreach(Hashtable entry in data) { if(entry[XMLHandler.NODE_NAME] as string == MusicData.MUSIC) { if(entry.ContainsKey(XMLHandler.NODES)) { ArrayList subs = entry[XMLHandler.NODES] as ArrayList; name = new string[subs.Count]; music = new MusicClip[subs.Count]; foreach(Hashtable val in subs) { if(val[XMLHandler.NODE_NAME] as string == MusicData.CLIP) { int i = int.Parse((string)val["id"]); music[i] = new MusicClip(); music[i].maxVolume = float.Parse((string)val["maxvol"]); if(val.ContainsKey("loop")) music[i].loop = true; int count = int.Parse((string)val["loops"]); music[i].checkTime = new float[count]; music[i].setTime = new float[count]; ArrayList s = val[XMLHandler.NODES] as ArrayList; foreach(Hashtable ht in s) { if(ht[XMLHandler.NODE_NAME] as string == MusicData.RESOURCE) { music[i].clipName = ht[XMLHandler.CONTENT] as string; } else if(ht[XMLHandler.NODE_NAME] as string == MusicData.NAME) { name[i] = ht[XMLHandler.CONTENT] as string; } else if(ht[XMLHandler.NODE_NAME] as string == MusicData.LOOP) { int j = int.Parse((string)ht["id"]); music[i].checkTime[j] = float.Parse((string)ht["check"]); music[i].setTime[j] = float.Parse((string)ht["set"]); } } } } } } } } }
public void StoreCurrent() { this.storedMusic = this.currentMusic; if(this.currentPlaying == 1 || this.currentPlaying == 4) this.storedTime = this.sourceA.time; else if(this.currentPlaying == 2 || this.currentPlaying == 3) this.storedTime = this.sourceB.time; }
public void Play(MusicClip m) { if(this.CheckPlay(m)) { this.sourceA.Stop(); this.sourceB.Stop(); this.lastMusic = this.currentMusic; this.currentMusic = m; this.sourceA.clip = this.currentMusic.GetClip(); this.sourceA.volume = this.currentMusic.maxVolume; this.sourceA.loop = this.currentMusic.loop; this.sourceA.Play(); this.currentPlaying = 1; if(this.currentMusic.HasLoops()) { this.ticking = true; this.DoTick(); } } }
public static MusicClip[] Add(MusicClip n, MusicClip[] list) { ArrayList tmp = new ArrayList(); foreach(MusicClip str in list) tmp.Add(str); tmp.Add(n); return tmp.ToArray(typeof(MusicClip)) as MusicClip[]; }
public static MusicClip[] Remove(int index, MusicClip[] list) { ArrayList tmp = new ArrayList(); foreach(MusicClip str in list) tmp.Add(str); tmp.RemoveAt(index); return tmp.ToArray(typeof(MusicClip)) as MusicClip[]; }