From 71f140349492eef7dad88623c303e59ec923b40e Mon Sep 17 00:00:00 2001 From: max Date: Thu, 5 Dec 2019 13:37:20 +0100 Subject: [PATCH] CleanUp TimeController closes #122 --- .../Qlist/scripts/TimelineController.cs | 21 ++++++++----------- .../VisualEffectGraph/VFX Graph Plane.unity | 1 + .../PdConnection/MidiTransitionController.cs | 18 +++++++--------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs b/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs index a38ff45..7165cc7 100644 --- a/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs +++ b/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs @@ -9,7 +9,6 @@ namespace cylvester { [SerializeField] private PlayableDirector playableDirector; [SerializeField] private StateManager stateManager; - [SerializeField] private MidiTransitionController transitionController; [SerializeField] private float initTransitionTime = 16f; @@ -23,6 +22,10 @@ namespace cylvester qlistMarkers_ = new List(); foreach (var marker in markers) qlistMarkers_.Add((QlistMarker)marker); + + playableDirector.Stop(); + playableDirector.time = 0; + playableDirector.Play(); } public void OnStateChanged(IStateReader stateManager) @@ -32,18 +35,9 @@ namespace cylvester { if (qlistMarker.id != stateName) continue; - playableDirector.Stop(); + //playableDirector.Stop(); //This resets speed to 1, so I had to cut it. playableDirector.time = qlistMarker.time; playableDirector.Play(); - - if (transitionController != null) - { - playableDirector.playableGraph.GetRootPlayable(0) - .SetSpeed(transitionController.TimelinePlaybackSpeed()); //Set Playback Speed of Timeline for CYL transitions - } - else - playableDirector.playableGraph.GetRootPlayable(0) - .SetSpeed(initTransitionTime); break; } } @@ -54,8 +48,11 @@ namespace cylvester return; var nextState = stateManager.NextState.Value; - if(notification.id == nextState.Title) + if (notification.id == nextState.Title) + { playableDirector.Pause(); // reaches the next state (marker) in timeline + playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(1); + } } } } diff --git a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity index 8551c31..73e4df1 100644 --- a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity +++ b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity @@ -194,6 +194,7 @@ MonoBehaviour: m_EditorClassIdentifier: oneBarLoopButton: 86 fourBarLoopButton: 94 + playableDirector: {fileID: 65620552} channel: 3 stateManager: {fileID: 850208555} --- !u!114 &65620555 diff --git a/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs b/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs index 125f5dd..6ebd5d8 100644 --- a/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs +++ b/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs @@ -1,5 +1,7 @@ using UnityEngine; using UnityEngine.Events; +using UnityEngine.Timeline; +using UnityEngine.Playables; namespace cylvester { @@ -7,6 +9,7 @@ namespace cylvester { [SerializeField] private int oneBarLoopButton = 86; [SerializeField] private int fourBarLoopButton = 94; + [SerializeField] private PlayableDirector playableDirector; private int oneBarLoop = 96; private int fourBarLoop = 384; @@ -18,10 +21,6 @@ namespace cylvester [SerializeField] StateManager stateManager; - public void Start() - { - - } public void OnSyncReceived(MidiSync midiSync, int counter) { @@ -35,11 +34,13 @@ namespace cylvester if (mes.Data1 == oneBarLoopButton) //Button fourBarLoop { RestTime(fourBarLoop - currentTick % fourBarLoop); + TimelinePlaybackSpeed(); } if (mes.Data1 == fourBarLoopButton) //Button oneBarLoop { RestTime(oneBarLoop - currentTick % oneBarLoop); + TimelinePlaybackSpeed(); } } } @@ -49,16 +50,11 @@ namespace cylvester restTimeS = restTick / 24.0f / stateManager.CurrentState.Bpm * 60; } - public float TimelinePlaybackSpeed () + public void TimelinePlaybackSpeed () { float timelinePlaybackSpeed; - /* if (restTimeS == 0f) - { - restTimeS = initTransitionTime; //Initial Transition Time - } - */ timelinePlaybackSpeed = transitionLength / Mathf.Clamp(restTimeS, 0.001f, transitionLength); - return timelinePlaybackSpeed; + playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(timelinePlaybackSpeed); //set playbackspeed of Timeline } } } \ No newline at end of file