Extract scheduled Action
This commit is contained in:
parent
f3e53b8597
commit
1582a10ce2
3 changed files with 58 additions and 26 deletions
|
@ -4,17 +4,16 @@ using UnityEngine.Playables;
|
||||||
|
|
||||||
namespace cylvester
|
namespace cylvester
|
||||||
{
|
{
|
||||||
public enum CYLCommand
|
|
||||||
{
|
|
||||||
OneBarLoopButton = 94,
|
|
||||||
FourBarLoopButton = 86,
|
|
||||||
NextSelectedScene = 18,
|
|
||||||
CurrentSelectedScene = 17,
|
|
||||||
InstantTrigger = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CylMidiTransitionController : MonoBehaviour
|
public class CylMidiTransitionController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
private enum CylCommand
|
||||||
|
{
|
||||||
|
OneBarLoopButton = 94,
|
||||||
|
FourBarLoopButton = 86,
|
||||||
|
NextSelectedScene = 18,
|
||||||
|
CurrentSelectedScene = 17,
|
||||||
|
InstantTrigger = 2,
|
||||||
|
}
|
||||||
|
|
||||||
[SerializeField] private PlayableDirector playableDirector;
|
[SerializeField] private PlayableDirector playableDirector;
|
||||||
[SerializeField, Range(1, 16)] private int channel = 1;
|
[SerializeField, Range(1, 16)] private int channel = 1;
|
||||||
|
@ -25,12 +24,21 @@ namespace cylvester
|
||||||
private const int FourBarTrigger = OneBarTrigger * 4;
|
private const int FourBarTrigger = OneBarTrigger * 4;
|
||||||
private const float TransitionLength = 16;
|
private const float TransitionLength = 16;
|
||||||
|
|
||||||
private bool instantChangeActive_;
|
private ScheduledAction scheduledAction_;
|
||||||
private int currentTick_;
|
private int currentTick_;
|
||||||
private float restTime_ = 1f;
|
private float restTime_ = 1f;
|
||||||
private int currentSelectedScene_ ;
|
private int currentSelectedScene_ ;
|
||||||
private int nextSelectedScene_;
|
private int nextSelectedScene_;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
scheduledAction_ = new ScheduledAction(() =>
|
||||||
|
{
|
||||||
|
stateManager.SelectedState = currentSelectedScene_;
|
||||||
|
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(instaTransitionSpeed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void OnSyncReceived(MidiSync midiSync, int counter)
|
public void OnSyncReceived(MidiSync midiSync, int counter)
|
||||||
{
|
{
|
||||||
currentTick_ = counter;
|
currentTick_ = counter;
|
||||||
|
@ -40,33 +48,26 @@ namespace cylvester
|
||||||
{
|
{
|
||||||
if (mes.Status - 176 != channel - 1) return;
|
if (mes.Status - 176 != channel - 1) return;
|
||||||
|
|
||||||
var command = (CYLCommand)mes.Data1;
|
var command = (CylCommand)mes.Data1;
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case CYLCommand.NextSelectedScene:
|
case CylCommand.NextSelectedScene:
|
||||||
{
|
{
|
||||||
nextSelectedScene_ = mes.Data2;
|
nextSelectedScene_ = mes.Data2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CYLCommand.InstantTrigger:
|
case CylCommand.InstantTrigger:
|
||||||
{
|
{
|
||||||
instantChangeActive_ = true;
|
scheduledAction_.Ready();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CYLCommand.CurrentSelectedScene:
|
case CylCommand.CurrentSelectedScene:
|
||||||
{
|
{
|
||||||
currentSelectedScene_ = mes.Data2;
|
currentSelectedScene_ = mes.Data2;
|
||||||
|
scheduledAction_.Go();
|
||||||
if (instantChangeActive_)
|
|
||||||
{
|
|
||||||
stateManager.SelectedState = currentSelectedScene_;
|
|
||||||
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(instaTransitionSpeed);
|
|
||||||
instantChangeActive_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CYLCommand.FourBarLoopButton:
|
case CylCommand.FourBarLoopButton:
|
||||||
{
|
{
|
||||||
if (nextSelectedScene_ > currentSelectedScene_)
|
if (nextSelectedScene_ > currentSelectedScene_)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +84,7 @@ namespace cylvester
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CYLCommand.OneBarLoopButton:
|
case CylCommand.OneBarLoopButton:
|
||||||
{
|
{
|
||||||
UpdateRestTime(OneBarTrigger - currentTick_ % OneBarTrigger);
|
UpdateRestTime(OneBarTrigger - currentTick_ % OneBarTrigger);
|
||||||
UpdateTimelinePlaybackSpeed(1f);
|
UpdateTimelinePlaybackSpeed(1f);
|
||||||
|
|
28
UnityProject/Assets/Scripts/PdConnection/ScheduledAction.cs
Normal file
28
UnityProject/Assets/Scripts/PdConnection/ScheduledAction.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace cylvester
|
||||||
|
{
|
||||||
|
public class ScheduledAction
|
||||||
|
{
|
||||||
|
public ScheduledAction(Action action)
|
||||||
|
{
|
||||||
|
action_ = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ready()
|
||||||
|
{
|
||||||
|
standBy_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Go()
|
||||||
|
{
|
||||||
|
if (!standBy_) return;
|
||||||
|
|
||||||
|
action_.Invoke();
|
||||||
|
standBy_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool standBy_;
|
||||||
|
private readonly Action action_;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3911173c24224aae853febfafe73c56c
|
||||||
|
timeCreated: 1575666666
|
Loading…
Reference in a new issue