handle raw midi data
This commit is contained in:
parent
b56eacd72e
commit
cf59b7f739
9 changed files with 1644 additions and 1570 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@ namespace cylvester
|
|||
public class PdBackendEditor : Editor
|
||||
{
|
||||
private PdBackend pdBackend_;
|
||||
private SerializedProperty controlMessageReceivedProperty_;
|
||||
private SerializedProperty midiMessageReceivedProperty_;
|
||||
|
||||
private readonly string[] samples_ =
|
||||
{
|
||||
|
@ -33,8 +33,8 @@ namespace cylvester
|
|||
|
||||
serializedObject.Update();
|
||||
pdBackend_ = (PdBackend) target;
|
||||
controlMessageReceivedProperty_ = serializedObject.FindProperty("controlMessageReceived");
|
||||
EditorGUILayout.PropertyField(controlMessageReceivedProperty_);
|
||||
midiMessageReceivedProperty_ = serializedObject.FindProperty("midiMessageReceived");
|
||||
EditorGUILayout.PropertyField(midiMessageReceivedProperty_);
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace cylvester
|
||||
{
|
||||
|
@ -8,12 +6,12 @@ namespace cylvester
|
|||
{
|
||||
[SerializeField,Range(1,16)] private int channel = 1;
|
||||
|
||||
public void OnControlMessageReceived(ControlMessage mes)
|
||||
public void OnMidiMessageReceived(MidiMessage mes)
|
||||
{
|
||||
if (mes.Channel == channel - 1)
|
||||
if (mes.Status - 176 == channel - 1)
|
||||
{
|
||||
var x = (mes.ControlNumber - 64) / 10f;
|
||||
var y = (mes.ControlValue - 64) / 10f;
|
||||
var x = (mes.Data1 - 64) / 10f;
|
||||
var y = (mes.Data2 - 64) / 10f;
|
||||
transform.position = new Vector3(x, y, 0f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,18 @@ using UnityEngine.Events;
|
|||
namespace cylvester
|
||||
{
|
||||
[Serializable]
|
||||
public class UnityControlEvent : UnityEvent<ControlMessage>
|
||||
public class UnityControlEvent : UnityEvent<MidiMessage>
|
||||
{}
|
||||
|
||||
public struct ControlMessage
|
||||
public struct MidiMessage
|
||||
{
|
||||
public byte Channel;
|
||||
public byte ControlNumber;
|
||||
public byte ControlValue;
|
||||
public byte Status;
|
||||
public byte Data1;
|
||||
public byte Data2;
|
||||
}
|
||||
|
||||
public interface IMidiParser : IDisposable
|
||||
{
|
||||
event Action<ControlMessage> ControlMessageReceived;
|
||||
event Action<MidiMessage> MidiMessageReceived;
|
||||
}
|
||||
|
||||
public class MidiParser : IMidiParser
|
||||
|
@ -28,13 +27,6 @@ namespace cylvester
|
|||
DataByte2
|
||||
}
|
||||
|
||||
private struct MidiMessage
|
||||
{
|
||||
public byte Status;
|
||||
public byte Data1;
|
||||
public byte Data2;
|
||||
}
|
||||
|
||||
private MidiMessage message_;
|
||||
private Accept accept_ = Accept.StatusByte;
|
||||
private readonly IPdReceiver pdReceiver_;
|
||||
|
@ -74,17 +66,7 @@ namespace cylvester
|
|||
|
||||
private void Invoke()
|
||||
{
|
||||
if (176 <= message_.Status || message_.Status <= 191)
|
||||
{
|
||||
var controlMessage = new ControlMessage
|
||||
{
|
||||
Channel = (byte) (message_.Status - 176),
|
||||
ControlNumber = message_.Data1,
|
||||
ControlValue = message_.Data2
|
||||
};
|
||||
|
||||
ControlMessageReceived?.Invoke(controlMessage);
|
||||
}
|
||||
MidiMessageReceived?.Invoke(message_);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -92,7 +74,7 @@ namespace cylvester
|
|||
pdReceiver_.DataReceived -= onDataReceived_;
|
||||
}
|
||||
|
||||
public event Action<ControlMessage> ControlMessageReceived;
|
||||
public event Action<MidiMessage> MidiMessageReceived;
|
||||
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace cylvester
|
|||
|
||||
public class PdBackend : MonoBehaviour, IPdBackend
|
||||
{
|
||||
[SerializeField] UnityControlEvent controlMessageReceived = null;
|
||||
[SerializeField] UnityControlEvent midiMessageReceived = null;
|
||||
|
||||
public int samplePlayback;
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace cylvester
|
|||
private List<IUpdater> updaters_;
|
||||
|
||||
private Action onSamplePlaybackChanged_;
|
||||
private Action<ControlMessage> onControlMessageReceived_;
|
||||
private Action<MidiMessage> onMidiMessageReceived_;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
@ -53,12 +53,12 @@ namespace cylvester
|
|||
|
||||
onSamplePlaybackChanged_ = () => { pdSender_.Send(new[]{(byte)PdMessage.SampleSound, (byte)samplePlayback}); };
|
||||
|
||||
onControlMessageReceived_ = (message) => {
|
||||
controlMessageReceived.Invoke(message);
|
||||
onMidiMessageReceived_ = (message) => {
|
||||
midiMessageReceived.Invoke(message);
|
||||
};
|
||||
|
||||
samplePlaybackObserver_.ValueChanged += onSamplePlaybackChanged_;
|
||||
midiParser_.ControlMessageReceived += onControlMessageReceived_;
|
||||
midiParser_.MidiMessageReceived += onMidiMessageReceived_;
|
||||
|
||||
dspController_.State = true;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace cylvester
|
|||
dspController_.State = false;
|
||||
pdSender_?.Dispose();
|
||||
samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_;
|
||||
midiParser_.ControlMessageReceived -= onControlMessageReceived_;
|
||||
midiParser_.MidiMessageReceived -= onMidiMessageReceived_;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
|
|
8
UnityProject/Assets/Shader.meta
Normal file
8
UnityProject/Assets/Shader.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a136572b1ed0a3d4baf99141901819b6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -6,6 +6,7 @@
|
|||
"com.unity.analytics": "3.3.2",
|
||||
"com.unity.collab-proxy": "1.2.16",
|
||||
"com.unity.ext.nunit": "1.0.0",
|
||||
"com.unity.ide.rider": "1.1.0",
|
||||
"com.unity.ide.vscode": "1.1.2",
|
||||
"com.unity.multiplayer-hlapi": "1.0.2",
|
||||
"com.unity.package-manager-ui": "2.2.0",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{5B580621-09B4-68CB-B5F4-5B9DD210A60F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{3CC9D2C0-C461-07D9-EDF3-4FFB4DE5C299}"
|
||||
|
|
Loading…
Reference in a new issue