From 9d6e037de9844b64613dc6bec1d3b390e8410a63 Mon Sep 17 00:00:00 2001 From: max Date: Fri, 6 Dec 2019 15:19:36 +0100 Subject: [PATCH] Fixed #125 --- .../PdConnection/MidiTransitionController.cs | 94 +++++++++---------- .../Scripts/StateManagement/StateManager.cs | 2 + .../StreamingAssets/pd/patch/analyzer.pd | 2 +- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs b/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs index 7928702..98388e5 100644 --- a/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs +++ b/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs @@ -4,30 +4,35 @@ using UnityEngine.Timeline; using UnityEngine.Playables; namespace cylvester -{ +{ + + public enum CYL_Command + { + OneBarLoopButton = 86, + FourBarLoopButton = 94, + NextScelectedScene = 18, + CurrentSelectedScene = 17, + instaTrig = 2 + } + public class MidiTransitionController : MonoBehaviour { - [SerializeField] private int oneBarLoopButton = 86; - [SerializeField] private int fourBarLoopButton = 94; - [SerializeField] private PlayableDirector playableDirector; - private int oneBarLoop = 96; - private int fourBarLoop = 384; - private const int cmd_instaTrig = 2; - private const int cmd_nextSelectedScene = 18; - private const int cmd_currentSelectedScene = 17; + [SerializeField] private PlayableDirector playableDirector; + [SerializeField, Range(1, 16)] private int channel = 1; + [SerializeField] StateManager stateManager; + + private const int oneBarLoopLength = 96; + private const int fourBarLoopLength = 384; + private bool instaChangeActive; 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 restTimeS = 1f; //init transTime is 1 Second - [SerializeField] private int currentSelectedScene; - [SerializeField] private int nextSelectedScene; - - [SerializeField, Range(1, 16)] private int channel = 1; - - [SerializeField] StateManager stateManager; + int currentSelectedScene = 0; + int nextSelectedScene = 0; public void OnSyncReceived(MidiSync midiSync, int counter) { @@ -37,49 +42,44 @@ namespace cylvester 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) - { - instaChangeActive = true; - } + case (byte) CYL_Command.instaTrig: + instaChangeActive = true; + break; - if (mes.Data1 == cmd_currentSelectedScene) - { + case (byte) CYL_Command.CurrentSelectedScene: currentSelectedScene = mes.Data2; //Get current selected Scene - if (instaChangeActive) - { - stateManager.SelectedState = currentSelectedScene; - playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(10); - // Debug.Log("Instatrig " + currentSelectedScene); - // Debug.Log("Last selected Scene new " + lastSelectedScene); - instaChangeActive = false; - } - } + if (instaChangeActive) + { + stateManager.SelectedState = currentSelectedScene; + playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(10); + instaChangeActive = false; + } + break; - if (mes.Data1 == oneBarLoopButton) //Button fourBarLoop - { - RestTime(fourBarLoop - currentTick % fourBarLoop); - TimelinePlaybackSpeed(); - stateManager.SelectedState = nextSelectedScene; - } - - if (mes.Data1 == fourBarLoopButton) //Button oneBarLoop - { - RestTime(oneBarLoop - currentTick % oneBarLoop); - TimelinePlaybackSpeed(); - stateManager.SelectedState = nextSelectedScene; - } + case (byte) CYL_Command.FourBarLoopButton: + RestTime(fourBarLoopLength - currentTick % fourBarLoopLength); + TimelinePlaybackSpeed(); + stateManager.SelectedState = nextSelectedScene; + break; + case (byte) CYL_Command.OneBarLoopButton: + RestTime(oneBarLoopLength - currentTick % oneBarLoopLength); + TimelinePlaybackSpeed(); + stateManager.SelectedState = nextSelectedScene; + break; } } + } public void RestTime(int restTick) { diff --git a/UnityProject/Assets/Scripts/StateManagement/StateManager.cs b/UnityProject/Assets/Scripts/StateManagement/StateManager.cs index 2774828..5e628ab 100644 --- a/UnityProject/Assets/Scripts/StateManagement/StateManager.cs +++ b/UnityProject/Assets/Scripts/StateManagement/StateManager.cs @@ -16,6 +16,8 @@ namespace cylvester { int SelectedState { set; } State[] States { get; } + + } public struct State diff --git a/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd b/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd index 997a894..5a284ff 100644 --- a/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd +++ b/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd @@ -420,7 +420,7 @@ 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; -#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 17 7 0 10 -203904 -1 -1; #X obj 192 287 bng 15 250 50 0 1bar_trig_sim empty 1_Bar_trigger_Sim