This commit is contained in:
Chikashi Miyama 2019-10-30 18:45:05 +01:00
parent b6bee77635
commit 8fae5f3707
9 changed files with 204 additions and 34 deletions

View file

@ -62,6 +62,7 @@
<Compile Include="Assets\Scenes\Examples\LevelThreshold\script\Spawner.cs" /> <Compile Include="Assets\Scenes\Examples\LevelThreshold\script\Spawner.cs" />
<Compile Include="Assets\Scenes\Examples\MIDI\script\CubeSync.cs" /> <Compile Include="Assets\Scenes\Examples\MIDI\script\CubeSync.cs" />
<Compile Include="Assets\Scenes\Examples\MIDI\script\MidiSyncCounter.cs" /> <Compile Include="Assets\Scenes\Examples\MIDI\script\MidiSyncCounter.cs" />
<Compile Include="Assets\Scenes\Examples\MIDI\script\Mover.cs" />
<Compile Include="Assets\Scenes\Examples\MIDI\script\PositionBind.cs" /> <Compile Include="Assets\Scenes\Examples\MIDI\script\PositionBind.cs" />
<Compile Include="Assets\Scenes\Examples\MIDI\script\RandomPosition.cs" /> <Compile Include="Assets\Scenes\Examples\MIDI\script\RandomPosition.cs" />
<Compile Include="Assets\Scenes\Examples\PdBackend\script\BoomBall.cs" /> <Compile Include="Assets\Scenes\Examples\PdBackend\script\BoomBall.cs" />
@ -77,6 +78,7 @@
<Compile Include="Assets\Scripts\PdConnection\ISpectrumGenerator.cs" /> <Compile Include="Assets\Scripts\PdConnection\ISpectrumGenerator.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\MidiSequencer.cs" />
<Compile Include="Assets\Scripts\PdConnection\MidiSyncedLoop.cs" /> <Compile Include="Assets\Scripts\PdConnection\MidiSyncedLoop.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" />
@ -91,7 +93,6 @@
<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" />

View file

@ -25,9 +25,11 @@ namespace cylvester
"TimbreID_Test" "TimbreID_Test"
}; };
private void Awake() private void OnEnable()
{ {
pdBackend_ = (PdBackend) target; pdBackend_ = (PdBackend) target;
midiMessageReceivedProperty_ = serializedObject.FindProperty("midiMessageReceived");
midiSyncReceivedProperty_ = serializedObject.FindProperty("midiSyncReceived");
} }
public override void OnInspectorGUI () public override void OnInspectorGUI ()
@ -35,10 +37,7 @@ namespace cylvester
serializedObject.Update(); serializedObject.Update();
pdBackend_ = (PdBackend) target; pdBackend_ = (PdBackend) target;
midiMessageReceivedProperty_ = serializedObject.FindProperty("midiMessageReceived");
EditorGUILayout.PropertyField(midiMessageReceivedProperty_); EditorGUILayout.PropertyField(midiMessageReceivedProperty_);
midiSyncReceivedProperty_ = serializedObject.FindProperty("midiSyncReceived");
EditorGUILayout.PropertyField(midiSyncReceivedProperty_); EditorGUILayout.PropertyField(midiSyncReceivedProperty_);
if (Application.isPlaying) if (Application.isPlaying)

View file

@ -3,30 +3,40 @@ using UnityEngine;
namespace cylvester namespace cylvester
{ {
[CustomEditor(typeof(Sequencer))] [CustomEditor(typeof(MidiSequencer))]
public class SequencerEditor : Editor public class MidiSequencerEditor : Editor
{ {
private SerializedProperty timeProperty_;
private SerializedProperty sequenceProperty_; private SerializedProperty sequenceProperty_;
private SerializedProperty callbackProperty_;
private readonly string[] options_ = new string[] {"3", "4", "5", "6"};
private void OnEnable() private void OnEnable()
{ {
timeProperty_ = serializedObject.FindProperty("time");
sequenceProperty_ = serializedObject.FindProperty("sequence"); sequenceProperty_ = serializedObject.FindProperty("sequence");
callbackProperty_ = serializedObject.FindProperty("triggered");
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
serializedObject.Update (); 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.BeginHorizontal();
EditorGUILayout.LabelField("Time:", GUILayout.Width(120));
timeProperty_.intValue = EditorGUILayout.Popup(timeProperty_.intValue - 3, options_) + 3;
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Trigger on:", GUILayout.Width(120));
for (var i = 0; i < 4 * timeProperty_.intValue; ++i)
{
sequenceProperty_.GetArrayElementAtIndex(i).boolValue
= EditorGUILayout.Toggle(sequenceProperty_.GetArrayElementAtIndex(i).boolValue, GUILayout.Width(10));
}
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(callbackProperty_);
serializedObject.ApplyModifiedProperties (); serializedObject.ApplyModifiedProperties ();
} }
} }

View file

@ -212,6 +212,97 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &517164549
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 517164553}
- component: {fileID: 517164552}
- component: {fileID: 517164551}
- component: {fileID: 517164550}
m_Layer: 0
m_Name: Tick
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &517164550
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 517164549}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eea570f89628f784989f4de365dff56d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!23 &517164551
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 517164549}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: f044463ea66a19c47aef13261142b54e, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &517164552
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 517164549}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &517164553
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 517164549}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.2028971, y: -0.6283364, z: 0.5670376}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &560516510 --- !u!1 &560516510
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -562,6 +653,17 @@ MonoBehaviour:
m_StringArgument: m_StringArgument:
m_BoolArgument: 0 m_BoolArgument: 0
m_CallState: 2 m_CallState: 2
- m_Target: {fileID: 1261823484}
m_MethodName: OnSyncReceived
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
samplePlayback: 0 samplePlayback: 0
--- !u!4 &1261823481 --- !u!4 &1261823481
Transform: Transform:
@ -617,7 +719,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6ebe1124d37e04742be155475d179a67, type: 3} m_Script: {fileID: 11500000, guid: 6ebe1124d37e04742be155475d179a67, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
sequence: 00000000000000000000000000000000 sequence: 010001000100000001010100010001000000000000000000
time: 4
triggered:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 517164550}
m_MethodName: Move
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
--- !u!114 &1261823485 --- !u!114 &1261823485
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -0,0 +1,15 @@
using UnityEngine;
namespace cylvester
{
public class Mover : MonoBehaviour
{
public void Move(int pos)
{
transform.position = new Vector3(pos - 8.0f, 0f, 0f);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eea570f89628f784989f4de365dff56d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,33 @@
using System;
using UnityEngine;
using UnityEngine.Events;
namespace cylvester
{
[Serializable]
class UnitySequenceEvent : UnityEvent<int>
{ }
public class MidiSequencer : MonoBehaviour
{
[SerializeField] private bool[] sequence = new bool[24]; // max 6 beat
[SerializeField] private int time = 4;
[SerializeField] private UnitySequenceEvent triggered;
private void OnValidate()
{
if(sequence.Length != 24)
Array.Resize(ref sequence, 24);
}
public void OnSyncReceived(MidiSync midiSync, int count)
{
if (count % 6 != 0) // 24 ppqn (pulse per quater note). %6 means every 16th note because 24/4
return;
var index = count /6 % (time * 4);
if (sequence[index])
triggered.Invoke(index);
}
}
}

View file

@ -1,16 +0,0 @@
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);
}
}
}