This commit is contained in:
max 2019-12-06 15:19:36 +01:00
parent 2955f202a7
commit 9d6e037de9
3 changed files with 50 additions and 48 deletions

View file

@ -5,29 +5,34 @@ using UnityEngine.Playables;
namespace cylvester namespace cylvester
{ {
public enum CYL_Command
{
OneBarLoopButton = 86,
FourBarLoopButton = 94,
NextScelectedScene = 18,
CurrentSelectedScene = 17,
instaTrig = 2
}
public class MidiTransitionController : MonoBehaviour public class MidiTransitionController : MonoBehaviour
{ {
[SerializeField] private int oneBarLoopButton = 86;
[SerializeField] private int fourBarLoopButton = 94;
[SerializeField] private PlayableDirector playableDirector;
private int oneBarLoop = 96; [SerializeField] private PlayableDirector playableDirector;
private int fourBarLoop = 384; [SerializeField, Range(1, 16)] private int channel = 1;
private const int cmd_instaTrig = 2; [SerializeField] StateManager stateManager;
private const int cmd_nextSelectedScene = 18;
private const int cmd_currentSelectedScene = 17; private const int oneBarLoopLength = 96;
private const int fourBarLoopLength = 384;
private bool instaChangeActive; private bool instaChangeActive;
private int currentTick; private int currentTick;
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 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 float restTimeS = 1f; //init transTime is 1 Second private float restTimeS = 1f; //init transTime is 1 Second
[SerializeField] private int currentSelectedScene; int currentSelectedScene = 0;
[SerializeField] private int nextSelectedScene; int nextSelectedScene = 0;
[SerializeField, Range(1, 16)] private int channel = 1;
[SerializeField] StateManager stateManager;
public void OnSyncReceived(MidiSync midiSync, int counter) public void OnSyncReceived(MidiSync midiSync, int counter)
{ {
@ -37,47 +42,42 @@ namespace cylvester
public void OnMidiMessageReceived(MidiMessage mes) public void OnMidiMessageReceived(MidiMessage mes)
{ {
if (mes.Status - 176 == channel - 1) //Which Channel if (mes.Status - 176 == channel - 1) //Choose Midi-Channel
{ {
if (mes.Data1 == cmd_nextSelectedScene) switch (mes.Data1)
{ {
nextSelectedScene = mes.Data2; //Get next Schene Update case (byte) CYL_Command.NextScelectedScene:
} nextSelectedScene = mes.Data2; //Get next selected Scene
break;
if (mes.Data1 == cmd_instaTrig) case (byte) CYL_Command.instaTrig:
{
instaChangeActive = true; instaChangeActive = true;
} break;
if (mes.Data1 == cmd_currentSelectedScene) case (byte) CYL_Command.CurrentSelectedScene:
{
currentSelectedScene = mes.Data2; //Get current selected Scene currentSelectedScene = mes.Data2; //Get current selected Scene
if (instaChangeActive) if (instaChangeActive)
{ {
stateManager.SelectedState = currentSelectedScene; stateManager.SelectedState = currentSelectedScene;
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(10); playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(10);
// Debug.Log("Instatrig " + currentSelectedScene);
// Debug.Log("Last selected Scene new " + lastSelectedScene);
instaChangeActive = false; instaChangeActive = false;
} }
} break;
if (mes.Data1 == oneBarLoopButton) //Button fourBarLoop case (byte) CYL_Command.FourBarLoopButton:
{ RestTime(fourBarLoopLength - currentTick % fourBarLoopLength);
RestTime(fourBarLoop - currentTick % fourBarLoop);
TimelinePlaybackSpeed(); TimelinePlaybackSpeed();
stateManager.SelectedState = nextSelectedScene; stateManager.SelectedState = nextSelectedScene;
} break;
if (mes.Data1 == fourBarLoopButton) //Button oneBarLoop case (byte) CYL_Command.OneBarLoopButton:
{ RestTime(oneBarLoopLength - currentTick % oneBarLoopLength);
RestTime(oneBarLoop - currentTick % oneBarLoop);
TimelinePlaybackSpeed(); TimelinePlaybackSpeed();
stateManager.SelectedState = nextSelectedScene; stateManager.SelectedState = nextSelectedScene;
break;
} }
} }
} }

View file

@ -16,6 +16,8 @@ namespace cylvester
{ {
int SelectedState { set; } int SelectedState { set; }
State[] States { get; } State[] States { get; }
} }
public struct State public struct State

View file

@ -420,7 +420,7 @@ samples/kick.wav kick \, read -resize samples/closed.wav closed;
#X connect 5 0 4 0; #X connect 5 0 4 0;
#X connect 6 0 7 0; #X connect 6 0 7 0;
#X restore 405 71 pd shmem; #X restore 405 71 pd shmem;
#N canvas 700 143 1014 1074 CYLVESTERmidi 1; #N canvas 700 143 1014 1074 CYLVESTERmidi 0;
#X obj 192 306 bng 15 250 50 0 4bar_trig_sim empty 4_Bar_trigger_Sim #X obj 192 306 bng 15 250 50 0 4bar_trig_sim empty 4_Bar_trigger_Sim
17 7 0 10 -203904 -1 -1; 17 7 0 10 -203904 -1 -1;
#X obj 192 287 bng 15 250 50 0 1bar_trig_sim empty 1_Bar_trigger_Sim #X obj 192 287 bng 15 250 50 0 1bar_trig_sim empty 1_Bar_trigger_Sim