2019-10-30 14:01:06 +00:00
|
|
|
|
using cylvester;
|
|
|
|
|
using UnityEngine;
|
2019-10-27 11:52:36 +00:00
|
|
|
|
|
|
|
|
|
public class CubeSync : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private float currentX_;
|
|
|
|
|
private float targetX_;
|
|
|
|
|
private float lastCallBack_;
|
|
|
|
|
private float callbackInterval_ = 0.05f;
|
|
|
|
|
|
2019-10-30 15:02:20 +00:00
|
|
|
|
public void OnSyncReceived(MidiSync midiSync, int count)
|
2019-10-27 11:52:36 +00:00
|
|
|
|
{
|
2019-10-30 14:01:06 +00:00
|
|
|
|
if (midiSync == MidiSync.Clock)
|
|
|
|
|
{
|
|
|
|
|
var now = Time.realtimeSinceStartup;
|
|
|
|
|
callbackInterval_ = now - lastCallBack_;
|
|
|
|
|
lastCallBack_ = now;
|
2019-10-30 15:02:20 +00:00
|
|
|
|
currentX_ = (count % 24 - 12) * 0.2f;
|
|
|
|
|
targetX_ = (count % 24 - 12) * 0.2f;
|
2019-10-30 14:01:06 +00:00
|
|
|
|
}
|
2019-10-27 11:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
var timeSinceLastCallback = Time.realtimeSinceStartup - lastCallBack_;
|
|
|
|
|
var elapsedRatio = timeSinceLastCallback / callbackInterval_;
|
|
|
|
|
var animationX = Mathf.Lerp(currentX_, targetX_, elapsedRatio);
|
|
|
|
|
transform.position = new Vector3(animationX, 0f, 0f);
|
|
|
|
|
}
|
|
|
|
|
}
|