2019-09-28 22:19:35 +00:00
|
|
|
using System;
|
2019-09-28 18:17:39 +00:00
|
|
|
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_;
|
|
|
|
|
2019-09-29 16:04:26 +00:00
|
|
|
private PdProcess()
|
2019-09-28 18:17:39 +00:00
|
|
|
{
|
2019-09-29 16:04:26 +00:00
|
|
|
} // cannot be instantiate normally
|
|
|
|
|
2019-09-28 18:17:39 +00:00
|
|
|
|
2019-09-28 22:19:35 +00:00
|
|
|
public static PdProcess Instance => instance_ ?? (instance_ = new PdProcess());
|
2019-09-28 18:17:39 +00:00
|
|
|
|
|
|
|
public void Start(string mainPatch, int numInputChannels)
|
|
|
|
{
|
|
|
|
if (pdProcess_ != null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pdProcess_ = new Process();
|
|
|
|
pdProcess_.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
2019-09-28 22:19:35 +00:00
|
|
|
pdProcess_.StartInfo.UseShellExecute = false;
|
2019-09-28 18:17:39 +00:00
|
|
|
pdProcess_.StartInfo.FileName = Application.streamingAssetsPath + "/pd/win/pd.com";
|
|
|
|
|
|
|
|
var path = Application.streamingAssetsPath + "/pd/patch/" + mainPatch;
|
|
|
|
pdProcess_.StartInfo.Arguments = "-nogui -rt -inchannels " + numInputChannels + " " + path;
|
2019-09-28 22:19:35 +00:00
|
|
|
|
|
|
|
if (!pdProcess_.Start())
|
|
|
|
{
|
|
|
|
throw new Exception("Pd process failed to start");
|
|
|
|
}
|
2019-09-28 18:17:39 +00:00
|
|
|
Debug.Log("Pd Process started");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
{
|
|
|
|
pdProcess_?.Kill();
|
|
|
|
pdProcess_ = null;
|
|
|
|
Debug.Log("Pd Process stopped");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|