accept MMC start/stop
This commit is contained in:
parent
c87301bf67
commit
90afb6b074
14 changed files with 175 additions and 51 deletions
|
@ -62,6 +62,7 @@
|
||||||
<Compile Include="Assets\Editor\PdBackendEditor.cs" />
|
<Compile Include="Assets\Editor\PdBackendEditor.cs" />
|
||||||
<Compile Include="Assets\Editor\PdSpectrumBindEditor.cs" />
|
<Compile Include="Assets\Editor\PdSpectrumBindEditor.cs" />
|
||||||
<Compile Include="Assets\Editor\RectangularSelection.cs" />
|
<Compile Include="Assets\Editor\RectangularSelection.cs" />
|
||||||
|
<Compile Include="Assets\Editor\SequencerEditor.cs" />
|
||||||
<Compile Include="Assets\Editor\SpectrumGeneratorEditMode.cs" />
|
<Compile Include="Assets\Editor\SpectrumGeneratorEditMode.cs" />
|
||||||
<Compile Include="Assets\Editor\StateManagerEditor.cs" />
|
<Compile Include="Assets\Editor\StateManagerEditor.cs" />
|
||||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_ChangeObserver.cs" />
|
<Compile Include="Assets\Editor\UnitTest\UnitTest_ChangeObserver.cs" />
|
||||||
|
|
|
@ -73,9 +73,9 @@
|
||||||
<Compile Include="Assets\Scripts\Math\Threshold.cs" />
|
<Compile Include="Assets\Scripts\Math\Threshold.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\MidiClockCounter.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\MidiSyncCounter.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" />
|
||||||
|
@ -89,6 +89,7 @@
|
||||||
<Compile Include="Assets\Scripts\PdConnection\PdSender.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\PdSender.cs" />
|
||||||
<Compile Include="Assets\Scripts\PdConnection\PdSpectrumBind.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\PdSpectrumBind.cs" />
|
||||||
<Compile Include="Assets\Scripts\PdConnection\PdTimbreIdBind.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\PdTimbreIdBind.cs" />
|
||||||
|
<Compile Include="Assets\Scripts\PdConnection\Sequencer.cs" />
|
||||||
<Compile Include="Assets\Scripts\PdConnection\Spectrogram.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\Spectrogram.cs" />
|
||||||
<Compile Include="Assets\Scripts\PdConnection\SpectrumGeneratorPlayMode.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\SpectrumGeneratorPlayMode.cs" />
|
||||||
<Compile Include="Assets\Scripts\PdConnection\Waveform.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\Waveform.cs" />
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace cylvester
|
||||||
{
|
{
|
||||||
private PdBackend pdBackend_;
|
private PdBackend pdBackend_;
|
||||||
private SerializedProperty midiMessageReceivedProperty_;
|
private SerializedProperty midiMessageReceivedProperty_;
|
||||||
private SerializedProperty midiClockReceivedProperty_;
|
private SerializedProperty midiSyncReceivedProperty_;
|
||||||
|
|
||||||
private readonly string[] samples_ =
|
private readonly string[] samples_ =
|
||||||
{
|
{
|
||||||
|
@ -38,8 +38,8 @@ namespace cylvester
|
||||||
midiMessageReceivedProperty_ = serializedObject.FindProperty("midiMessageReceived");
|
midiMessageReceivedProperty_ = serializedObject.FindProperty("midiMessageReceived");
|
||||||
EditorGUILayout.PropertyField(midiMessageReceivedProperty_);
|
EditorGUILayout.PropertyField(midiMessageReceivedProperty_);
|
||||||
|
|
||||||
midiClockReceivedProperty_ = serializedObject.FindProperty("midiClockReceived");
|
midiSyncReceivedProperty_ = serializedObject.FindProperty("midiSyncReceived");
|
||||||
EditorGUILayout.PropertyField(midiClockReceivedProperty_);
|
EditorGUILayout.PropertyField(midiSyncReceivedProperty_);
|
||||||
|
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
{
|
{
|
||||||
|
|
34
UnityProject/Assets/Editor/SequencerEditor.cs
Normal file
34
UnityProject/Assets/Editor/SequencerEditor.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace cylvester
|
||||||
|
{
|
||||||
|
[CustomEditor(typeof(Sequencer))]
|
||||||
|
public class SequencerEditor : Editor
|
||||||
|
{
|
||||||
|
private SerializedProperty sequenceProperty_;
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
sequenceProperty_ = serializedObject.FindProperty("sequence");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
serializedObject.Update ();
|
||||||
|
EditorGUILayout.BeginHorizontal();
|
||||||
|
EditorGUILayout.LabelField("Trigger on:", GUILayout.Width(200));
|
||||||
|
EditorGUILayout.BeginHorizontal(GUILayout.Width(160));
|
||||||
|
|
||||||
|
for (var i = 0; i < 16; ++i)
|
||||||
|
{
|
||||||
|
sequenceProperty_.GetArrayElementAtIndex(i).boolValue
|
||||||
|
= EditorGUILayout.Toggle(sequenceProperty_.GetArrayElementAtIndex(i).boolValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
|
serializedObject.ApplyModifiedProperties ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
UnityProject/Assets/Editor/SequencerEditor.cs.meta
Normal file
11
UnityProject/Assets/Editor/SequencerEditor.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 271cb432726f4f145aef895a05d2a97a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -480,6 +480,7 @@ GameObject:
|
||||||
- component: {fileID: 1261823480}
|
- component: {fileID: 1261823480}
|
||||||
- component: {fileID: 1261823482}
|
- component: {fileID: 1261823482}
|
||||||
- component: {fileID: 1261823483}
|
- component: {fileID: 1261823483}
|
||||||
|
- component: {fileID: 1261823484}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: PdBackend
|
m_Name: PdBackend
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -524,12 +525,12 @@ MonoBehaviour:
|
||||||
m_StringArgument:
|
m_StringArgument:
|
||||||
m_BoolArgument: 0
|
m_BoolArgument: 0
|
||||||
m_CallState: 2
|
m_CallState: 2
|
||||||
midiClockReceived:
|
midiSyncReceived:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls:
|
m_Calls:
|
||||||
- m_Target: {fileID: 1261823483}
|
- m_Target: {fileID: 1261823483}
|
||||||
m_MethodName: onClockReceived
|
m_MethodName: OnSyncReceived
|
||||||
m_Mode: 1
|
m_Mode: 0
|
||||||
m_Arguments:
|
m_Arguments:
|
||||||
m_ObjectArgument: {fileID: 0}
|
m_ObjectArgument: {fileID: 0}
|
||||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||||
|
@ -539,8 +540,8 @@ MonoBehaviour:
|
||||||
m_BoolArgument: 0
|
m_BoolArgument: 0
|
||||||
m_CallState: 2
|
m_CallState: 2
|
||||||
- m_Target: {fileID: 669316603}
|
- m_Target: {fileID: 669316603}
|
||||||
m_MethodName: onClockReceived
|
m_MethodName: onSyncReceived
|
||||||
m_Mode: 1
|
m_Mode: 0
|
||||||
m_Arguments:
|
m_Arguments:
|
||||||
m_ObjectArgument: {fileID: 0}
|
m_ObjectArgument: {fileID: 0}
|
||||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||||
|
@ -592,6 +593,19 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
counter: {fileID: 1790437805}
|
counter: {fileID: 1790437805}
|
||||||
|
--- !u!114 &1261823484
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1261823479}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 6ebe1124d37e04742be155475d179a67, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
sequence: 00000000000000000000000000000000
|
||||||
--- !u!1 &1461024797
|
--- !u!1 &1461024797
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using UnityEngine;
|
using cylvester;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
public class CubeSync : MonoBehaviour
|
public class CubeSync : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
@ -8,15 +9,18 @@ public class CubeSync : MonoBehaviour
|
||||||
private float lastCallBack_;
|
private float lastCallBack_;
|
||||||
private float callbackInterval_ = 0.05f;
|
private float callbackInterval_ = 0.05f;
|
||||||
|
|
||||||
public void onClockReceived()
|
public void onSyncReceived(MidiSync midiSync)
|
||||||
{
|
{
|
||||||
var now = Time.realtimeSinceStartup;
|
if (midiSync == MidiSync.Clock)
|
||||||
callbackInterval_ = now - lastCallBack_;
|
{
|
||||||
lastCallBack_ = now;
|
var now = Time.realtimeSinceStartup;
|
||||||
currentX_ = (counter_ - 12) * 0.2f;
|
callbackInterval_ = now - lastCallBack_;
|
||||||
counter_++;
|
lastCallBack_ = now;
|
||||||
targetX_ = (counter_ - 12) * 0.2f;
|
currentX_ = (counter_ - 12) * 0.2f;
|
||||||
counter_ %= 24;
|
counter_++;
|
||||||
|
targetX_ = (counter_ - 12) * 0.2f;
|
||||||
|
counter_ %= 24;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
public class MidiClockCounter : MonoBehaviour
|
|
||||||
{
|
|
||||||
|
|
||||||
[SerializeField] private Text counter;
|
|
||||||
|
|
||||||
private int count_ = 0;
|
|
||||||
|
|
||||||
public void onClockReceived()
|
|
||||||
{
|
|
||||||
count_++;
|
|
||||||
var tick = count_ % 24;
|
|
||||||
var beat = count_ / 24;
|
|
||||||
var measure = beat / 4;
|
|
||||||
|
|
||||||
counter.text = (measure+1) + ":" + (beat%4+1) + ":" + tick;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,6 +7,17 @@ namespace cylvester
|
||||||
public class UnityMidiEvent : UnityEvent<MidiMessage>
|
public class UnityMidiEvent : UnityEvent<MidiMessage>
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class UnitySyncEvent : UnityEvent<MidiSync>
|
||||||
|
{}
|
||||||
|
|
||||||
|
public enum MidiSync
|
||||||
|
{
|
||||||
|
Start = 250,
|
||||||
|
Stop = 252,
|
||||||
|
Clock = 248,
|
||||||
|
}
|
||||||
|
|
||||||
public struct MidiMessage
|
public struct MidiMessage
|
||||||
{
|
{
|
||||||
public byte Status;
|
public byte Status;
|
||||||
|
@ -24,8 +35,7 @@ namespace cylvester
|
||||||
public interface IMidiParser : IDisposable
|
public interface IMidiParser : IDisposable
|
||||||
{
|
{
|
||||||
event Action<MidiMessage> MidiMessageReceived;
|
event Action<MidiMessage> MidiMessageReceived;
|
||||||
event Action MidiClockReceived;
|
event Action<MidiSync> MidiSyncReceived;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MidiParser : IMidiParser
|
public class MidiParser : IMidiParser
|
||||||
|
@ -41,7 +51,6 @@ namespace cylvester
|
||||||
private Accept accept_ = Accept.StatusByte;
|
private Accept accept_ = Accept.StatusByte;
|
||||||
private readonly IPdReceiver pdReceiver_;
|
private readonly IPdReceiver pdReceiver_;
|
||||||
private readonly Action<byte[]> onDataReceived_;
|
private readonly Action<byte[]> onDataReceived_;
|
||||||
private static byte MIDI_CLOCK = 248;
|
|
||||||
|
|
||||||
public MidiParser(IPdReceiver pdReceiver)
|
public MidiParser(IPdReceiver pdReceiver)
|
||||||
{
|
{
|
||||||
|
@ -51,8 +60,8 @@ namespace cylvester
|
||||||
{
|
{
|
||||||
foreach (var element in bytes)
|
foreach (var element in bytes)
|
||||||
{
|
{
|
||||||
if (element == MIDI_CLOCK)
|
if (ProcessSyncByte(element))
|
||||||
MidiClockReceived?.Invoke();
|
continue;
|
||||||
|
|
||||||
if (element >= 128)
|
if (element >= 128)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +92,18 @@ namespace cylvester
|
||||||
pdReceiver_.DataReceived -= onDataReceived_;
|
pdReceiver_.DataReceived -= onDataReceived_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ProcessSyncByte(byte element)
|
||||||
|
{
|
||||||
|
if (element != (byte)MidiSync.Clock &&
|
||||||
|
element != (byte)MidiSync.Start &&
|
||||||
|
element != (byte)MidiSync.Stop)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
MidiSyncReceived?.Invoke((MidiSync)element);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public event Action<MidiMessage> MidiMessageReceived;
|
public event Action<MidiMessage> MidiMessageReceived;
|
||||||
public event Action MidiClockReceived;
|
public event Action<MidiSync> MidiSyncReceived;
|
||||||
}
|
}
|
||||||
}
|
}
|
33
UnityProject/Assets/Scripts/PdConnection/MidiSyncCounter.cs
Normal file
33
UnityProject/Assets/Scripts/PdConnection/MidiSyncCounter.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using cylvester;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class MidiSyncCounter : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
[SerializeField] private Text counter;
|
||||||
|
|
||||||
|
private int count_ = 0;
|
||||||
|
|
||||||
|
public void OnSyncReceived(MidiSync midiSync)
|
||||||
|
{
|
||||||
|
if (midiSync == MidiSync.Clock)
|
||||||
|
{
|
||||||
|
count_++;
|
||||||
|
var tick = count_ % 24;
|
||||||
|
var beat = count_ / 24;
|
||||||
|
var measure = beat / 4;
|
||||||
|
|
||||||
|
counter.text = (measure + 1) + ":" + (beat % 4 + 1) + ":" + tick;
|
||||||
|
}
|
||||||
|
else if (midiSync == MidiSync.Start)
|
||||||
|
{
|
||||||
|
Debug.Log("playback started");
|
||||||
|
count_ = 0;
|
||||||
|
}
|
||||||
|
else if (midiSync == MidiSync.Stop)
|
||||||
|
{
|
||||||
|
Debug.Log("playback ended");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ namespace cylvester
|
||||||
public class PdBackend : MonoBehaviour, IPdBackend
|
public class PdBackend : MonoBehaviour, IPdBackend
|
||||||
{
|
{
|
||||||
[SerializeField] UnityMidiEvent midiMessageReceived = null;
|
[SerializeField] UnityMidiEvent midiMessageReceived = null;
|
||||||
[SerializeField] UnityEvent midiClockReceived = null;
|
[SerializeField] UnitySyncEvent midiSyncReceived = null;
|
||||||
|
|
||||||
public int samplePlayback;
|
public int samplePlayback;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace cylvester
|
||||||
|
|
||||||
private Action onSamplePlaybackChanged_;
|
private Action onSamplePlaybackChanged_;
|
||||||
private Action<MidiMessage> onMidiMessageReceived_;
|
private Action<MidiMessage> onMidiMessageReceived_;
|
||||||
private Action onMidiClockReceived_;
|
private Action<MidiSync> onMidiSyncReceived_;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
@ -72,11 +72,11 @@ namespace cylvester
|
||||||
};
|
};
|
||||||
|
|
||||||
onMidiMessageReceived_ = (message) => { midiMessageReceived.Invoke(message); };
|
onMidiMessageReceived_ = (message) => { midiMessageReceived.Invoke(message); };
|
||||||
onMidiClockReceived_ = () => { midiClockReceived.Invoke(); };
|
onMidiSyncReceived_ = (sync) => { midiSyncReceived.Invoke(sync); };
|
||||||
|
|
||||||
samplePlaybackObserver_.ValueChanged += onSamplePlaybackChanged_;
|
samplePlaybackObserver_.ValueChanged += onSamplePlaybackChanged_;
|
||||||
midiParser_.MidiMessageReceived += onMidiMessageReceived_;
|
midiParser_.MidiMessageReceived += onMidiMessageReceived_;
|
||||||
midiParser_.MidiClockReceived += onMidiClockReceived_;
|
midiParser_.MidiSyncReceived += onMidiSyncReceived_;
|
||||||
dspController_.State = true;
|
dspController_.State = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ namespace cylvester
|
||||||
pdSender_?.Dispose();
|
pdSender_?.Dispose();
|
||||||
samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_;
|
samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_;
|
||||||
midiParser_.MidiMessageReceived -= onMidiMessageReceived_;
|
midiParser_.MidiMessageReceived -= onMidiMessageReceived_;
|
||||||
midiParser_.MidiClockReceived -= onMidiClockReceived_;
|
midiParser_.MidiSyncReceived -= onMidiSyncReceived_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
UnityProject/Assets/Scripts/PdConnection/Sequencer.cs
Normal file
16
UnityProject/Assets/Scripts/PdConnection/Sequencer.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace cylvester
|
||||||
|
{
|
||||||
|
public class Sequencer : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private bool[] sequence = new bool[16];
|
||||||
|
|
||||||
|
private void OnValidate()
|
||||||
|
{
|
||||||
|
if(sequence.Length != 16)
|
||||||
|
Array.Resize(ref sequence, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
UnityProject/Assets/Scripts/PdConnection/Sequencer.cs.meta
Normal file
11
UnityProject/Assets/Scripts/PdConnection/Sequencer.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6ebe1124d37e04742be155475d179a67
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in a new issue