2019-10-30 14:01:06 +00:00
|
|
|
|
using cylvester;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class MidiSyncCounter : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Text counter;
|
2020-01-21 22:31:06 +00:00
|
|
|
|
|
2019-10-30 14:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-30 15:02:20 +00:00
|
|
|
|
public void OnSyncReceived(MidiSync midiSync, int count)
|
2019-10-30 14:01:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (midiSync == MidiSync.Clock)
|
|
|
|
|
{
|
2019-10-30 15:02:20 +00:00
|
|
|
|
var tick = count % 24;
|
|
|
|
|
var beat = count / 24;
|
2019-10-30 14:01:06 +00:00
|
|
|
|
var measure = beat / 4;
|
|
|
|
|
|
|
|
|
|
counter.text = (measure + 1) + ":" + (beat % 4 + 1) + ":" + tick;
|
|
|
|
|
}
|
|
|
|
|
else if (midiSync == MidiSync.Start)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("playback started");
|
|
|
|
|
}
|
|
|
|
|
else if (midiSync == MidiSync.Stop)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("playback ended");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|