drop Pd Backend

This commit is contained in:
Chikashi Miyama 2019-10-05 06:15:15 +02:00
parent 2ceca4eec1
commit 9771869b4c
7 changed files with 50 additions and 45 deletions

View file

@ -62,6 +62,7 @@
<Compile Include="Assets\Scenes\Examples\PostProcessing\script\BokehBind.cs" />
<Compile Include="Assets\Scenes\Examples\VisualEffectGraph\script\FlareBind.cs" />
<Compile Include="Assets\Scenes\Examples\VisualEffectGraph\script\SmokeBind.cs" />
<Compile Include="Assets\Scripts\PdConnection\DspController.cs" />
<Compile Include="Assets\Scripts\PdConnection\SpectrumArrayContainer.cs" />
<Compile Include="Assets\Scripts\PdConnection\SpectrumArraySelector.cs" />
<Compile Include="Assets\Scripts\PdConnection\ISpectrumGenerator.cs" />

View file

@ -7,10 +7,6 @@ namespace cylvester
public class PdBackendEditor : Editor
{
private PdBackend 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 readonly string[] samples_ =
{
@ -29,25 +25,15 @@ namespace cylvester
private void Awake()
{
pdBackend_ = (PdBackend) target;
levelMeters_ = new ILevelMeter[16];
for (var i = 0; i < 16; ++i)
levelMeters_[i] = new LevelMeter(i);
}
public override void OnInspectorGUI ()
{
pdBackend_ = (PdBackend) target;
GUILayout.Space(5);
GUILayout.BeginHorizontal();
GUILayout.Label("Main Patch");
pdBackend_.mainPatch = GUILayout.TextField(pdBackend_.mainPatch, 30);
GUILayout.EndHorizontal();
if (Application.isPlaying)
{
RenderSamplePlayback();
RenderLevelMeters();
Repaint();
}
}
@ -58,13 +44,5 @@ namespace cylvester
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,25 @@
namespace cylvester
{
public interface IDspController
{
bool State { set; }
}
public class DspController : IDspController
{
private IPdSocket socket_;
public DspController(IPdSocket socket)
{
socket_ = socket;
}
public bool State
{
set
{
socket_.Send (new[]{(byte)PdMessage.dsp, (byte)(value?1:0)});
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 115ba206523f48d3bf8005ef8af8230f
timeCreated: 1570248564

View file

@ -5,48 +5,45 @@ namespace cylvester
{
public class PdBackend : MonoBehaviour
{
public string mainPatch = "analyzer.pd";
public int samplePlayback;
public PdArray levelMeterArray;
public ISpectrumArrayContainer spectrumArrayContainer;
private IChangeObserver<int> samplePlaybackObserver_;
private Action onSamplePlaybackChanged_;
private IPdSocket pdSocket_;
private IDspController dspController_;
private void Awake()
{
PdProcess.Instance.Start(mainPatch);
levelMeterArray = new PdArray("levelmeters", PdConstant.NumMaxInputChannels);
spectrumArrayContainer = new SpectrumArrayContainer();
pdSocket_ = new PdSocket(PdConstant.ip, PdConstant.port);
dspController_ = new DspController(pdSocket_);
samplePlaybackObserver_ = new ChangeObserver<int>(samplePlayback);
onSamplePlaybackChanged_ = () =>
{
var bytes = new[]{(byte)PdMessage.SampleSound, (byte)samplePlayback};
pdSocket_.Send(bytes);
pdSocket_.Send(new[]{(byte)PdMessage.SampleSound, (byte)samplePlayback});
};
samplePlaybackObserver_.ValueChanged += onSamplePlaybackChanged_;
dspController_.State = true;
}
private void OnDestroy()
{
PdProcess.Instance.Stop();
levelMeterArray?.Dispose();
dspController_.State = false;
pdSocket_?.Dispose();
samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_;
}
public void Update()
{
if(PdProcess.Instance.Running)
levelMeterArray.Update();
spectrumArrayContainer.Update();
samplePlaybackObserver_.Value = samplePlayback;
}
}
}

View file

@ -2,7 +2,8 @@ namespace cylvester
{
enum PdMessage
{
SampleSound = 0
dsp = 0,
SampleSound = 1
}
public class PdConstant

View file

@ -1,4 +1,4 @@
#N canvas 1494 726 560 380 10;
#N canvas 473 11 560 380 10;
#X obj 217 251 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 215 619 730 390 analyzers_______________________________
@ -203,11 +203,14 @@
#X restore 420 50 pd window;
#N canvas 2182 728 450 338 commands_from_unity 0;
#X obj 44 31 inlet;
#X obj 44 84 route 0;
#X obj 44 177 s sample_playback;
#X text 128 43 0 ... sample playback;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X obj 69 132 s sample_playback;
#X text 128 55 1 ... sample playback;
#X text 127 38 0 ... dsp start/stop;
#X obj 44 84 route 0 1;
#X msg 44 190 \; pd dsp \$1;
#X connect 0 0 4 0;
#X connect 4 0 5 0;
#X connect 4 1 1 0;
#X restore 230 79 pd commands_from_unity;
#N canvas 667 603 877 437 sample_playback 0;
#X obj 86 166 readsf~;
@ -240,8 +243,6 @@
#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;
@ -265,4 +266,3 @@ Roses_Front.wav;
#X connect 10 0 1 1;
#X connect 10 0 2 0;
#X connect 11 0 9 0;
#X connect 13 0 14 0;