CleanUp TimeController

closes #122
This commit is contained in:
max 2019-12-05 13:37:20 +01:00
parent ca5568e94b
commit 71f1403494
3 changed files with 17 additions and 23 deletions

View file

@ -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<QlistMarker>();
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;
}
}
@ -55,7 +49,10 @@ namespace cylvester
var nextState = stateManager.NextState.Value;
if (notification.id == nextState.Title)
{
playableDirector.Pause(); // reaches the next state (marker) in timeline
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(1);
}
}
}
}

View file

@ -194,6 +194,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
oneBarLoopButton: 86
fourBarLoopButton: 94
playableDirector: {fileID: 65620552}
channel: 3
stateManager: {fileID: 850208555}
--- !u!114 &65620555

View file

@ -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
}
}
}