Added Calculation for TransitionSpeed

to Timline Controller that updates every frame
This commit is contained in:
max 2019-12-11 17:08:52 +01:00
parent 8ad6ccf13e
commit ca64fc6b39
4 changed files with 67 additions and 35 deletions

View file

@ -15,6 +15,10 @@ namespace cylvester
private IList<QlistMarker> qlistMarkers_;
private Boundary boundary_;
private float speed_;
private float transitionTargetRealtime_;
private float previousMarkerTime_;
private float nextMarkerTime_;
private float restTime_;
public void Start()
{
@ -26,7 +30,7 @@ namespace cylvester
playableDirector.time = 0;
boundary_ = new Boundary(null, null);
UpdateSpeed();
ResetSpeed();
}
public void OnStateChanged(IStateReader stateManager)
@ -41,6 +45,8 @@ namespace cylvester
playableDirector.time = qlistMarkers_[i].time;
var previousMarkerTime = i > 0 ? (double?) qlistMarkers_[i - 1].time : null;
var nextMarkerTime = i < numMarkers - 1 ? (double?) qlistMarkers_[i + 1].time : null;
previousMarkerTime_ = (float) previousMarkerTime;
nextMarkerTime_ = (float) nextMarkerTime;
boundary_ = new Boundary(previousMarkerTime, nextMarkerTime);
playableDirector.Play();
break;
@ -52,6 +58,15 @@ namespace cylvester
if (playableDirector.state == PlayState.Paused)
return;
if (!(Time.fixedUnscaledTime >= transitionTargetRealtime_)) // check o current time >= targetTime
{
speed_ = (CalculateTransitionSpeed(nextMarkerTime_));// berechne tnrsitionSpeed
Debug.Log("Rest time: " + restTime_);
Debug.Log("Speed set to: " + speed_);
}
var deltaTime = Time.deltaTime;
var expectedTimeIncrement = speed_ * deltaTime;
var expectedTimeInTimeline = playableDirector.time + expectedTimeIncrement;
@ -64,13 +79,27 @@ namespace cylvester
else
{
playableDirector.Pause();
UpdateSpeed();
ResetSpeed();
Debug.Log("Speed Reset to " + speed_);
}
}
private void UpdateSpeed()
private void ResetSpeed()
{
speed_ = initTransitionFactor;
}
public void UpdateTransitionTargetRealTime(float restTime)
{
transitionTargetRealtime_ = Time.fixedUnscaledTime + restTime;
restTime_ = restTime;
}
private float CalculateTransitionSpeed(float targetMarkerTime)
{
var transitionSpeed = (targetMarkerTime - playableDirector.time) / (transitionTargetRealtime_ - Time.fixedUnscaledTime);
return (float) transitionSpeed;
}
}
}

View file

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.0013490503, g: 0.0011814049, b: 0.0008122615, a: 1}
m_IndirectSpecularColor: {r: 0.0013421604, g: 0.0011744275, b: 0.0008066663, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -193,9 +193,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
playableDirector: {fileID: 65620552}
timelineController: {fileID: 65620555}
channel: 3
stateManager: {fileID: 850208555}
instaTransitionSpeed: 10
instaTransitionSpeed: 1
--- !u!114 &65620555
MonoBehaviour:
m_ObjectHideFlags: 0

View file

@ -16,6 +16,7 @@ namespace cylvester
}
[SerializeField] private PlayableDirector playableDirector;
[SerializeField] private TimelineController timelineController;
[SerializeField, Range(1, 16)] private int channel = 1;
[SerializeField] private StateManager stateManager;
[SerializeField] private float instaTransitionSpeed = 10;
@ -68,42 +69,44 @@ namespace cylvester
}
case CylCommand.FourBarLoopButton:
{
var restTime = UpdateRestTime(FourBarTrigger - currentTick_ % FourBarTrigger);
var restTime = CalculateRestTime(FourBarTrigger - currentTick_ % FourBarTrigger);
if (nextSelectedScene_ > currentSelectedScene_)
{
UpdateTimelinePlaybackSpeed(1f, restTime);
timelineController.UpdateTransitionTargetRealTime(restTime);
stateManager.SelectedState = nextSelectedScene_;
}
else
{
UpdateTimelinePlaybackSpeed(-1f, restTime);
stateManager.SelectedState = nextSelectedScene_ + 2;
timelineController.UpdateTransitionTargetRealTime(-restTime);
stateManager.SelectedState = nextSelectedScene_ + 1;
}
break;
}
case CylCommand.OneBarLoopButton:
{
var restTime = UpdateRestTime(OneBarTrigger - currentTick_ % OneBarTrigger);
UpdateTimelinePlaybackSpeed(1f, restTime);
stateManager.SelectedState = nextSelectedScene_;
var restTime = CalculateRestTime(OneBarTrigger - currentTick_ % OneBarTrigger);
if (nextSelectedScene_ > currentSelectedScene_)
{
timelineController.UpdateTransitionTargetRealTime(restTime);
stateManager.SelectedState = nextSelectedScene_;
}
else
{
timelineController.UpdateTransitionTargetRealTime(-restTime);
stateManager.SelectedState = nextSelectedScene_ + 1;
}
break;
}
default:
throw new Exception("Unexpected CYL command");
}
}
private float UpdateRestTime(int restTicks)
private float CalculateRestTime(int restTicks)
{
return restTicks / 24f / stateManager.CurrentState.Bpm * 60f;
}
private void UpdateTimelinePlaybackSpeed(float speed, float restTime)
{
var timelinePlaybackSpeed = TransitionLength / Mathf.Clamp(restTime, 0.001f, TransitionLength);
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(timelinePlaybackSpeed * speed);
}
}
}

View file

@ -1,4 +1,4 @@
#N canvas 179 93 1690 536 10;
#N canvas -3090 415 1690 536 10;
#X declare -lib timbreID/timbreIDLib;
#X obj 484 442 adc~ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16;
#X obj 414 483 dac~, f 6;
@ -290,8 +290,8 @@ Roses_Front.wav \; TimbreID_Test.wav \;;
#X text 416 223 176... control channel 1;
#X obj 6 194 midirealtimein;
#X obj 242 41 netreceive -u 54345;
#X obj 598 90 cnv 15 500 60 empty current Forces 20 12 0 45 -204786
-66577 0;
#X obj 598 90 cnv 15 500 60 empty current PositionCloud 20 12 0 45
-204786 -66577 0;
#X obj 786 234 bng 50 250 50 0 empty empty next 15 25 0 10 -204786
-1 -1;
#X obj 596 227 bng 50 250 50 0 empty empty rewind 7 25 0 10 -261234
@ -302,10 +302,10 @@ Roses_Front.wav \; TimbreID_Test.wav \;;
-1 -1;
#X msg 692 303 send 176 127 1;
#X msg 791 304 send 176 127 2;
#X obj 594 46 cnv 12 500 30 empty previous PositionCloud 20 12 0 25
-262130 -66577 0;
#X obj 596 152 cnv 12 500 30 empty next ShowAll 20 12 0 25 -262130
#X obj 594 46 cnv 12 500 30 empty previous PontCloud 20 12 0 25 -262130
-66577 0;
#X obj 596 152 cnv 12 500 30 empty next Forces 20 12 0 25 -262130 -66577
0;
#X obj 879 467 declare -lib timbreID/timbreIDLib;
#N canvas 28 541 1273 735 timbreID_example 0;
#X obj 77 657 nbx 3 28 -1e+037 1e+037 0 0 empty empty empty 0 -8 0
@ -420,7 +420,6 @@ samples/kick.wav kick \, read -resize samples/closed.wav closed;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X restore 405 71 pd shmem;
#X text 701 378 <--- this is only for reference;
#X obj 1167 19 cnv 15 400 500 empty empty CYL_Transition_Sim 20 12
0 14 -204800 -66577 0;
#X obj 1383 196 bng 15 250 50 0 4bar_trig_sim empty 4_Bar_trigger_Sim
@ -594,13 +593,13 @@ samples/kick.wav kick \, read -resize samples/closed.wav closed;
#X floatatom 1472 98 5 0 0 1 BPM - midi_sim_tempo;
#X text 1374 100 Clock Sim.:;
#X obj 1451 98 tgl 15 0 clock_sim_start_stop empty empty 17 7 0 10
-204786 -1 -1 0 1;
-204786 -1 -1 1 1;
#X text 1198 40 Simulate the Press of a 1_Bar or 4_Bar Transition trigger.
;
#N canvas 0 50 1167 867 Midi_Clock_Sim 0;
#X obj 21 155 outlet;
#X obj 155 14 tgl 15 0 empty clock_sim_start_stop mock 17 7 0 10 -262144
-1 -1 0 1;
-1 -1 1 1;
#X msg 110 128 248, f 4;
#X text 29 -56 MIDI Clock Simulator;
#X text 8 10 start;
@ -885,10 +884,10 @@ samples/kick.wav kick \, read -resize samples/closed.wav closed;
#X connect 30 0 11 0;
#X connect 31 0 11 0;
#X connect 36 0 11 0;
#X connect 42 0 43 0;
#X connect 43 0 54 0;
#X connect 44 0 74 0;
#X connect 58 0 44 0;
#X connect 58 0 63 0;
#X connect 64 0 11 0;
#X connect 41 0 42 0;
#X connect 42 0 53 0;
#X connect 43 0 73 0;
#X connect 57 0 43 0;
#X connect 57 0 62 0;
#X connect 63 0 11 0;
#X coords 0 0 2 2 0 0 0;