soundvision/UnityProject/Assets/Scenes/Examples/MIDI/script/MidiSyncCounter.cs

31 lines
688 B
C#
Raw Normal View History

2019-10-30 14:01:06 +00:00
using cylvester;
using UnityEngine;
using UnityEngine.UI;
public class MidiSyncCounter : MonoBehaviour
{
[SerializeField] private Text counter;
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");
}
}
}