From 386757c9d7aaf20d756a2acb36386bc852a75a61 Mon Sep 17 00:00:00 2001 From: Chikashi Miyama Date: Sat, 26 Oct 2019 22:45:33 +0200 Subject: [PATCH] add midi logger --- UnityProject/Assembly-CSharp-Editor.csproj | 6 ++-- UnityProject/Assembly-CSharp.csproj | 7 ++-- .../Assets/Scenes/Examples/MIDI/MIDI.unity | 33 +++++++++++++++++-- .../Assets/Scripts/PdConnection/MidiLogger.cs | 25 ++++++++++++++ .../Scripts/PdConnection/MidiLogger.cs.meta | 11 +++++++ .../Assets/Scripts/PdConnection/MidiParser.cs | 8 +++++ 6 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs create mode 100644 UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs.meta diff --git a/UnityProject/Assembly-CSharp-Editor.csproj b/UnityProject/Assembly-CSharp-Editor.csproj index 2e6f340..7e735fa 100644 --- a/UnityProject/Assembly-CSharp-Editor.csproj +++ b/UnityProject/Assembly-CSharp-Editor.csproj @@ -121,6 +121,9 @@ C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/UnityEngine.XR.LegacyInputHelpers.dll + + C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/Unity.Rider.Editor.dll + C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary.dll @@ -163,9 +166,6 @@ C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/com.unity.multiplayer-hlapi.Runtime.dll - - C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/Unity.Rider.Editor.dll - C:/Program Files/Unity_2019.2.8f1/Editor/Data/Managed/UnityEngine/UnityEngine.AIModule.dll diff --git a/UnityProject/Assembly-CSharp.csproj b/UnityProject/Assembly-CSharp.csproj index 29d7a7d..7bf1c50 100644 --- a/UnityProject/Assembly-CSharp.csproj +++ b/UnityProject/Assembly-CSharp.csproj @@ -142,6 +142,7 @@ + @@ -344,6 +345,9 @@ C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/UnityEngine.XR.LegacyInputHelpers.dll + + C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/Unity.Rider.Editor.dll + C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary.dll @@ -386,9 +390,6 @@ C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/com.unity.multiplayer-hlapi.Runtime.dll - - C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/Unity.Rider.Editor.dll - C:/Program Files/Unity_2019.2.8f1/Editor/Data/Managed/UnityEngine/UnityEngine.AIModule.dll diff --git a/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity b/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity index 8c36672..4f0745f 100644 --- a/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity +++ b/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity @@ -222,6 +222,7 @@ GameObject: m_Component: - component: {fileID: 1261823481} - component: {fileID: 1261823480} + - component: {fileID: 1261823482} m_Layer: 0 m_Name: PdBackend m_TagString: Untagged @@ -241,11 +242,22 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3ba69cee3466a304d9d570268f717413, type: 3} m_Name: m_EditorClassIdentifier: - onControlMessageReceived: + midiMessageReceived: m_PersistentCalls: m_Calls: - m_Target: {fileID: 265790068} - m_MethodName: OnControlMessageReceived + m_MethodName: OnMidiMessageReceived + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 1261823482} + m_MethodName: OnMidiMessageReceived m_Mode: 0 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -270,6 +282,21 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1261823482 +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: 41f237c64f02a2241a30c5c0b5c087e6, type: 3} + m_Name: + m_EditorClassIdentifier: + logAll: 0 + logFiltered: 0 + filterStatusByte: 176 --- !u!1 &1461024797 GameObject: m_ObjectHideFlags: 0 @@ -348,7 +375,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1461024797} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.18, z: -2.08} + m_LocalPosition: {x: 0, y: -0.18, z: -14.47} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} diff --git a/UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs b/UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs new file mode 100644 index 0000000..942b23f --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace cylvester +{ + public class MidiLogger : MonoBehaviour + { + [SerializeField] private bool logAll; + [SerializeField] private bool logFiltered; + [SerializeField, Range(128, 255)] private int filterStatusByte = 128; + + public void OnMidiMessageReceived(MidiMessage mes) + { + if(logAll) + Debug.Log("MIDI Received: " + mes); + + if(logFiltered) + { + if (mes.Status == filterStatusByte) + { + Debug.Log("Filtered MIDI Received: " + mes); + } + } + } + } +} diff --git a/UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs.meta b/UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs.meta new file mode 100644 index 0000000..057f7fa --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection/MidiLogger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 41f237c64f02a2241a30c5c0b5c087e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/Scripts/PdConnection/MidiParser.cs b/UnityProject/Assets/Scripts/PdConnection/MidiParser.cs index 849a98a..eba3f2d 100644 --- a/UnityProject/Assets/Scripts/PdConnection/MidiParser.cs +++ b/UnityProject/Assets/Scripts/PdConnection/MidiParser.cs @@ -12,6 +12,14 @@ namespace cylvester public byte Status; public byte Data1; public byte Data2; + + public override string ToString() + { + var statusStr = Status.ToString(); + var data1Str = Data1.ToString(); + var data2Str = Data2.ToString(); + return statusStr + " " +data1Str + " " +data2Str; + } } public interface IMidiParser : IDisposable {