This commit is contained in:
Chikashi Miyama 2019-09-28 20:17:39 +02:00
parent 2015f97849
commit 78023946cd
30 changed files with 320 additions and 67 deletions

4
.gitattributes vendored
View file

@ -1,7 +1,6 @@
############################################################################### ###############################################################################
# Set default behavior to automatically normalize line endings. # Set default behavior to automatically normalize line endings.
* text=auto * text=auto
# Set default behavior for command prompt diff. # Set default behavior for command prompt diff.
# #
# This is need for earlier builds of msysgit that does not have it on by # This is need for earlier builds of msysgit that does not have it on by
@ -47,4 +46,7 @@
#*.PDF diff=astextplain #*.PDF diff=astextplain
#*.rtf diff=astextplain #*.rtf diff=astextplain
#*.RTF diff=astextplain #*.RTF diff=astextplain
*.wav filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.aiff filter=lfs diff=lfs merge=lfs -text
. text !filter !merge !diff . text !filter !merge !diff

View file

@ -58,8 +58,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Assets\Editor\AppBuilder.cs" /> <Compile Include="Assets\Editor\AppBuilder.cs" />
<Compile Include="Assets\Editor\PdBackendEditor.cs" /> <Compile Include="Assets\Editor\EditorToggle.cs" />
<Compile Include="Assets\Editor\PreviewExampleInspector.cs" /> <Compile Include="Assets\Editor\PdBindEditor.cs" />
<Compile Include="Assets\Editor\PdConsole.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\ComponentFactoryTestCase.cs" />
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\KinectSensorTestCase.cs" /> <Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\KinectSensorTestCase.cs" />
<Compile Include="Assets\ThridParty\Editor\KinectCopyPluginDataHelper.cs" /> <Compile Include="Assets\ThridParty\Editor\KinectCopyPluginDataHelper.cs" />

View file

@ -57,11 +57,13 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Assets\PdBackend\PdBackend.cs" />
<Compile Include="Assets\PdBackend\PreviewExample.cs" />
<Compile Include="Assets\Scenes\Examples\Example1\script\BallMapping.cs" /> <Compile Include="Assets\Scenes\Examples\Example1\script\BallMapping.cs" />
<Compile Include="Assets\Scenes\Examples\Example1\script\RmsAnalyzer.cs" /> <Compile Include="Assets\Scenes\Examples\Example1\script\RmsAnalyzer.cs" />
<Compile Include="Assets\Scripts\DataModel\Parameter.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdArray.cs" /> <Compile Include="Assets\Scripts\PdConnection\PdArray.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdBackend.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdBind.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdProcess.cs" />
<Compile Include="Assets\Scripts\Versioning\VersionToggleBehaviour.cs" /> <Compile Include="Assets\Scripts\Versioning\VersionToggleBehaviour.cs" />
<Compile Include="Assets\Scripts\VideoInput\ComponentFactory.cs" /> <Compile Include="Assets\Scripts\VideoInput\ComponentFactory.cs" />
<Compile Include="Assets\Scripts\VideoInput\InfraredCamera.cs" /> <Compile Include="Assets\Scripts\VideoInput\InfraredCamera.cs" />

View file

@ -0,0 +1,30 @@
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

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

View file

@ -2,12 +2,11 @@
using UnityEditor; using UnityEditor;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
namespace cylvester namespace cylvester
{ {
[CustomEditor(typeof(PdBackend))] [CustomEditor(typeof(PdBind))]
class PdBackendEditor : Editor class PdBindEditor : UnityEditor.Editor
{ {
private int selectedSpectrum_; private int selectedSpectrum_;

View file

@ -0,0 +1,36 @@
using UnityEditor;
using UnityEngine;
namespace cylvester
{
public class PdConsole : EditorWindow
{
private IEditorToggle dspToggle_;
private ITogglePresenter togglePresenter_;
private IPdBackend pdBackend_;
[MenuItem("SoundVision/Pd console %#p")]
static void Init()
{
var window = (PdConsole)GetWindow(typeof(PdConsole));
window.Show();
}
private void OnEnable()
{
object[] foundObjects = FindObjectsOfType(typeof(PdBackend));
dspToggle_ = new EditorToggle();
togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_);
}
void OnGUI ()
{
foundObjects.
dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State);
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 1f64c3bbc6cc3ba419c8c56c02e08ec2 guid: 48196f9158f8594488b69520ab352d53
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View file

@ -1,13 +0,0 @@
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PreviewExample))]
public class PreviewExampleInspector : Editor {
public override bool HasPreviewGUI() { return true; }
public override GUIContent GetPreviewTitle() { return new GUIContent("name"); }
public override void OnPreviewGUI(Rect r, GUIStyle background) {
GUI.Box(new Rect(10, 10, 100, 100), "Preview");
}
}

View file

@ -0,0 +1,36 @@
using System;
namespace cylvester
{
public interface ITogglePresenter
{
}
public class TogglePresenter : ITogglePresenter, IDisposable
{
private readonly IEditorToggle editorToggle_;
private IPdBackend pdBackend_;
private readonly Action onToggleChanged_;
public TogglePresenter(IEditorToggle toggle, IPdBackend pdBackend)
{
editorToggle_ = toggle;
pdBackend_ = pdBackend;
onToggleChanged_ = () =>
{
var state = editorToggle_.State;
// apply state to pd backend;
};
editorToggle_.ToggleStateChanged += onToggleChanged_;
}
public void Dispose()
{
editorToggle_.ToggleStateChanged -= onToggleChanged_;
}
}
}

View file

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

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a29e3d7fadb042e09992f4e2df21181d
timeCreated: 1569682888

View file

@ -0,0 +1,35 @@
using NUnit.Framework;
namespace cylvester
{
public class UnitTest_ParameterResponder
{
[Test]
public void Set_Get()
{
var responder = new Parameter<float>(1.0f);
responder.Value = 3.2f;
Assert.AreEqual(3.2f, responder.Value);
}
[Test]
public void ValueChanged()
{
var responder = new Parameter<float>(1.0f);
responder.Value = 0f;
void OnValueChanged()
{
Assert.AreEqual(3.2f, responder.Value);
}
responder.ValueChanged += OnValueChanged;
responder.Value = 3.2f;
responder.ValueChanged -= OnValueChanged;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7bb461211f174fdc956fa904e780aa12
timeCreated: 1569682903

View file

@ -1,35 +0,0 @@
using System.Diagnostics;
using UnityEngine;
namespace cylvester
{
public class PdBackend : MonoBehaviour
{
[SerializeField] string mainPatch;
[SerializeField] int inchannels = 2;
private Process pdProcess_;
void Start()
{
pdProcess_ = new Process();
pdProcess_.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pdProcess_.StartInfo.UseShellExecute = true;
pdProcess_.StartInfo.FileName = Application.streamingAssetsPath + "/pd/win/pd.com";
var path = Application.streamingAssetsPath + "/pd/patch/" + mainPatch;
pdProcess_.StartInfo.Arguments = "-nogui -rt -inchannels " + inchannels + " " + path;
pdProcess_.Start();
}
private void OnDestroy()
{
pdProcess_.Kill();
}
}
}

View file

@ -1,5 +0,0 @@
using UnityEngine;
public class PreviewExample : MonoBehaviour
{
}

View file

@ -225,6 +225,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
mainPatch: test.pd mainPatch: test.pd
inchannels: 2 inchannels: 2
pdProcess: 0
--- !u!4 &987772534 --- !u!4 &987772534
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a845f6e8a2e4efd49b60d8ba5967e05b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,37 @@
using System;
namespace cylvester
{
interface IParameter<T> where T : IComparable<T>
{
T Value { set; get; }
event Action ValueChanged;
}
public class Parameter<T> : IParameter<T> where T : IComparable<T>
{
public Parameter(T initial)
{
Value = initial;
}
private T value_;
public T Value
{
get => value_;
set
{
if (value.CompareTo(value_) == 0)
return;
value_ = value;
ValueChanged.Invoke();
}
}
public event Action ValueChanged = () => { };
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 006fa2bbb30564c4da3895276ec8a526 guid: aeda2217423376843a1f77eedf34b248
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View file

@ -1,7 +1,7 @@
using System; using System;
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
namespace PdConnection namespace cylvester
{ {
public class PdArray : IDisposable public class PdArray : IDisposable
{ {

View file

@ -0,0 +1,34 @@
using System;
using UnityEngine;
namespace cylvester
{
public interface IPdBackend
{
bool State { set; }
}
[ExecuteInEditMode]
public class PdBackend : MonoBehaviour, IPdBackend
{
[SerializeField] string mainPatch;
[SerializeField] int inchannels = 2;
private Action onToggled_;
private void OnEnable()
{
PdProcess.Instance.Start(mainPatch, inchannels);
}
private void OnDisable()
{
PdProcess.Instance.Stop();
}
public bool State
{
set => enabled = value;
}
}
}

View file

@ -0,0 +1,12 @@
using UnityEngine;
namespace cylvester
{
public class PdBind : MonoBehaviour
{
private void Start()
{
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 54ab37d032df403e881d6a7a78141815
timeCreated: 1569681770

View file

@ -0,0 +1,51 @@
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace cylvester
{
interface IPdProcess
{
void Start(string mainPatch, int numInputChannels);
void Stop();
}
public class PdProcess : IPdProcess
{
private static PdProcess instance_ = null;
private Process pdProcess_;
private PdProcess() // cannot be instantiate normally
{
}
public static PdProcess Instance
{
get { return instance_ ?? (instance_ = new PdProcess()); }
}
public void Start(string mainPatch, int numInputChannels)
{
if (pdProcess_ != null)
return;
pdProcess_ = new Process();
pdProcess_.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pdProcess_.StartInfo.UseShellExecute = true;
pdProcess_.StartInfo.FileName = Application.streamingAssetsPath + "/pd/win/pd.com";
var path = Application.streamingAssetsPath + "/pd/patch/" + mainPatch;
pdProcess_.StartInfo.Arguments = "-nogui -rt -inchannels " + numInputChannels + " " + path;
pdProcess_.Start();
Debug.Log("Pd Process started");
}
public void Stop()
{
pdProcess_?.Kill();
pdProcess_ = null;
Debug.Log("Pd Process stopped");
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c7e3c06f21c04ec68ed9e1551c072f08
timeCreated: 1569686346

View file

@ -1,6 +1,6 @@
using UnityEngine; using UnityEngine;
namespace Visualizer namespace cylvester
{ {
public class WaveformVisualizerBehaviour : MonoBehaviour public class WaveformVisualizerBehaviour : MonoBehaviour
{ {
@ -11,11 +11,11 @@ namespace Visualizer
[SerializeField, Range(0f, 10f)] private float scale = 1f; [SerializeField, Range(0f, 10f)] private float scale = 1f;
#pragma warning restore 649 #pragma warning restore 649
private PdConnection.PdArray pdArray_; private PdArray pdArray_;
void Start() void Start()
{ {
pdArray_ = new PdConnection.PdArray(pdArrayName, pdArraySize); pdArray_ = new PdArray(pdArrayName, pdArraySize);
} }
void Update() void Update()

View file

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=cylvester/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>