private static BankData CreateBankDataItem(InMusicGroup node) { BankData data = new BankData(); data.MusicNode = node; return(data); }
public double GetRemainingTime(InMusicGroup musicGroup) { double maxTime = 0; var info = musicGroup.PlayingInfo; for (int i = 0; i < info.Players.Count; i++) { var source = musicGroup.PlayingInfo.Players[i]; double time = source.ExactTimeLength(); if (time / source.pitch > maxTime) { maxTime = time; } } for (int i = 0; i < musicGroup._children.Count; i++) { double time = GetRemainingTime(musicGroup); if (time > maxTime) { maxTime = time; } } return(maxTime); }
public void PlayWithFadeInAt(InMusicGroup musicGroup, float targetVolume, float duration, double dspTime, LeanTweenType tweenType = LeanTweenType.easeInOutQuad) { var parent = GetParent(musicGroup); PlayAt(parent, dspTime); SetVolume(parent, 0); Fade(parent, targetVolume, duration, tweenType, Time.time + Mathf.Max((float)(dspTime - AudioSettings.dspTime), 0)); }
public void PlayWithFadeIn(InMusicGroup musicGroup, float targetVolume, float duration, LeanTweenType tweenType = LeanTweenType.easeInOutQuad) { var parent = GetParent(musicGroup); Play(parent); SetVolume(parent, 0); Fade(parent, targetVolume, duration, tweenType, Time.time); }
private static void PlayMusicGroup(InMusicGroup toPlay, double playTime, int skipSamples) { var musicPool = InAudioInstanceFinder.InMusicPlayerPool; var mixer = toPlay.GetUsedMixerGroup(); toPlay.PlayingInfo.State = MusicState.Playing; var editorClips = toPlay._clips; int clipCount = editorClips.Count; var playingInfo = toPlay.PlayingInfo; playingInfo.State = MusicState.Playing; playingInfo.DoAtEnd = MusicState.Nothing; for (int j = 0; j < clipCount; j++) { var player = musicPool.GetObject(); toPlay.PlayingInfo.Players.Add(player); player.clip = editorClips[j]; player.loop = toPlay._loop; player.timeSamples = skipSamples; player.outputAudioMixerGroup = mixer; player.PlayScheduled(playTime); } for (int i = 0; i < toPlay._children.Count; i++) { PlayMusicGroup(toPlay._children[i] as InMusicGroup, playTime, skipSamples); } }
public void Pause(InMusicGroup musicGroup) { if (musicGroup == null) { return; } PausePlayers(GetParent(musicGroup)); }
public void Stop(InMusicGroup musicGroup) { var playingInfo = musicGroup.PlayingInfo; if (playingInfo != null) { StopPlayersNow(GetParent(musicGroup)); } }
public void Play(InMusicGroup toPlay) { if (toPlay == null) { Debug.LogError("InAudio: Cannot play Null Music group"); return; } PlayAt(GetParent(toPlay), AudioSettings.dspTime + 0.1f); }
private static InMusicGroup GetParent(InMusicGroup group) { if (group._parent.IsRootOrFolder) { return(group); } else { return(GetParent(group._parent as InMusicGroup)); } }
public static void AddNodeToBank(InMusicGroup node) { var bank = node.GetBank(); if (bank != null) { bank._bankData.Add(CreateBankDataItem(node)); EditorUtility.SetDirty(bank); } else { Debug.LogError("InAudio: Could not add node to bank as bank could not be found"); } }
private static bool HandleExcistingPlay(InMusicGroup musicGroup, ref PlayingMusicInfo playingInfo) { if (playingInfo.State == MusicState.Playing) { StopPlayersNow(musicGroup); } else if (playingInfo.State == MusicState.Paused) { UnpausePlayers(musicGroup); return(true); } return(false); }
public void PlayAt(InMusicGroup musicGroup, double absoluteDSPTime) { if (musicGroup == null) { Debug.LogError("InAudio: Cannot play 'Null' music group"); return; } var parent = GetParent(musicGroup); var playingInfo = parent.PlayingInfo; if (HandleExcistingPlay(parent, ref playingInfo)) return; double playTime = absoluteDSPTime; PlayMusicGroup(parent, playTime, 0); }
private static void DrawPlayStop(Rect fullArea, InMusicGroup group) { Rect butArea = fullArea; butArea.width = 16; butArea.height = 12; butArea.y += 3; butArea.x += EditorGUI.indentLevel * 5 - 10; Texture playing; if (Application.isPlaying) { playing = group.PlayingInfo.State == MusicState.Playing ? EditorResources.Instance.Pause : EditorResources.Instance.Play; } else { playing = EditorResources.Instance.Play; } if (GUI.Button(butArea, playing, GUIStyle.none)) { if (group.PlayingInfo.State == MusicState.Playing) { InAudio.Music.Pause(group); } else { InAudio.Music.Play(group); } } if (group.PlayingInfo.State == MusicState.Stopped || group.PlayingInfo.State == MusicState.Nothing) { GUI.enabled = false; } butArea.y += 14; Texture stop = EditorResources.Instance.Stop; if (GUI.Button(butArea, stop, GUIStyle.none)) { InAudio.Music.Stop(group); } GUI.enabled = true; }
private static void PausePlayers(InMusicGroup musicGroup) { var playingInfo = musicGroup.PlayingInfo; if (playingInfo.State == MusicState.Playing) { playingInfo.State = MusicState.Paused; var playing = playingInfo.Players; for (int i = 0; i < playing.Count; i++) { playing[i].Pause(); } } for (int i = 0; i < musicGroup._children.Count; i++) { PausePlayers(musicGroup._children[i] as InMusicGroup); } }
private static void StopPlayersAt(InMusicGroup musicGroup, double absoluteDSPTime) { var playingInfo = musicGroup.PlayingInfo; if (playingInfo.State != MusicState.Stopped) { var playing = playingInfo.Players; for (int i = 0; i < playing.Count; i++) { playing[i].SetScheduledEndTime(absoluteDSPTime); //cleanup happens in MusicUpdater } } for (int i = 0; i < musicGroup._children.Count; i++) { StopPlayersAt(musicGroup._children[i] as InMusicGroup, absoluteDSPTime); } }
private static void PlayMusicGroup(InMusicGroup toPlay, double playTime, int skipSamples) { var musicPool = InAudioInstanceFinder.InMusicPlayerPool; var mixer = toPlay.GetUsedMixerGroup(); toPlay.PlayingInfo.State = MusicState.Playing; var editorClips = toPlay._clips; int clipCount = editorClips.Count; var playingInfo = toPlay.PlayingInfo; playingInfo.State = MusicState.Playing; playingInfo.DoAtEnd = MusicState.Nothing; for (int j = 0; j < clipCount; j++) { var player = musicPool.GetObject(); toPlay.PlayingInfo.Players.Add(player); toPlay.PlayingInfo.StartedAtDSPTime = playTime; player.clip = editorClips[j]; player.loop = toPlay._loop; player.timeSamples = skipSamples; player.outputAudioMixerGroup = mixer; #if UNITY_WEBGL player.Play(0); // SK: HACK: Workaround for https://issuetracker.unity3d.com/issues/playschedule-does-not-loop-audio-in-webgl-build #else player.PlayScheduled(playTime); #endif // SK: Koreographer integration var visor = player.GetComponent <SonicBloom.Koreo.Players.AudioSourceVisor>(); if (!visor) { visor = player.gameObject.AddComponent <SonicBloom.Koreo.Players.AudioSourceVisor>(); } visor.ScheduledPlayTime = playTime; visor.ResyncTimings(0); } for (int i = 0; i < toPlay._children.Count; i++) { PlayMusicGroup(toPlay._children[i] as InMusicGroup, playTime, skipSamples); } }
private static void HandleDragging(AudioEventAction currentAction, Rect dragArea) { if (currentAction != null) { if (currentAction is InEventAudioAction) { InAudioNode dragged = OnDragging.DraggingObject <InAudioNode>(dragArea, node => node.IsPlayable); if (dragged != null) { InUndoHelper.RecordObject(currentAction, "Change Action Type"); currentAction.Target = dragged; } } else if (currentAction is InEventBankLoadingAction) { InAudioBankLink dragged = OnDragging.DraggingObject <InAudioBankLink>(dragArea, bank => bank._type == AudioBankTypes.Bank); if (dragged != null) { InUndoHelper.RecordObject(currentAction, "Change Action Type"); currentAction.Target = dragged; } } else if (currentAction is InEventMixerValueAction) { AudioMixer dragged = OnDragging.DraggingObject <AudioMixer>(dragArea); if (dragged != null) { InUndoHelper.RecordObject(currentAction, "Change Action Type"); currentAction.Target = dragged; } } else if (currentAction is InEventMusicControl || currentAction is InEventMusicFade || currentAction is InEventSoloMuteMusic) { InMusicGroup dragged = OnDragging.DraggingObject <InMusicGroup>(dragArea); if (dragged != null) { InUndoHelper.RecordObject(currentAction, "Change Action Type"); currentAction.Target = dragged; } } } }
private void Update() { if (playingCurrently != null && musicState == MusicState.Playing) { double remainingTime = InAudio.Music.GetRemainingTime(playingCurrently); var next = GetNextTrack(); if (playingPreviously != null && playingPreviously.Stopped) { transitionToNextSong = false; } if (!transitionToNextSong && next != playingCurrently) { if (crossfade) { if (remainingTime <= crossfadeTime) { float pitch = InAudio.Music.GetHiearchyPitch(playingCurrently); float nextPitch = InAudio.Music.GetHiearchyPitch(next); transitionToNextSong = true; InAudio.Music.FadeAndStop(playingCurrently, (float)remainingTime / pitch); InAudio.Music.PlayWithFadeInAt(next, musicParameters.Volume, (float)remainingTime / nextPitch, AudioSettings.dspTime + delayBetweenTracks); playingPreviously = playingCurrently; playingCurrently = next; } } else if (remainingTime / playingCurrently.Pitch <= prebookAudioTime) { float pitch = InAudio.Music.GetHiearchyPitch(playingCurrently); float nextPitch = InAudio.Music.GetHiearchyPitch(next); transitionToNextSong = true; InAudio.Music.StopAt(playingCurrently, AudioSettings.dspTime + remainingTime / pitch); InAudio.Music.PlayWithFadeInAt(next, (float)remainingTime / nextPitch, AudioSettings.dspTime + remainingTime / nextPitch + delayBetweenTracks); playingPreviously = playingCurrently; playingCurrently = next; playingCurrently.Volume = musicParameters.Volume; } } } }
//Only handles one node, remember to clear its children public static void CleanupMusicNode(InMusicGroup musicGroup) { AudioSource player; var playingInfo = musicGroup.PlayingInfo; var players = playingInfo.Players; playingInfo.State = MusicState.Stopped; playingInfo.Fading = false; for (int i = 0; i < players.Count; i++) { player = players[i]; if (player != null) { player.clip = null; InAudioInstanceFinder.InMusicPlayerPool.ImmidiateRelease(player); } } players.Clear(); }
public void PlayAt(InMusicGroup musicGroup, double absoluteDSPTime, int skipSamples) { if (musicGroup == null) { Debug.LogError("InAudio: Cannot play 'Null' music group"); return; } var parent = GetParent(musicGroup); var playingInfo = parent.PlayingInfo; if (HandleExcistingPlay(parent, ref playingInfo)) { return; } double playTime = absoluteDSPTime; PlayMusicGroup(parent, playTime, skipSamples); }
private static void DrawPlayStop(Rect fullArea, InMusicGroup group) { Rect butArea = fullArea; butArea.width = 16; butArea.height = 12; butArea.y += 3; butArea.x += EditorGUI.indentLevel * 5 - 10; Texture playing; if(Application.isPlaying) playing = group.PlayingInfo.State == MusicState.Playing ? EditorResources.Instance.Pause : EditorResources.Instance.Play; else { playing = EditorResources.Instance.Play; } if (GUI.Button(butArea, playing, GUIStyle.none)) { if(group.PlayingInfo.State == MusicState.Playing) InAudio.Music.Pause(group); else InAudio.Music.Play(group); } if (group.PlayingInfo.State == MusicState.Stopped || group.PlayingInfo.State == MusicState.Nothing) { GUI.enabled = false; } butArea.y += 14; Texture stop= EditorResources.Instance.Stop; if (GUI.Button(butArea, stop, GUIStyle.none)) { InAudio.Music.Stop(group); } GUI.enabled = true; }
private static void StopPlayersNow(InMusicGroup musicGroup) { var playingInfo = musicGroup.PlayingInfo; if (playingInfo.State != MusicState.Stopped) { playingInfo.State = MusicState.Stopped; var playing = playingInfo.Players; for (int i = 0; i < playing.Count; i++) { if (playing[i] != null) { playing[i].Stop(); } MusicUpdater.CleanupMusicNode(musicGroup); } } for (int i = 0; i < musicGroup._children.Count; i++) { StopPlayersNow(musicGroup._children[i] as InMusicGroup); } }
public void ReceiveNode(InMusicGroup group) { if (SelectedNode != null) { InUndoHelper.DoInGroup(() => { TreeWalker.ForEachParent(SelectedNode, n => n.EditorSettings.IsFoldedOut = true); InUndoHelper.RecordObject(SelectedNode, "Send to Event"); if (SelectedNode.IsRootOrFolder) { var myEvent = AudioEventWorker.CreateNode(SelectedNode, EventNodeType.Event); var myAction = AudioEventWorker.AddEventAction <InEventMusicControl>(myEvent, EventActionTypes.PlayMusic); myAction.Target = group; SelectedNode = myEvent; treeDrawer.SelectedNode = myEvent; } else { var myAction = AudioEventWorker.AddEventAction <InEventMusicControl>(SelectedNode, EventActionTypes.PlayMusic); myAction.Target = group; } }); } }
private void SetCurrentlyPlaying(InMusicGroup group) { playingCurrently = group; }
public bool Load(InMusicGroup musicGroup) { return BankLoader.Load(musicGroup.GetBank()); }
public float GetPitch(InMusicGroup musicGroup) { return musicGroup.runtimePitch; }
public void Mute(InMusicGroup musicGroup, bool mute) { musicGroup.runtimeMute = mute; }
public void StopAt(InMusicGroup musicGroup, double absoluteDSPTime) { StopPlayersAt(GetParent(musicGroup), absoluteDSPTime); }
public void CrossfadeVolume(InMusicNode from, InMusicGroup to, float duration, LeanTweenType tweenType = LeanTweenType.easeInOutQuad) { Fade(from, 0f, duration, tweenType, Time.time); Fade(to, 1f, duration, tweenType, Time.time); }
//These settings are applied in the beginning of the next frame in the update loop in InAudio.cs public void Solo(InMusicGroup musicGroup, bool solo) { musicGroup.runtimeSolo = true; }
public bool IsSolo(InMusicGroup musicGroup) { return musicGroup.runtimeSolo; }
private static InMusicGroup GetParent(InMusicGroup group) { if (group._parent.IsRootOrFolder) return group; else return GetParent(group._parent as InMusicGroup); }
public bool IsSolo(InMusicGroup musicGroup) { return(musicGroup.runtimeSolo); }
public void StopFade(InMusicGroup stopFade) { stopFade.PlayingInfo.Fading = false; }
public bool IsMuted(InMusicGroup musicGroup) { return(musicGroup.runtimeMute); }
public double GetRemainingTime(InMusicGroup musicGroup) { double maxTime = 0; var info = musicGroup.PlayingInfo; for (int i = 0; i < info.Players.Count; i++) { var source = musicGroup.PlayingInfo.Players[i]; double time = source.ExactTimeLength(); if (time / source.pitch > maxTime) { maxTime = time; } } for (int i = 0; i < musicGroup._children.Count; i++) { double time = GetRemainingTime(musicGroup); if (time > maxTime) { maxTime = time; } } return maxTime; }
public void UnLoad(InMusicGroup musicGroup) { BankLoader.Unload(musicGroup.GetBank()); }
/// <summary> /// Get the initial pitch of this node, independent from the volume pitch playing and the hierarchy /// </summary> /// <param name="musicGroup"></param> /// <returns></returns> public float GetInitialPitch(InMusicGroup musicGroup) { //Do not change this value, except from the GUI as it will change the prefab, even in Play mode. return musicGroup._minPitch; }
public void ReceiveNode(InMusicGroup group) { audioEventCreatorGUI.ReceiveNode(group); }
public bool IsStopped(InMusicGroup musicGroup) { return musicGroup.Stopped; }
private static bool HandleExcistingPlay(InMusicGroup musicGroup, ref PlayingMusicInfo playingInfo) { if (playingInfo.State == MusicState.Playing) { StopPlayersNow(musicGroup); } else if (playingInfo.State == MusicState.Paused) { UnpausePlayers(musicGroup); return true; } return false; }
public bool IsPaused(InMusicGroup musicGroup) { return musicGroup.Paused; }
public bool IsPlaying(InMusicGroup musicGroup) { return musicGroup.Playing; }
public static void Draw(InMusicGroup node) { node.ScrollPosition = EditorGUILayout.BeginScrollView(node.ScrollPosition); var prop = new SerializedObject(node); prop.Update(); EditorGUILayout.PropertyField(prop.FindProperty("_name")); if (!Application.isPlaying) { InUndoHelper.GUIUndo(node, "Volume", ref node._minVolume, () => EditorGUILayout.Slider("Initial Volume", node._minVolume, 0f, 1f)); } else { InUndoHelper.GUIUndo(node, "Volume", ref node.runtimeVolume, () => EditorGUILayout.Slider("Current Volume", node.runtimeVolume, 0f, 1f)); } if (!Application.isPlaying) { InUndoHelper.GUIUndo(node, "Pitch", ref node._minPitch, () => EditorGUILayout.Slider("Initial Pitch", node._minPitch, 0f, 3f)); } else { InUndoHelper.GUIUndo(node, "Pitch", ref node.runtimePitch, () => EditorGUILayout.Slider("Current Pitch", node.runtimePitch, 0f, 3f)); } EditorGUILayout.BeginHorizontal(); if (Application.isPlaying) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Save volume & pitch")) { InUndoHelper.RecordObject(node, "Volume & Pitch for Music"); node._minVolume = node.runtimeVolume; node._minPitch = node.runtimePitch; Debug.Log("InAudio: Saved volume: " + node._minVolume + ", pitch: " + node._minPitch); } } EditorGUILayout.EndHorizontal(); var playingInfo = node.PlayingInfo; if (playingInfo.Fading && Application.isPlaying) { EditorGUILayout.Slider("Volume target", playingInfo.TargetVolume, 0f, 1f); GUI.enabled = false; var duration = playingInfo.EndTime - playingInfo.StartTime; var left = playingInfo.EndTime - Time.time; EditorGUILayout.Slider("Time elapsed", duration - left, 0, duration); GUI.enabled = true; } EditorGUILayout.PropertyField(prop.FindProperty("_loop")); EditorGUILayout.Separator(); DataDrawerHelper.DrawMixer(node, prop.FindProperty("_mixerGroup")); EditorGUILayout.Separator(); prop.ApplyModifiedProperties(); if (!Application.isPlaying) { InUndoHelper.GUIUndo(node, "Mute", ref node._mute, () => EditorGUILayout.Toggle("Initial Mute", node._mute)); } else { InUndoHelper.GUIUndo(node, "Mute", ref node.runtimeMute, () => EditorGUILayout.Toggle("Currently Mute", node.runtimeMute)); } if (!Application.isPlaying) { InUndoHelper.GUIUndo(node, "Solo", ref node._solo, () => EditorGUILayout.Toggle("Initial Solo", node._solo)); } else { InUndoHelper.GUIUndo(node, "Solo", ref node.runtimeSolo, () => EditorGUILayout.Toggle("Currently Solo", node.runtimeSolo)); } EditorGUILayout.Separator(); prop.Update(); EditorGUILayout.LabelField("Clips in node"); if (Application.isPlaying) { ReorderableListGUI.ListField(prop.FindProperty("_clips"), ReorderableListFlags.DisableDuplicateCommand | ReorderableListFlags.DisableContextMenu | ReorderableListFlags.DisableReordering | ReorderableListFlags.HideRemoveButtons); var rect = GUILayoutUtility.GetLastRect(); for (int i = 0; i < node._clips.Count; i++) { var progress = rect; progress.height = 3; progress.x += 5; progress.width -= 30; progress.y += i * 20 + 20; //GUI.DrawTexture(progress, EditorResources.Background); var item = node._clips[i]; var player = node.PlayingInfo.Players.Find(s => s.clip == item); if (player != null) { EditorGUI.DrawRect(progress, Color.white); float pos = (float)player.ExactPosition(); if (node.PlayingInfo.State == MusicState.Playing || node.PlayingInfo.State == MusicState.Paused) { progress.width = progress.width * Mathf.Clamp01(pos / item.length); EditorGUI.DrawRect(progress, Color.green); } } } } else { ReorderableListGUI.ListField(prop.FindProperty("_clips"), ReorderableListFlags.DisableDuplicateCommand); } prop.ApplyModifiedProperties(); EditorGUILayout.Separator(); if (node._children.Count > 0) { EditorGUILayout.LabelField("Child nodes"); ReorderableListGUI.ListField(node._children, (position, item) => { EditorGUI.LabelField(position, item._name); return(item); }, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.DisableReordering | ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons); } EditorGUILayout.EndScrollView(); }
public void CrossfadePlayStop(InMusicNode from, InMusicGroup to, float duration, LeanTweenType tweenType = LeanTweenType.easeInOutQuad) { FadeAndStop(from, duration, tweenType); PlayWithFadeIn(to, 1f, duration, tweenType); }
private static void StopPlayersNow(InMusicGroup musicGroup) { var playingInfo = musicGroup.PlayingInfo; if (playingInfo.State != MusicState.Stopped) { playingInfo.State = MusicState.Stopped; var playing = playingInfo.Players; for (int i = 0; i < playing.Count; i++) { if (playing[i] != null) playing[i].Stop(); MusicUpdater.CleanupMusicNode(musicGroup); } } for (int i = 0; i < musicGroup._children.Count; i++) { StopPlayersNow(musicGroup._children[i] as InMusicGroup); } }
public bool IsMuted(InMusicGroup musicGroup) { return musicGroup.runtimeMute; }