CylMidiController can drive Timeline forwards and Backwards now

Bug: Playback deosnt stop for reverse.
This commit is contained in:
max 2019-12-06 17:11:43 +01:00
parent 9d6e037de9
commit a757349071
4 changed files with 43 additions and 21 deletions

View file

@ -105,13 +105,13 @@
<Compile Include="Assets\Scripts\Math\BodyHolder.cs" /> <Compile Include="Assets\Scripts\Math\BodyHolder.cs" />
<Compile Include="Assets\Scripts\Math\Smoother.cs" /> <Compile Include="Assets\Scripts\Math\Smoother.cs" />
<Compile Include="Assets\Scripts\Math\Threshold.cs" /> <Compile Include="Assets\Scripts\Math\Threshold.cs" />
<Compile Include="Assets\Scripts\PdConnection\CylMidiTransitionController.cs" />
<Compile Include="Assets\Scripts\PdConnection\DspController.cs" /> <Compile Include="Assets\Scripts\PdConnection\DspController.cs" />
<Compile Include="Assets\Scripts\PdConnection\ISpectrumGenerator.cs" /> <Compile Include="Assets\Scripts\PdConnection\ISpectrumGenerator.cs" />
<Compile Include="Assets\Scripts\PdConnection\MidiLogger.cs" /> <Compile Include="Assets\Scripts\PdConnection\MidiLogger.cs" />
<Compile Include="Assets\Scripts\PdConnection\MidiParser.cs" /> <Compile Include="Assets\Scripts\PdConnection\MidiParser.cs" />
<Compile Include="Assets\Scripts\PdConnection\MidiSequencer.cs" /> <Compile Include="Assets\Scripts\PdConnection\MidiSequencer.cs" />
<Compile Include="Assets\Scripts\PdConnection\MidiSyncedLoop.cs" /> <Compile Include="Assets\Scripts\PdConnection\MidiSyncedLoop.cs" />
<Compile Include="Assets\Scripts\PdConnection\MidiTransitionController.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdArray.cs" /> <Compile Include="Assets\Scripts\PdConnection\PdArray.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdArrayContainer.cs" /> <Compile Include="Assets\Scripts\PdConnection\PdArrayContainer.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdArraySelector.cs" /> <Compile Include="Assets\Scripts\PdConnection\PdArraySelector.cs" />

View file

@ -10,7 +10,7 @@ namespace cylvester
[SerializeField] private PlayableDirector playableDirector; [SerializeField] private PlayableDirector playableDirector;
[SerializeField] private StateManager stateManager; [SerializeField] private StateManager stateManager;
[SerializeField] private float initTransitionFactor = 8f; [SerializeField] private float initTransitionFactor = 1f;
private IList<QlistMarker> qlistMarkers_; private IList<QlistMarker> qlistMarkers_;
@ -48,10 +48,15 @@ namespace cylvester
return; return;
var nextState = stateManager.NextState.Value; var nextState = stateManager.NextState.Value;
if (notification.id == nextState.Title) var prevState = stateManager.PreviousState.Value; //ToDO this is the same as nextState???
Debug.Log("next State " + prevState.Title);
Debug.Log("prev State " + prevState.Title);
if (notification.id == nextState.Title || notification.id == prevState.Title)
{ {
playableDirector.Pause(); // reaches the next state (marker) in timeline playableDirector.Pause(); // reaches the next state (marker) in timeline
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(initTransitionFactor); playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(initTransitionFactor); // Max added this instead of .Stop
} }
} }
} }

View file

@ -5,25 +5,33 @@ using UnityEngine.Playables;
namespace cylvester namespace cylvester
{ {
public enum CYL_Command public enum CYL_Command
{ {
OneBarLoopButton = 86, //these are the midi CCs coming from the CYL_Axoloti box
FourBarLoopButton = 94, OneBarLoopButton = 94,
FourBarLoopButton = 86,
NextScelectedScene = 18, NextScelectedScene = 18,
CurrentSelectedScene = 17, CurrentSelectedScene = 17,
instaTrig = 2 instaTrig = 2,
} }
public class MidiTransitionController : MonoBehaviour public enum Timeline_Command
{
Forwards = 1,
Backwards = -1
}
public class CylMidiTransitionController : MonoBehaviour
{ {
[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] StateManager stateManager;
[SerializeField] float instaTransitionSpeed = 10;
private const int oneBarLoopLength = 96; private const int oneBarTrigger = 96;
private const int fourBarLoopLength = 384; private const int fourBarTrigger = 384;
private bool instaChangeActive; private bool instaChangeActive;
@ -58,23 +66,32 @@ namespace cylvester
case (byte) CYL_Command.CurrentSelectedScene: case (byte) CYL_Command.CurrentSelectedScene:
currentSelectedScene = mes.Data2; //Get current selected Scene currentSelectedScene = mes.Data2; //Get current selected Scene
if (instaChangeActive) if (instaChangeActive) //This triggers instant Switch between states
{ {
stateManager.SelectedState = currentSelectedScene; stateManager.SelectedState = currentSelectedScene;
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(10); playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(instaTransitionSpeed);
instaChangeActive = false; instaChangeActive = false;
} }
break; break;
case (byte) CYL_Command.FourBarLoopButton: case (byte) CYL_Command.FourBarLoopButton:
RestTime(fourBarLoopLength - currentTick % fourBarLoopLength); if (nextSelectedScene > currentSelectedScene)
TimelinePlaybackSpeed(); {
RestTime(fourBarTrigger - currentTick % fourBarTrigger);
TimelinePlaybackSpeed((int) Timeline_Command.Forwards);
stateManager.SelectedState = nextSelectedScene; stateManager.SelectedState = nextSelectedScene;
break; }
else
{
RestTime(fourBarTrigger - currentTick % fourBarTrigger);
TimelinePlaybackSpeed((int)Timeline_Command.Backwards);
stateManager.SelectedState = nextSelectedScene + 2;
}
break;
case (byte) CYL_Command.OneBarLoopButton: case (byte) CYL_Command.OneBarLoopButton:
RestTime(oneBarLoopLength - currentTick % oneBarLoopLength); RestTime(oneBarTrigger - currentTick % oneBarTrigger);
TimelinePlaybackSpeed(); TimelinePlaybackSpeed((int) Timeline_Command.Forwards);
stateManager.SelectedState = nextSelectedScene; stateManager.SelectedState = nextSelectedScene;
break; break;
} }
@ -86,10 +103,10 @@ namespace cylvester
restTimeS = restTick / 24.0f / stateManager.CurrentState.Bpm * 60; restTimeS = restTick / 24.0f / stateManager.CurrentState.Bpm * 60;
} }
public void TimelinePlaybackSpeed() public void TimelinePlaybackSpeed(int direction)
{ {
float 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 playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(timelinePlaybackSpeed * direction); //set playbackspeed of Timeline
} }
} }
} }