Pd backend levelmeters

This commit is contained in:
Chikashi Miyama 2019-09-29 18:04:26 +02:00
parent b13ed2cb97
commit a04dbcc5d5
23 changed files with 852 additions and 726 deletions

View file

@ -9,12 +9,14 @@
<e p="Assets" t="Include">
<e p="Editor" t="Include">
<e p="AppBuilder.cs" t="Include" />
<e p="LevelMeter.cs" t="Include" />
<e p="PdBackendEditor.cs" t="Include" />
<e p="PreviewExampleInspector.cs" t="Include" />
</e>
<e p="PdBackend" t="Include">
<e p="PdBackend.cs" t="Include" />
<e p="PreviewExample.cs" t="Include" />
<e p="PdSpectrumBindEditor.cs" t="Include" />
<e p="RectangularSelection.cs" t="Include" />
<e p="SpectrumGenerator.cs" t="Include" />
<e p="UnitTest" t="Include">
<e p="UnitTest_ParameterResponder.cs" t="Include" />
</e>
</e>
<e p="Resources" t="Include">
<e p="buildNumber.txt" t="Include" />
@ -30,8 +32,15 @@
</e>
</e>
<e p="Scripts" t="Include">
<e p="DataModel" t="Include">
<e p="Parameter.cs" t="Include" />
</e>
<e p="PdConnection" t="Include">
<e p="PdArray.cs" t="Include" />
<e p="PdBackend.cs" t="Include" />
<e p="PdProcess.cs" t="Include" />
<e p="PdSpectrumBind.cs" t="Include" />
<e p="UdpSender.cs" t="Include" />
</e>
<e p="Versioning" t="Include">
<e p="VersionToggleBehaviour.cs" t="Include" />

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_4_OR_NEWER;UNITY_2018_4_3;UNITY_2018_4;UNITY_2018;PLATFORM_ARCH_64;UNITY_64;UNITY_INCLUDE_TESTS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_TEXTURE_STREAMING;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_VIDEO;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_EVENT_QUEUE;ENABLE_CLUSTER_SYNC;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_4_6;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_4_OR_NEWER;UNITY_2018_4_3;UNITY_2018_4;UNITY_2018;PLATFORM_ARCH_64;UNITY_64;UNITY_INCLUDE_TESTS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_TEXTURE_STREAMING;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_VIDEO;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_EVENT_QUEUE;ENABLE_CLUSTER_SYNC;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_4_6;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;EXTOSC;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
@ -58,13 +58,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Editor\AppBuilder.cs" />
<Compile Include="Assets\Editor\EditorToggle.cs" />
<Compile Include="Assets\Editor\LevelMeter.cs" />
<Compile Include="Assets\Editor\PdConsole.cs" />
<Compile Include="Assets\Editor\PdBackendEditor.cs" />
<Compile Include="Assets\Editor\PdSpectrumBindEditor.cs" />
<Compile Include="Assets\Editor\RectangularSelection.cs" />
<Compile Include="Assets\Editor\SpectrumGenerator.cs" />
<Compile Include="Assets\Editor\TogglePresenter.cs" />
<Compile Include="Assets\Editor\UnitTest\UnitTest_ParameterResponder.cs" />
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\ComponentFactoryTestCase.cs" />
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\KinectSensorTestCase.cs" />

View file

@ -26,7 +26,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_4_OR_NEWER;UNITY_2018_4_3;UNITY_2018_4;UNITY_2018;PLATFORM_ARCH_64;UNITY_64;UNITY_INCLUDE_TESTS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_TEXTURE_STREAMING;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_VIDEO;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_EVENT_QUEUE;ENABLE_CLUSTER_SYNC;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_STANDARD_2_0;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_4_OR_NEWER;UNITY_2018_4_3;UNITY_2018_4;UNITY_2018;PLATFORM_ARCH_64;UNITY_64;UNITY_INCLUDE_TESTS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_TEXTURE_STREAMING;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_VIDEO;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_EVENT_QUEUE;ENABLE_CLUSTER_SYNC;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_STANDARD_2_0;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;EXTOSC;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
@ -64,6 +64,7 @@
<Compile Include="Assets\Scripts\PdConnection\PdBackend.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdProcess.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdSpectrumBind.cs" />
<Compile Include="Assets\Scripts\PdConnection\UdpSender.cs" />
<Compile Include="Assets\Scripts\Versioning\VersionToggleBehaviour.cs" />
<Compile Include="Assets\Scripts\VideoInput\ComponentFactory.cs" />
<Compile Include="Assets\Scripts\VideoInput\InfraredCamera.cs" />

View file

@ -1,30 +0,0 @@
using System;
namespace cylvester
{
public interface IEditorToggle
{
event Action ToggleStateChanged;
bool State { get; set; }
}
public class EditorToggle : IEditorToggle
{
private bool state_;
public event Action ToggleStateChanged = () => { };
public bool State
{
get => state_;
set
{
if (state_ != value)
{
state_ = value;
ToggleStateChanged.Invoke();
}
}
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6c627fe9ba84425a92fe457030f5f874
timeCreated: 1569673031

View file

@ -3,7 +3,12 @@ using UnityEditor;
namespace cylvester
{
public class LevelMeter
interface ILevelMeter
{
void Render();
}
public class LevelMeter : ILevelMeter
{
private const int TextureWidth = 1;
private const int TextureHeight = 100;

View file

@ -0,0 +1,56 @@
using System;
using UnityEditor;
using UnityEngine;
namespace cylvester
{
[CustomEditor(typeof(PdBackend))]
public class PdBackendEditor : Editor
{
private IPdBackend pdBackend_;
private ILevelMeter[] levelMeters_;
private readonly string[] channels = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"
};
private void Awake()
{
pdBackend_ = (IPdBackend) target;
levelMeters_ = new ILevelMeter[16];
for (var i = 0; i < 16; ++i)
levelMeters_[i] = new LevelMeter(i, pdBackend_.LevelMeterArray);
}
public override void OnInspectorGUI ()
{
pdBackend_ = (IPdBackend) target;
GUILayout.Space(5);
GUILayout.BeginHorizontal();
GUILayout.Label("Main Patch");
pdBackend_.MainPatch = GUILayout.TextField(pdBackend_.MainPatch, 30);
GUILayout.EndHorizontal();
pdBackend_.NumInputChannels = EditorGUILayout.Popup("Number of input channels", pdBackend_.NumInputChannels, channels);
pdBackend_.State = GUILayout.Toggle(pdBackend_.State, "DSP Processing");
if (!pdBackend_.State)
return;
pdBackend_.UpdateShmem();
GUILayout.Space(5);
GUILayout.BeginHorizontal();
foreach (var levelMeter in levelMeters_)
levelMeter.Render();
GUILayout.EndHorizontal();
Repaint();
}
}
}

View file

@ -1,99 +0,0 @@
using System;
using UnityEditor;
namespace cylvester
{
public class PdConsole : EditorWindow
{
private const int NumChannels = 16;
private IEditorToggle dspToggle_;
private ITogglePresenter togglePresenter_;
private Action onDspToggleStateChanged_;
private IPdBackend pdBackend_;
private LevelMeter[] levelMeters_;
private PdArray levelMeterArray_;
[MenuItem("SoundVision/Pd console %#p")]
static void Init()
{
var window = (PdConsole)GetWindow(typeof(PdConsole));
window.Show();
}
private void Awake()
{
var foundObjects = FindObjectsOfType(typeof(PdBackend));
if (foundObjects.Length != 1)
return;
pdBackend_ = (IPdBackend) foundObjects[0];
dspToggle_ = new EditorToggle();
onDspToggleStateChanged_ = () =>
{
if (pdBackend_.State)
{
levelMeterArray_ = new PdArray("levelmeters", NumChannels);
for (var i = 0; i < NumChannels; ++i)
levelMeters_[i] = new LevelMeter(i, levelMeterArray_);
}
else
levelMeterArray_.Dispose();
};
pdBackend_.StateChanged += onDspToggleStateChanged_;
togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_);
levelMeters_ = new LevelMeter[NumChannels];
}
private void OnDestroy()
{
levelMeterArray_?.Dispose();
dspToggle_.ToggleStateChanged -= onDspToggleStateChanged_;
}
private void OnGUI ()
{
if(!ValidatePdBackend())
return;
EditorGUILayout.Space();
dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State);
if(!CheckProcessingState())
return;
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
levelMeterArray_.Update();
foreach (var levelMeter in levelMeters_)
levelMeter.Render();
EditorGUILayout.EndHorizontal();
Repaint();
}
private bool ValidatePdBackend()
{
if (pdBackend_ != null)
return true;
EditorGUILayout.LabelField("No Pd backend found in the scene");
return false;
}
private bool CheckProcessingState()
{
if (pdBackend_.State)
return true;
EditorGUILayout.LabelField("Pd process is currently inactive");
return false;
}
}
}

View file

@ -11,7 +11,6 @@ namespace cylvester
private readonly string[] channels = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"
};
private int selectedSpectrum_;
private ISpectrumGenerator spectrumGenerator_;
private IRectangularSelection rectangularSelection_;
private Rect paintSpace_;
@ -26,7 +25,6 @@ namespace cylvester
{
var behaviour = (PdSpectrumBind)target;
if (Event.current.isMouse && Event.current.button == 0)
{
switch (Event.current.type)
@ -46,7 +44,7 @@ namespace cylvester
GUILayout.Label("PureData Inputs", EditorStyles.boldLabel);
selectedSpectrum_ = EditorGUILayout.Popup("Input Channel", selectedSpectrum_, channels);
behaviour.channel = EditorGUILayout.Popup("Input Channel", behaviour.channel, channels);
GUILayout.Space(5);
GUILayout.Label("Spectrum Extractor", EditorStyles.boldLabel);
@ -54,7 +52,8 @@ namespace cylvester
if (Event.current.type == EventType.Repaint)
{
paintSpace_ = paintSpace;
spectrumGenerator_.Update(ref rectangularSelection_.Selection);
behaviour.PdArray.Update();
spectrumGenerator_.Update(behaviour.PdArray.Data, ref rectangularSelection_.Selection);
GUI.DrawTexture(paintSpace_, spectrumGenerator_.Spectrum);
}

View file

@ -5,7 +5,7 @@ namespace cylvester
interface ISpectrumGenerator
{
Texture2D Spectrum { get; }
void Update(ref Rect selectionRect);
void Update(float[] fftData, ref Rect selectionRect);
}
public class SpectrumGenerator : ISpectrumGenerator
@ -20,20 +20,24 @@ namespace cylvester
height_ = height;
}
public void Update(ref Rect selectionRect)
public void Update(float[] fftData, ref Rect selectionRect)
{
for (var y = 0; y < texture_.height; y++)
for (var x = 0; x < texture_.width; x++)
{
for (var x = 0; x < texture_.width; x++)
var magnitude = fftData[x];
for (var y = 0; y < texture_.height; y++)
{
var alpha = 0.4f;
if ((selectionRect.x < x && x < (selectionRect.x + selectionRect.width)) &&
(selectionRect.y < y && y < (selectionRect.y + selectionRect.height)))
{
alpha = 1f;
}
var color = new Color(Random.value, Random.value, Random.value, alpha);
texture_.SetPixel(x, height_-y, color);
var color = y > magnitude ? Color.white : Color.gray;
color.a = alpha;
texture_.SetPixel(x, height_, color);
}
}
texture_.Apply();

View file

@ -1,33 +0,0 @@
using System;
namespace cylvester
{
public interface ITogglePresenter
{
}
public class TogglePresenter : ITogglePresenter, IDisposable
{
private readonly IEditorToggle editorToggle_;
private readonly Action onToggleChanged_;
public TogglePresenter(IEditorToggle toggle, IPdBackend pdBackend)
{
editorToggle_ = toggle;
onToggleChanged_ = () =>
{
pdBackend.State = editorToggle_.State;
};
editorToggle_.ToggleStateChanged += onToggleChanged_;
}
public void Dispose()
{
editorToggle_.ToggleStateChanged -= onToggleChanged_;
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a612dbdf74c948728e59ddede1c1f6d9
timeCreated: 1569673646

View file

@ -295,7 +295,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 987772532}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3ba69cee3466a304d9d570268f717413, type: 3}
m_Name:

View file

@ -6,40 +6,70 @@ namespace cylvester
{
public interface IPdBackend
{
bool State { set; get; }
event Action StateChanged;
string MainPatch { get; set; }
int NumInputChannels { get; set;}
bool State { get; set; }
void UpdateShmem();
IPdArray LevelMeterArray { get; }
}
[ExecuteInEditMode]
public class PdBackend : MonoBehaviour, IPdBackend
{
[SerializeField] string mainPatch = "";
[SerializeField] int inchannels = 2;
private Action onToggled_;
public string mainPatch = "analyzer.pd";
public int inchannels = 2;
private Action onToggled_;
private PdArray levelMeterArray_;
private UdpSender udpSender_;
private bool state_;
private const int NumMaxInputChannels = 16;
public IPdArray LevelMeterArray => levelMeterArray_;
public string MainPatch { get => mainPatch; set => mainPatch = value; }
public int NumInputChannels { get => inchannels -1; set => inchannels = value + 1; }
public bool State
{
get => state_;
set
{
if (state_ == value)
return;
var bytes = new byte[1];
bytes[0] = state_ ? (byte)0 : (byte)1;
udpSender_.SendBytes(bytes);
state_ = value;
}
}
private void OnEnable()
{
PdProcess.Instance.Start(mainPatch, inchannels);
Thread.Sleep(500);
levelMeterArray_ = new PdArray("levelmeters", NumMaxInputChannels);
udpSender_ = new UdpSender("127.0.0.1", 54637);
}
private void OnDisable()
{
PdProcess.Instance.Stop();
levelMeterArray_?.Dispose();
udpSender_?.Dispose();
}
public bool State
public void UpdateShmem()
{
set
{
enabled = value;
if(StateChanged != null)
StateChanged.Invoke();
}
get => enabled;
levelMeterArray_.Update();
}
public event Action StateChanged;
}
}

View file

@ -16,9 +16,10 @@ namespace cylvester
private static PdProcess instance_ = null;
private Process pdProcess_;
private PdProcess() // cannot be instantiate normally
private PdProcess()
{
}
} // cannot be instantiate normally
public static PdProcess Instance => instance_ ?? (instance_ = new PdProcess());
@ -40,7 +41,6 @@ namespace cylvester
throw new Exception("Pd process failed to start");
}
Debug.Log("Pd Process started");
}
public void Stop()
@ -49,6 +49,5 @@ namespace cylvester
pdProcess_ = null;
Debug.Log("Pd Process stopped");
}
}
}

View file

@ -4,28 +4,30 @@ namespace cylvester
{
public interface IPdSpectrumBind
{
IPdArray PdArray { get; }
float TrimmedEnergy { get; }
}
[ExecuteInEditMode]
public class PdSpectrumBind : MonoBehaviour, IPdSpectrumBind
{
public int channel;
public int startBin;
public int endBin;
[SerializeField] private float topClip;
[SerializeField] private float bottomClip;
[SerializeField] private float trimmedEnergy = 0f;
public float topClip;
public float bottomClip;
public float trimmedEnergy = 0f;
public float TrimmedEnergy => trimmedEnergy;
private void Start()
private PdArray pdArray_;
public IPdArray PdArray => pdArray_;
private void Awake()
{
pdArray_ = new PdArray("fft_" + channel, 512);
}
private void Update()
{
}
}
}

View file

@ -0,0 +1,34 @@
using System;
namespace cylvester
{
interface IUdpSender : IDisposable
{
void SendBytes(byte[] data);
}
public class UdpSender : IDisposable
{
private readonly string remoteHost_;
private readonly int remotePort_;
private System.Net.Sockets.UdpClient udpClient_;
public UdpSender(string remoteHost, int remotePort)
{
remoteHost_ = remoteHost;
remotePort_ = remotePort;
udpClient_ = new System.Net.Sockets.UdpClient();
}
public void SendBytes(byte[] data)
{
udpClient_.Send(data, data.Length, remoteHost_, remotePort_);
}
public void Dispose()
{
udpClient_.Close();
udpClient_ = null;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1f65f75415684cef9649e0eaa0fcbfc7
timeCreated: 1569772195

View file

@ -1,5 +1,4 @@
#N canvas 550 301 727 406 10;
#X msg 307 54 \; pd dsp 1;
#N canvas 1334 361 827 452 10;
#X obj 187 61 loadbang;
#X obj 80 273 adc~ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16;
#N canvas 0 50 450 250 (subpatch) 0;
@ -72,7 +71,7 @@
#X obj 45 42 r shmemupdate;
#X obj 42 105 table levelmeters 16;
#X connect 1 0 0 0;
#X restore 608 25 pd shmems;
#X restore 654 34 pd shmems;
#N canvas 763 290 686 441 window 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array hann 1024 float 1;
@ -211,32 +210,39 @@
0.000244498 0.000150442 9.39965e-005 3.75807e-005 1.87755e-005;
#X coords 0 1 1023 0 300 100 1 0 0;
#X restore 39 32 graph;
#X restore 611 47 pd window;
#X connect 1 0 0 0;
#X connect 1 0 5 0;
#X restore 657 56 pd window;
#X msg 478 110 \; pd dsp \$1;
#X msg 274 17 test;
#X obj 479 83 netreceive -u -b 54637;
#N canvas 927 320 450 300 udpmessage 0;
#X text 60 33 0 ... dsp;
#X restore 660 100 pd udpmessage;
#X connect 0 0 4 0;
#X connect 0 0 7 0;
#X connect 0 0 16 0;
#X connect 1 0 8 0;
#X connect 2 0 9 0;
#X connect 2 1 9 1;
#X connect 2 2 9 2;
#X connect 2 3 9 3;
#X connect 2 4 9 4;
#X connect 2 5 9 5;
#X connect 2 6 9 6;
#X connect 2 7 9 7;
#X connect 2 8 9 8;
#X connect 2 9 9 9;
#X connect 2 10 9 10;
#X connect 2 11 9 11;
#X connect 2 12 9 12;
#X connect 2 13 9 13;
#X connect 2 14 9 14;
#X connect 2 15 9 15;
#X connect 5 0 4 0;
#X connect 7 0 6 1;
#X connect 1 1 8 1;
#X connect 1 2 8 2;
#X connect 1 3 8 3;
#X connect 1 4 8 4;
#X connect 1 5 8 5;
#X connect 1 6 8 6;
#X connect 1 7 8 7;
#X connect 1 8 8 8;
#X connect 1 9 8 9;
#X connect 1 10 8 10;
#X connect 1 11 8 11;
#X connect 1 12 8 12;
#X connect 1 13 8 13;
#X connect 1 14 8 14;
#X connect 1 15 8 15;
#X connect 4 0 3 0;
#X connect 6 0 5 1;
#X connect 6 0 5 0;
#X connect 6 0 8 0;
#X connect 6 1 7 0;
#X connect 7 0 6 0;
#X connect 7 0 9 0;
#X connect 7 1 8 0;
#X connect 8 0 7 0;
#X connect 9 0 10 0;
#X connect 10 0 11 0;
#X connect 11 0 12 0;
#X connect 12 0 13 0;
#X connect 17 0 15 0;

View file

@ -6,8 +6,11 @@
#X obj 57 239 tabwrite levelmeters;
#X obj 85 135 spectrum \$1;
#X obj 229 240 table fft_\$1 512;
#X obj 228 190 r shmemupdate;
#X obj 228 216 shmem fft_\$1 512;
#X connect 0 0 4 0;
#X connect 1 0 0 0;
#X connect 1 0 5 0;
#X connect 2 0 3 0;
#X connect 3 0 4 1;
#X connect 7 0 8 0;

View file

@ -527,7 +527,16 @@ PlayerSettings:
webGLCompressionFormat: 1
webGLLinkerTarget: 1
webGLThreadsSupport: 0
scriptingDefineSymbols: {}
scriptingDefineSymbols:
1: EXTOSC
7: EXTOSC
13: EXTOSC
19: EXTOSC
21: EXTOSC
25: EXTOSC
26: EXTOSC
27: EXTOSC
28: EXTOSC
platformArchitecture: {}
scriptingBackend:
Standalone: 0