Merge branch 'samplefileplayer'

This commit is contained in:
Chikashi Miyama 2019-10-01 15:16:38 +02:00
commit cee612af5b
37 changed files with 298 additions and 171 deletions

3
.gitignore vendored
View file

@ -5,3 +5,6 @@ UnityProject/.idea
bin bin
setup/setup/obj setup/setup/obj
UnityProject/.idea UnityProject/.idea
UnityProject/.idea
UnityProject/.vs
UnityProject/.idea

View file

@ -63,7 +63,7 @@
<Compile Include="Assets\Editor\PdSpectrumBindEditor.cs" /> <Compile Include="Assets\Editor\PdSpectrumBindEditor.cs" />
<Compile Include="Assets\Editor\RectangularSelection.cs" /> <Compile Include="Assets\Editor\RectangularSelection.cs" />
<Compile Include="Assets\Editor\SpectrumGenerator.cs" /> <Compile Include="Assets\Editor\SpectrumGenerator.cs" />
<Compile Include="Assets\Editor\UnitTest\UnitTest_ParameterResponder.cs" /> <Compile Include="Assets\Editor\UnitTest\UnitTest_ChangeObserver.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

@ -59,13 +59,14 @@
<ItemGroup> <ItemGroup>
<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\FFTArrayContainer.cs" /> <Compile Include="Assets\Scripts\PdConnection\FFTArrayContainer.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\PdBackend.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdConstant.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdProcess.cs" /> <Compile Include="Assets\Scripts\PdConnection\PdProcess.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdSocket.cs" />
<Compile Include="Assets\Scripts\PdConnection\PdSpectrumBind.cs" /> <Compile Include="Assets\Scripts\PdConnection\PdSpectrumBind.cs" />
<Compile Include="Assets\Scripts\PdConnection\UdpSender.cs" /> <Compile Include="Assets\Scripts\TemplateLibrary\ChangeObserver.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

@ -6,15 +6,29 @@ namespace cylvester
[CustomEditor(typeof(PdBackend))] [CustomEditor(typeof(PdBackend))]
public class PdBackendEditor : Editor public class PdBackendEditor : Editor
{ {
private IPdBackend pdBackend_; private PdBackend pdBackend_;
private ILevelMeter[] levelMeters_; private ILevelMeter[] levelMeters_;
private readonly string[] channels = { private readonly string[] channels_ = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"
}; };
private readonly string[] samples_ =
{
"No Playback",
"Back_Back",
"Brutal_Synth",
"Dialog",
"Drums",
"Fox_Melo",
"Kick",
"Pads+Strings",
"Rose_Sax",
"Roses_Front"
};
private void Awake() private void Awake()
{ {
pdBackend_ = (IPdBackend) target; pdBackend_ = (PdBackend) target;
levelMeters_ = new ILevelMeter[16]; levelMeters_ = new ILevelMeter[16];
for (var i = 0; i < 16; ++i) for (var i = 0; i < 16; ++i)
levelMeters_[i] = new LevelMeter(i); levelMeters_[i] = new LevelMeter(i);
@ -22,27 +36,37 @@ namespace cylvester
public override void OnInspectorGUI () public override void OnInspectorGUI ()
{ {
pdBackend_ = (IPdBackend) target; pdBackend_ = (PdBackend) target;
GUILayout.Space(5); GUILayout.Space(5);
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label("Main Patch"); GUILayout.Label("Main Patch");
pdBackend_.MainPatch = GUILayout.TextField(pdBackend_.MainPatch, 30); pdBackend_.mainPatch = GUILayout.TextField(pdBackend_.mainPatch, 30);
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
pdBackend_.NumInputChannels = EditorGUILayout.Popup("Number of input channels", pdBackend_.NumInputChannels, channels); pdBackend_.inchannels = EditorGUILayout.Popup("Number of input channels", pdBackend_.inchannels, channels_);
if (Application.isPlaying) if (Application.isPlaying)
{ {
RenderSamplePlayback();
GUILayout.Space(5); RenderLevelMeters();
GUILayout.BeginHorizontal();
foreach (var levelMeter in levelMeters_)
levelMeter.Render(pdBackend_.LevelMeterArray);
GUILayout.EndHorizontal();
Repaint(); Repaint();
} }
} }
private void RenderSamplePlayback()
{
GUILayout.Space(5);
pdBackend_.samplePlayback = EditorGUILayout.Popup("Sample File to play", pdBackend_.samplePlayback, samples_);
}
private void RenderLevelMeters()
{
GUILayout.Space(5);
GUILayout.BeginHorizontal();
foreach (var levelMeter in levelMeters_)
levelMeter.Render(pdBackend_.levelMeterArray);
GUILayout.EndHorizontal();
}
} }
} }

View file

@ -0,0 +1,33 @@
using NUnit.Framework;
namespace cylvester
{
public class UnitTest_ChangeObserver
{
[Test]
public void Set_Get()
{
var called = false;
var observer = new ChangeObserver<float>(1.0f);
observer.ValueChanged += ()=> { called = true; };
observer.Value = 1.0001f;
Assert.IsTrue(called);
}
[Test]
public void ValueChanged()
{
var callCount = 0;
var observer = new ChangeObserver<float>(1.0f);
observer.ValueChanged += () => { callCount++; };
observer.Value = 1.0001f;
observer.Value = 1.0001f;
Assert.AreEqual(1, callCount);
}
}
}

View file

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

@ -3,52 +3,53 @@ using UnityEngine;
namespace cylvester namespace cylvester
{ {
public interface IPdBackend public class PdBackend : MonoBehaviour
{
string MainPatch { get; set; }
int NumInputChannels { get; set;}
IPdArray LevelMeterArray { get; }
IFftArrayContainer FFTArrayContainer { get; }
}
public class PdBackend : MonoBehaviour, IPdBackend
{ {
public string mainPatch = "analyzer.pd"; public string mainPatch = "analyzer.pd";
public int inchannels = 2; public int inchannels = 2;
public int samplePlayback = 0;
public PdArray levelMeterArray;
public FftArrayContainer fftArrayContainer;
private Action onToggled_; private IChangeObserver<int> samplePlaybackObserver_;
private PdArray levelMeterArray_; private Action onSamplePlaybackChanged_;
private FftArrayContainer fftArrayContainer_; private IPdSocket pdSocket_;
private const int NumMaxInputChannels = 16;
public IPdArray LevelMeterArray => levelMeterArray_;
public IFftArrayContainer FFTArrayContainer => fftArrayContainer_;
public string MainPatch { get => mainPatch; set => mainPatch = value; }
public int NumInputChannels { get => inchannels -1; set => inchannels = value + 1; }
private void Start() private void Start()
{ {
PdProcess.Instance.Start(mainPatch, inchannels); PdProcess.Instance.Start(mainPatch, inchannels);
levelMeterArray_ = new PdArray("levelmeters", NumMaxInputChannels); levelMeterArray = new PdArray("levelmeters", PdConstant.NumMaxInputChannels);
fftArrayContainer_ = new FftArrayContainer(); fftArrayContainer = new FftArrayContainer();
pdSocket_ = new PdSocket(PdConstant.ip, PdConstant.port);
samplePlaybackObserver_ = new ChangeObserver<int>(samplePlayback);
onSamplePlaybackChanged_ = () =>
{
var bytes = new byte[]{(byte)PdMessage.SampleSound, (byte)samplePlayback};
pdSocket_.Send(bytes);
};
samplePlaybackObserver_.ValueChanged += onSamplePlaybackChanged_;
} }
private void OnDestroy() private void OnDestroy()
{ {
PdProcess.Instance.Stop(); PdProcess.Instance.Stop();
levelMeterArray_?.Dispose(); levelMeterArray?.Dispose();
pdSocket_?.Dispose();
samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_;
} }
public void Update() public void Update()
{ {
if(PdProcess.Instance.Running) if(PdProcess.Instance.Running)
levelMeterArray_.Update(); levelMeterArray.Update();
fftArrayContainer_.Update(); fftArrayContainer.Update();
samplePlaybackObserver_.Value = samplePlayback;
} }
} }
} }

View file

@ -0,0 +1,17 @@
namespace cylvester
{
enum PdMessage
{
SampleSound = 0
}
public class PdConstant
{
public static readonly int NumMaxInputChannels = 16;
public static readonly string ip = "127.0.0.1";
public static readonly int port = 54345;
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 921619bf97b640dca91071f73784d3cb
timeCreated: 1569928306

View file

@ -0,0 +1,32 @@
using System;
using System.Net;
using System.Net.Sockets;
namespace cylvester
{
public interface IPdSocket : IDisposable
{
void Send(byte[] bytes);
}
public class PdSocket : IPdSocket
{
private Socket socket_;
public PdSocket(string ip, int port)
{
socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket_.Connect(IPAddress.Parse(ip), port);
}
public void Send(byte[] bytes)
{
socket_.Send(bytes);
}
public void Dispose()
{
socket_.Close();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0b3bd2ba944d458c84bbeb5fa97b9382
timeCreated: 1569927529

View file

@ -17,7 +17,7 @@ namespace cylvester
public IPdArray GetPdArray(int index) public IPdArray GetPdArray(int index)
{ {
return pdBackend.FFTArrayContainer[index]; return pdBackend.fftArrayContainer[index];
} }
public int Channel { get; set; } public int Channel { get; set; }

View file

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

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

View file

@ -2,25 +2,22 @@ using System;
namespace cylvester namespace cylvester
{ {
interface IParameter<T> where T : IComparable<T> interface IChangeObserver<T> where T : IComparable<T>
{ {
T Value { set; get; } T Value { set; }
event Action ValueChanged; event Action ValueChanged;
} }
public class Parameter<T> : IParameter<T> where T : IComparable<T> public class ChangeObserver<T> : IChangeObserver<T> where T : IComparable<T>
{ {
public Parameter(T initial) private T value_;
public ChangeObserver(T initial)
{ {
Value = initial; Value = initial;
} }
private T value_;
public T Value public T Value
{ {
get => value_;
set set
{ {
if (value.CompareTo(value_) == 0) if (value.CompareTo(value_) == 0)
@ -32,6 +29,5 @@ namespace cylvester
} }
public event Action ValueChanged = () => { }; public event Action ValueChanged = () => { };
} }
} }

View file

@ -1,16 +1,6 @@
#N canvas 1494 726 827 452 10; #N canvas 1494 726 560 380 10;
#X obj 351 23 loadbang; #X obj 217 251 adc~ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16;
#X obj 80 273 adc~ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; #X obj 48 304 dac~, f 6;
#N canvas 0 50 450 250 (subpatch) 0;
#X array loop 211681 float 2;
#X coords 0 1 211681 -1 200 140 1 0 0;
#X restore 446 219 graph;
#X obj 274 146 soundfiler;
#X msg 269 109 read -resize drumloop.wav loop;
#X obj 6 318 dac~, f 6;
#X obj 31 228 tabplay~ loop;
#X obj 30 179 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#N canvas 215 619 730 390 analyzers_______________________________ #N canvas 215 619 730 390 analyzers_______________________________
0; 0;
#X obj 95 44 inlet~; #X obj 95 44 inlet~;
@ -61,7 +51,7 @@
#X connect 13 0 29 0; #X connect 13 0 29 0;
#X connect 14 0 30 0; #X connect 14 0 30 0;
#X connect 15 0 31 0; #X connect 15 0 31 0;
#X restore 80 309 pd analyzers_______________________________; #X restore 218 298 pd analyzers_______________________________;
#X obj 46 26 bang~; #X obj 46 26 bang~;
#X obj 46 49 count 16; #X obj 46 49 count 16;
#X obj 46 76 sel 0; #X obj 46 76 sel 0;
@ -71,7 +61,7 @@
#X obj 45 42 r shmemupdate; #X obj 45 42 r shmemupdate;
#X obj 42 105 table levelmeters 16; #X obj 42 105 table levelmeters 16;
#X connect 1 0 0 0; #X connect 1 0 0 0;
#X restore 654 34 pd shmems; #X restore 421 27 pd shmems;
#N canvas 763 290 686 441 window 0; #N canvas 763 290 686 441 window 0;
#N canvas 0 0 450 300 (subpatch) 0; #N canvas 0 0 450 300 (subpatch) 0;
#X array hann 1024 float 1; #X array hann 1024 float 1;
@ -210,36 +200,69 @@
0.000244498 0.000150442 9.39965e-005 3.75807e-005 1.87755e-005; 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 coords 0 1 1023 0 300 100 1 0 0;
#X restore 39 32 graph; #X restore 39 32 graph;
#X restore 657 56 pd window; #X restore 420 50 pd window;
#N canvas 927 320 450 300 udpmessage 0; #N canvas 2182 728 450 338 commands_from_unity 0;
#X text 60 33 0 ... dsp; #X obj 44 31 inlet;
#X restore 660 100 pd udpmessage; #X obj 44 84 route 0;
#X msg 478 110 \; pd dsp 1; #X obj 44 177 s sample_playback;
#X connect 0 0 4 0; #X text 128 43 0 ... sample playback;
#X connect 0 0 7 0; #X connect 0 0 1 0;
#X connect 0 0 16 0; #X connect 1 0 2 0;
#X restore 230 79 pd commands_from_unity;
#N canvas 667 603 877 437 sample_playback 0;
#X obj 86 166 readsf~;
#X obj 95 6 r sample_playback;
#X obj 87 280 outlet~;
#X obj 269 241 makefilename ../../../../AudioSamples/%s;
#X obj 269 280 route symbol;
#X obj 269 202 symbol;
#X obj 269 163 text get samplefiles;
#X floatatom 269 125 5 0 0 0 - - -;
#X obj 95 38 sel 0;
#X obj 122 72 - 1;
#X msg 33 114 0;
#X msg 269 318 open \$1 \, 1;
#X connect 0 0 2 0;
#X connect 1 0 8 0; #X connect 1 0 8 0;
#X connect 1 1 8 1; #X connect 3 0 4 0;
#X connect 1 2 8 2; #X connect 4 0 11 0;
#X connect 1 3 8 3; #X connect 5 0 3 0;
#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 5 0;
#X connect 6 0 8 0;
#X connect 6 1 7 0;
#X connect 7 0 6 0; #X connect 7 0 6 0;
#X connect 9 0 10 0; #X connect 8 0 10 0;
#X connect 10 0 11 0; #X connect 8 1 9 0;
#X connect 11 0 12 0; #X connect 9 0 7 0;
#X connect 10 0 0 0;
#X connect 11 0 0 0;
#X restore 54 219 pd sample_playback;
#X obj 230 24 netreceive -u -b 54345;
#X obj 45 140 text define -k samplefiles;
#A set Back_Back.wav \; Brutal_Synth.wav \; Dialog.wav \; Drums.wav
\; Fox_Melo.wav \; Kick.wav \; Pads+Strings.wav \; Rose_Sax.wav \;
Roses_Front.wav;
#X obj 418 90 loadbang;
#X msg 418 117 \; pd dsp 1;
#X connect 0 0 2 0;
#X connect 0 1 2 1;
#X connect 0 2 2 2;
#X connect 0 3 2 3;
#X connect 0 4 2 4;
#X connect 0 5 2 5;
#X connect 0 6 2 6;
#X connect 0 7 2 7;
#X connect 0 8 2 8;
#X connect 0 9 2 9;
#X connect 0 10 2 10;
#X connect 0 11 2 11;
#X connect 0 12 2 12;
#X connect 0 13 2 13;
#X connect 0 14 2 14;
#X connect 0 15 2 15;
#X connect 3 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 6 0;
#X connect 10 0 1 0;
#X connect 10 0 1 1;
#X connect 10 0 2 0;
#X connect 11 0 9 0;
#X connect 13 0 14 0;

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0b4a7d86a42d4954fbae7c8ffa024e14
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 04552a3cec6540a4ea80bb0484b713bc
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 705b2647ea2483541866c0466bb12e61
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f6f49b6192a95384c94f48da8d83d053
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 129fd39c4116ba44a9dd09553877da45
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e92dfebc2a76b0a4983a6479bf585802
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f52ec377e44171c4b85108218b43ff56
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6335db3e5dad4304688c86c9e583c0a5
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2a3df2a4ee7800d4e8848625622eed9f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: