2019-09-28 18:17:39 +00:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
|
{
|
|
|
|
|
public interface IPdBackend
|
|
|
|
|
{
|
2019-09-29 16:04:26 +00:00
|
|
|
|
string MainPatch { get; set; }
|
|
|
|
|
int NumInputChannels { get; set;}
|
|
|
|
|
|
|
|
|
|
IPdArray LevelMeterArray { get; }
|
2019-09-29 19:53:47 +00:00
|
|
|
|
IFftArrayContainer FFTArrayContainer { get; }
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PdBackend : MonoBehaviour, IPdBackend
|
|
|
|
|
{
|
2019-09-29 16:04:26 +00:00
|
|
|
|
public string mainPatch = "analyzer.pd";
|
|
|
|
|
public int inchannels = 2;
|
|
|
|
|
|
2019-09-28 18:17:39 +00:00
|
|
|
|
private Action onToggled_;
|
2019-09-29 16:04:26 +00:00
|
|
|
|
private PdArray levelMeterArray_;
|
2019-09-29 19:53:47 +00:00
|
|
|
|
private FftArrayContainer fftArrayContainer_;
|
2019-09-28 18:17:39 +00:00
|
|
|
|
|
2019-09-29 16:04:26 +00:00
|
|
|
|
private const int NumMaxInputChannels = 16;
|
|
|
|
|
|
|
|
|
|
public IPdArray LevelMeterArray => levelMeterArray_;
|
2019-09-29 19:53:47 +00:00
|
|
|
|
public IFftArrayContainer FFTArrayContainer => fftArrayContainer_;
|
2019-09-29 16:04:26 +00:00
|
|
|
|
|
|
|
|
|
public string MainPatch { get => mainPatch; set => mainPatch = value; }
|
|
|
|
|
public int NumInputChannels { get => inchannels -1; set => inchannels = value + 1; }
|
|
|
|
|
|
|
|
|
|
|
2019-09-29 19:53:47 +00:00
|
|
|
|
private void Start()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
|
|
|
|
PdProcess.Instance.Start(mainPatch, inchannels);
|
2019-09-29 16:04:26 +00:00
|
|
|
|
levelMeterArray_ = new PdArray("levelmeters", NumMaxInputChannels);
|
2019-09-29 19:53:47 +00:00
|
|
|
|
fftArrayContainer_ = new FftArrayContainer();
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 19:53:47 +00:00
|
|
|
|
private void OnDestroy()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
|
|
|
|
PdProcess.Instance.Stop();
|
2019-09-29 16:04:26 +00:00
|
|
|
|
levelMeterArray_?.Dispose();
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 19:53:47 +00:00
|
|
|
|
public void Update()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
2019-09-29 17:47:17 +00:00
|
|
|
|
if(PdProcess.Instance.Running)
|
|
|
|
|
levelMeterArray_.Update();
|
2019-09-29 19:53:47 +00:00
|
|
|
|
|
|
|
|
|
fftArrayContainer_.Update();
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|