From 324816de023da87a42dc863a4d16cb9f0d7343f3 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 5 Dec 2019 22:08:56 +0100 Subject: [PATCH] Implement CYLtransitions into MidiTransitionController Closes #121 --- .../Qlist/scripts/TimelineController.cs | 4 +- .../VisualEffectGraph/Animation.playable | 4 +- .../VisualEffectGraph/VFX Graph Plane.unity | 18 ++++---- .../Force Position Texture.vfx | 4 +- .../PdConnection/MidiTransitionController.cs | 43 +++++++++++++++++-- .../Scripts/StateManagement/StateManager.cs | 27 +++++++++++- .../StreamingAssets/pd/patch/analyzer.pd | 16 +++---- .../StreamingAssets/qlist_VFX_Graph_Demo.csv | 12 +++--- 8 files changed, 92 insertions(+), 36 deletions(-) diff --git a/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs b/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs index 7165cc7..f111a5a 100644 --- a/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs +++ b/UnityProject/Assets/Scenes/Examples/Qlist/scripts/TimelineController.cs @@ -10,7 +10,7 @@ namespace cylvester [SerializeField] private PlayableDirector playableDirector; [SerializeField] private StateManager stateManager; - [SerializeField] private float initTransitionTime = 16f; + [SerializeField] private float initTransitionFactor = 8f; private IList qlistMarkers_; @@ -51,7 +51,7 @@ namespace cylvester if (notification.id == nextState.Title) { playableDirector.Pause(); // reaches the next state (marker) in timeline - playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(1); + playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(initTransitionFactor); } } } diff --git a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/Animation.playable b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/Animation.playable index 034e7fe..c24b796 100644 --- a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/Animation.playable +++ b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/Animation.playable @@ -1054,9 +1054,7 @@ MonoBehaviour: m_Name: Qlist Marker m_EditorClassIdentifier: m_Time: 80 - stateName: 'ShowAll - -' + stateName: ShowAll --- !u!114 &-2843494771311315102 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity index 73e4df1..6423745 100644 --- a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity +++ b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.0013421604, g: 0.0011744275, b: 0.0008066663, a: 1} + m_IndirectSpecularColor: {r: 0.0013490503, g: 0.0011814049, b: 0.0008122615, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -195,6 +195,9 @@ MonoBehaviour: oneBarLoopButton: 86 fourBarLoopButton: 94 playableDirector: {fileID: 65620552} + lastSelectedScene: 0 + currentSelectedScene: 0 + nextSelectedScene: 0 channel: 3 stateManager: {fileID: 850208555} --- !u!114 &65620555 @@ -211,8 +214,7 @@ MonoBehaviour: m_EditorClassIdentifier: playableDirector: {fileID: 65620552} stateManager: {fileID: 850208555} - transitionController: {fileID: 65620554} - initTransitionTime: 16 + initTransitionFactor: 8 --- !u!1 &155821760 GameObject: m_ObjectHideFlags: 0 @@ -809,7 +811,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: attackSmooth: 1 - releaseSmooth: 1 + releaseSmooth: 3.44 ignore0: 0 onSmoothProcessed: m_PersistentCalls: @@ -880,7 +882,7 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 - channel: 0 + channel: 5 --- !u!1 &736002103 GameObject: m_ObjectHideFlags: 0 @@ -1240,7 +1242,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 41f237c64f02a2241a30c5c0b5c087e6, type: 3} m_Name: m_EditorClassIdentifier: - logAll: 0 + logAll: 1 logFiltered: 0 filterStatusByte: 128 --- !u!1 &859452785 @@ -1617,7 +1619,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: attackSmooth: 1 - releaseSmooth: 1 + releaseSmooth: 2 ignore0: 0 onSmoothProcessed: m_PersistentCalls: @@ -1688,7 +1690,7 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 - channel: 0 + channel: 4 --- !u!1 &1471219110 GameObject: m_ObjectHideFlags: 0 diff --git a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane/Force Position Texture.vfx b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane/Force Position Texture.vfx index 6180d2c..2904a4b 100644 --- a/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane/Force Position Texture.vfx +++ b/UnityProject/Assets/Scenes/Examples/VisualEffectGraph/VFX Graph Plane/Force Position Texture.vfx @@ -147,9 +147,9 @@ MonoBehaviour: uiBounds: serializedVersion: 2 x: -2339 - y: -232 + y: -231 width: 3713 - height: 3104 + height: 3101 --- !u!114 &114350483966674976 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs b/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs index 6ebd5d8..aa3e570 100644 --- a/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs +++ b/UnityProject/Assets/Scripts/PdConnection/MidiTransitionController.cs @@ -13,15 +13,23 @@ namespace cylvester private int oneBarLoop = 96; private int fourBarLoop = 384; + private int instaTrig = 2; + private int nextSelectedSceneOutput = 18; + private int lastSelectedSceneOutput = 17; + 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 lastSelectedScene = 0; + [SerializeField] private int currentSelectedScene = 0; + [SerializeField] private int nextSelectedScene; + [SerializeField, Range(1, 16)] private int channel = 1; [SerializeField] StateManager stateManager; - public void OnSyncReceived(MidiSync midiSync, int counter) { currentTick = counter; @@ -29,18 +37,46 @@ namespace cylvester public void OnMidiMessageReceived(MidiMessage mes) { + if (mes.Status - 176 == channel - 1) //Which Channel { + + if (mes.Data1 == nextSelectedSceneOutput) + { + nextSelectedScene = mes.Data2; //Get next Schene Update + } + + if (mes.Data1 == lastSelectedSceneOutput) + lastSelectedScene = mes.Data2; //Get current selected Scene + 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; + } + + if (mes.Data1 == instaTrig) + { + instaChangeActive = true; + + if (instaChangeActive && (currentSelectedScene != lastSelectedScene)) + { + currentSelectedScene = lastSelectedScene; + stateManager.SelectedState = lastSelectedScene; + playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(10); + Debug.Log("Instatrig " + currentSelectedScene); + Debug.Log("Last selected Scene new " + lastSelectedScene); + instaChangeActive = false; + } + } } } @@ -50,10 +86,9 @@ namespace cylvester restTimeS = restTick / 24.0f / stateManager.CurrentState.Bpm * 60; } - public void TimelinePlaybackSpeed () + public void TimelinePlaybackSpeed() { - float timelinePlaybackSpeed; - timelinePlaybackSpeed = transitionLength / Mathf.Clamp(restTimeS, 0.001f, transitionLength); + float timelinePlaybackSpeed = transitionLength / Mathf.Clamp(restTimeS, 0.001f, transitionLength); playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(timelinePlaybackSpeed); //set playbackspeed of Timeline } } diff --git a/UnityProject/Assets/Scripts/StateManagement/StateManager.cs b/UnityProject/Assets/Scripts/StateManagement/StateManager.cs index 7e17720..2774828 100644 --- a/UnityProject/Assets/Scripts/StateManagement/StateManager.cs +++ b/UnityProject/Assets/Scripts/StateManagement/StateManager.cs @@ -33,7 +33,7 @@ namespace cylvester public class StateManager : MonoBehaviour, IStateManager { - private enum Operation + public enum Operation { Rewind = 0, Previous = 1, @@ -85,6 +85,8 @@ namespace cylvester sceneSelection = value; onStateChanged.Invoke(this); } + get + { return sceneSelection; } } public void OnMidiReceived(MidiMessage message) @@ -110,6 +112,29 @@ namespace cylvester } onStateChanged.Invoke(this); } + + public void OnStateChanged(Operation operation) + { + + switch (operation) + { + case Operation.Rewind: + if (sceneSelection == 0) return; + sceneSelection = 0; + break; + case Operation.Previous: + if (sceneSelection == 0) return; + sceneSelection--; + break; + case Operation.Next: + if (sceneSelection >= States.Length - 1) return; + sceneSelection++; + break; + default: + return; + } + onStateChanged.Invoke(this); + } } } \ No newline at end of file diff --git a/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd b/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd index 965b2c5..997a894 100644 --- a/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd +++ b/UnityProject/Assets/StreamingAssets/pd/patch/analyzer.pd @@ -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 PositionCloud 20 12 0 45 --204786 -66577 0; +#X obj 598 90 cnv 15 500 60 empty current PontCloud 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 786 304 send 176 127 2; -#X obj 594 46 cnv 12 500 30 empty previous PontCloud 20 12 0 25 -262130 +#X obj 594 46 cnv 12 500 30 empty previous needles 20 12 0 25 -262130 +-66577 0; +#X obj 596 152 cnv 12 500 30 empty next PositionCloud 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,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 -2849 181 1014 1074 CYLVESTERmidi 1; +#N canvas 700 143 1014 1074 CYLVESTERmidi 1; #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 @@ -803,8 +803,6 @@ samples/kick.wav kick \, read -resize samples/closed.wav closed; #X connect 58 0 47 0; #X restore 598 377 pd CYLVESTERmidi; #X text 701 378 <--- this is only for reference; -#X obj 758 193 ctlin 94 3; -#X obj 845 191 ctlin 86 3; #X connect 0 0 2 0; #X connect 0 1 2 1; #X connect 0 2 2 2; @@ -845,5 +843,3 @@ 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 40 0 25 0; -#X connect 41 0 25 0; diff --git a/UnityProject/Assets/StreamingAssets/qlist_VFX_Graph_Demo.csv b/UnityProject/Assets/StreamingAssets/qlist_VFX_Graph_Demo.csv index f455122..ab45fd0 100644 --- a/UnityProject/Assets/StreamingAssets/qlist_VFX_Graph_Demo.csv +++ b/UnityProject/Assets/StreamingAssets/qlist_VFX_Graph_Demo.csv @@ -1,7 +1,7 @@ Scene Title,BPM,Notes -Intro,162,Show all -needles,162,only needles -PontCloud,162,only points -PositionCloud,162,only points different view -Forces,162,only forces -ShowAll,162,all again different poisition \ No newline at end of file +Intro,120,Show all +needles,120,only needles +PontCloud,120,only points +PositionCloud,120,only points different view +Forces,120,only forces +ShowAll,120,all again different poisition \ No newline at end of file