fix formatting and style error
This commit is contained in:
parent
24c7c805bc
commit
f3e53b8597
1 changed files with 69 additions and 71 deletions
|
@ -1,25 +1,16 @@
|
||||||
using UnityEngine;
|
using System;
|
||||||
using UnityEngine.Events;
|
using UnityEngine;
|
||||||
using UnityEngine.Timeline;
|
|
||||||
using UnityEngine.Playables;
|
using UnityEngine.Playables;
|
||||||
|
|
||||||
namespace cylvester
|
namespace cylvester
|
||||||
{
|
{
|
||||||
|
public enum CYLCommand
|
||||||
public enum CYL_Command
|
|
||||||
{
|
{
|
||||||
//these are the midi CCs coming from the CYL_Axoloti box
|
|
||||||
OneBarLoopButton = 94,
|
OneBarLoopButton = 94,
|
||||||
FourBarLoopButton = 86,
|
FourBarLoopButton = 86,
|
||||||
NextScelectedScene = 18,
|
NextSelectedScene = 18,
|
||||||
CurrentSelectedScene = 17,
|
CurrentSelectedScene = 17,
|
||||||
instaTrig = 2,
|
InstantTrigger = 2,
|
||||||
}
|
|
||||||
|
|
||||||
public enum Timeline_Command
|
|
||||||
{
|
|
||||||
Forwards = 1,
|
|
||||||
Backwards = -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CylMidiTransitionController : MonoBehaviour
|
public class CylMidiTransitionController : MonoBehaviour
|
||||||
|
@ -27,86 +18,93 @@ namespace cylvester
|
||||||
|
|
||||||
[SerializeField] private PlayableDirector playableDirector;
|
[SerializeField] private PlayableDirector playableDirector;
|
||||||
[SerializeField, Range(1, 16)] private int channel = 1;
|
[SerializeField, Range(1, 16)] private int channel = 1;
|
||||||
[SerializeField] StateManager stateManager;
|
[SerializeField] private StateManager stateManager;
|
||||||
[SerializeField] float instaTransitionSpeed = 10;
|
[SerializeField] private float instaTransitionSpeed = 10;
|
||||||
|
|
||||||
private const int oneBarTrigger = 96;
|
private const int OneBarTrigger = 96;
|
||||||
private const int fourBarTrigger = 384;
|
private const int FourBarTrigger = OneBarTrigger * 4;
|
||||||
|
private const float TransitionLength = 16;
|
||||||
|
|
||||||
private bool instaChangeActive;
|
private bool instantChangeActive_;
|
||||||
|
private int currentTick_;
|
||||||
private int currentTick;
|
private float restTime_ = 1f;
|
||||||
private float transitionLength = 16; //sets the duration in Seconds, how long a transition has to be in "TimeLine" to be played back correctly when CYLVESTER is hooked up correctly
|
private int currentSelectedScene_ ;
|
||||||
private float restTimeS = 1f; //init transTime is 1 Second
|
private int nextSelectedScene_;
|
||||||
|
|
||||||
int currentSelectedScene = 0;
|
|
||||||
int nextSelectedScene = 0;
|
|
||||||
|
|
||||||
public void OnSyncReceived(MidiSync midiSync, int counter)
|
public void OnSyncReceived(MidiSync midiSync, int counter)
|
||||||
{
|
{
|
||||||
currentTick = counter;
|
currentTick_ = counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMidiMessageReceived(MidiMessage mes)
|
public void OnMidiMessageReceived(MidiMessage mes)
|
||||||
{
|
{
|
||||||
|
if (mes.Status - 176 != channel - 1) return;
|
||||||
|
|
||||||
if (mes.Status - 176 == channel - 1) //Choose Midi-Channel
|
var command = (CYLCommand)mes.Data1;
|
||||||
|
switch (command)
|
||||||
{
|
{
|
||||||
|
case CYLCommand.NextSelectedScene:
|
||||||
switch (mes.Data1)
|
|
||||||
{
|
{
|
||||||
case (byte) CYL_Command.NextScelectedScene:
|
nextSelectedScene_ = mes.Data2;
|
||||||
nextSelectedScene = mes.Data2; //Get next selected Scene
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (byte) CYL_Command.instaTrig:
|
|
||||||
instaChangeActive = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (byte) CYL_Command.CurrentSelectedScene:
|
|
||||||
currentSelectedScene = mes.Data2; //Get current selected Scene
|
|
||||||
|
|
||||||
if (instaChangeActive) //This triggers instant Switch between states
|
|
||||||
{
|
|
||||||
stateManager.SelectedState = currentSelectedScene;
|
|
||||||
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(instaTransitionSpeed);
|
|
||||||
instaChangeActive = false;
|
|
||||||
}
|
}
|
||||||
break;
|
case CYLCommand.InstantTrigger:
|
||||||
|
|
||||||
case (byte) CYL_Command.FourBarLoopButton:
|
|
||||||
if (nextSelectedScene > currentSelectedScene)
|
|
||||||
{
|
{
|
||||||
RestTime(fourBarTrigger - currentTick % fourBarTrigger);
|
instantChangeActive_ = true;
|
||||||
TimelinePlaybackSpeed((int) Timeline_Command.Forwards);
|
break;
|
||||||
stateManager.SelectedState = nextSelectedScene;
|
}
|
||||||
|
case CYLCommand.CurrentSelectedScene:
|
||||||
|
{
|
||||||
|
currentSelectedScene_ = mes.Data2;
|
||||||
|
|
||||||
|
if (instantChangeActive_)
|
||||||
|
{
|
||||||
|
stateManager.SelectedState = currentSelectedScene_;
|
||||||
|
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(instaTransitionSpeed);
|
||||||
|
instantChangeActive_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CYLCommand.FourBarLoopButton:
|
||||||
|
{
|
||||||
|
if (nextSelectedScene_ > currentSelectedScene_)
|
||||||
|
{
|
||||||
|
UpdateRestTime(FourBarTrigger - currentTick_ % FourBarTrigger);
|
||||||
|
UpdateTimelinePlaybackSpeed(1f);
|
||||||
|
stateManager.SelectedState = nextSelectedScene_;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RestTime(fourBarTrigger - currentTick % fourBarTrigger);
|
UpdateRestTime(FourBarTrigger - currentTick_ % FourBarTrigger);
|
||||||
TimelinePlaybackSpeed((int)Timeline_Command.Backwards);
|
UpdateTimelinePlaybackSpeed(-1f);
|
||||||
stateManager.SelectedState = nextSelectedScene + 2;
|
stateManager.SelectedState = nextSelectedScene_ + 2;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case (byte) CYL_Command.OneBarLoopButton:
|
|
||||||
RestTime(oneBarTrigger - currentTick % oneBarTrigger);
|
|
||||||
TimelinePlaybackSpeed((int) Timeline_Command.Forwards);
|
|
||||||
stateManager.SelectedState = nextSelectedScene;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CYLCommand.OneBarLoopButton:
|
||||||
|
{
|
||||||
|
UpdateRestTime(OneBarTrigger - currentTick_ % OneBarTrigger);
|
||||||
|
UpdateTimelinePlaybackSpeed(1f);
|
||||||
|
stateManager.SelectedState = nextSelectedScene_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new Exception("Unexpected CYL command");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestTime(int restTick)
|
private void UpdateRestTime(int restTicks)
|
||||||
{
|
{
|
||||||
restTimeS = restTick / 24.0f / stateManager.CurrentState.Bpm * 60;
|
restTime_ = restTicks / 24.0f / stateManager.CurrentState.Bpm * 60f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TimelinePlaybackSpeed(int direction)
|
private void UpdateTimelinePlaybackSpeed(float speed)
|
||||||
{
|
{
|
||||||
float timelinePlaybackSpeed = transitionLength / Mathf.Clamp(restTimeS, 0.001f, transitionLength);
|
var timelinePlaybackSpeed = TransitionLength / Mathf.Clamp(restTime_, 0.001f, TransitionLength);
|
||||||
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(timelinePlaybackSpeed * direction); //set playbackspeed of Timeline
|
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(timelinePlaybackSpeed * speed); //set playbackspeed of Timeline
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue