Exemplo n.º 1
0
    void OnGUI()
    {
        float x         = 0;
        float y         = 0;
        float btnWidth  = Screen.width * .4f;
        float btnHeight = btnWidth * .2f;
        float margin    = 20.0f;

        if (!patchOpened)
        {
            if (GUI.Button(new Rect(x, y, btnWidth, btnHeight), "Open Patch"))
            {
                patchOpened = true;
                libPd.OpenPatch(patch, id => patchId = id);
                libPd.LoadClip("sample0", clip, "sample_length");
                libPd.Subscribe("frequency");
            }
        }
        else if (patchId != -1 && GUI.Button(new Rect(x, y, btnWidth, btnHeight), "Close patch"))
        {
            libPd.ClosePatch(patchId);
            patchOpened = false;
        }

        y += btnHeight + margin;
        GUI.Label(new Rect(x, y, btnWidth, btnHeight), "Pitch:");
        y    += margin;
        pitch = GUI.HorizontalSlider(new Rect(x, y, btnWidth, btnHeight), pitch, .0f, 1.0f);
        libPd.SendFloat("pitch", pitch);
        Debug.Log("STREAM OF FLOATS: " + LibPD.receivedFloatValue);
    }
Exemplo n.º 2
0
 public PdOperation(string filePath)
 {
     _patchHandle = LibPD.OpenPatch(filePath);
     LibPD.Bang  += LibPD_Bang;
     LibPD.Subscribe(DoneReceiver);
     LibPD.OpenAudio(0, 2, SampleRate);
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 3
0
        public static void loadPatch()
        {
            SDllHandle = LoadLibrary("libpdcsharp.dll");
            LibPD.ReInit();

            LibPD.OpenAudio(2, 3, 44100);
            SPatch = LibPD.OpenPatch(@"..\..\test_csharp.pd");
            LibPD.ComputeAudio(true);
        }
Exemplo n.º 4
0
        private int LoadPatch(string patchName)
        {
            string assetsPath = Application.streamingAssetsPath + "/PdAssets/";
            string path       = assetsPath + patchName;

#if UNITY_ANDROID && !UNITY_EDITOR
            path = JavaLoadPatch(path, patchName);
#endif
            return(LibPD.OpenPatch(path));
        }
Exemplo n.º 5
0
 public void Open(params string[] patchesName)
 {
     foreach (string patchName in patchesName)
     {
         string path = GetPatchPath(patchName);
         patches[Path.GetFileName(patchName)] = LibPD.OpenPatch(path);
         pdPlayer.communicator.Initialize();
         pdPlayer.itemManager.Initialize();
     }
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Sets up communication with libPd.
 /// </summary>
 void SetUpPd()
 {
     // Open Pd file
     _patchHandle = LibPD.OpenPatch("../../pd/test.pd");
     // Subscribe to receiver
     LibPD.Float += LibPd_Float;
     LibPD.Subscribe(CursorReceiver);
     // Set up audio format for Pd
     LibPD.OpenAudio(0, 2, SampleRate);
     // Start audio
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 7
0
        public static void loadPatch()
        {
            if (loader == null)
            {
                loader = IsLinux() ? (IDllLoader) new LinuxDllLoader() : (IDllLoader) new WindowsDllLoader();
            }
            SDllHandle = loader.LoadLibrary("libpdcsharp." + (IsLinux() ? "so" : "dll"));
            LibPD.ReInit();

            LibPD.OpenAudio(2, 3, 44100);
            SPatch = LibPD.OpenPatch(@"../../test_csharp.pd");
            LibPD.ComputeAudio(true);
        }
Exemplo n.º 8
0
    public void loadPatch()
    {
        Debug.Log("Load patch:" + path);

        // we can also work in stereo or more: LibPD.OpenAudio (2, 2, 48000);
        if (!islibpdready)
        {
            LibPD.OpenAudio(1, 1, 48000);
        }
        SPatch = LibPD.OpenPatch(path);
        LibPD.ComputeAudio(true);
        islibpdready = true;

        //LibPD.Print += Receive;
    }
Exemplo n.º 9
0
 public void Open(params string[] patchesName)
 {
     foreach (string patchName in patchesName)
     {
         if (!patchIdDict.ContainsKey(Path.GetFileName(patchName)))
         {
             string path = GetPatchPath(patchName);
             patchIdDict[Path.GetFileName(patchName)] = LibPD.OpenPatch(path);
             pureData.communicator.Initialize();
             pureData.busManager.Update();
             pureData.spatializerManager.Update();
         }
     }
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 10
0
    /** Pd helper functions from here **/

    // Load pd patch, specfied in Unity's inspector, returns patch handle
    public int loadPatch(string patchName)
    {
        string assetsPath = Application.streamingAssetsPath + "/PdAssets/";

        Debug.Log(assetsPath);
        string path = assetsPath + patchName;

        // Android voodoo to load the patch. TODO: use Android APIs to copy whole folder?
                #if UNITY_ANDROID && !UNITY_EDITOR
        string patchJar = Application.persistentDataPath + "/" + patchName;

        if (File.Exists(patchJar))
        {
            Debug.Log("Patch already unpacked");
            File.Delete(patchJar);

            if (File.Exists(patchJar))
            {
                Debug.Log("Couldn't delete");
            }
        }

        WWW dataStream = new WWW(path);


        // Hack to wait till download is done
        while (!dataStream.isDone)
        {
        }

        if (!String.IsNullOrEmpty(dataStream.error))
        {
            Debug.Log("### WWW ERROR IN DATA STREAM:" + dataStream.error);
        }

        File.WriteAllBytes(patchJar, dataStream.bytes);

        path = patchJar;
                #endif

        Debug.Log("Loading patch:" + path);
        return(LibPD.OpenPatch(path));
    }
Exemplo n.º 11
0
    void OnGUI()
    {
        float x         = 0;
        float y         = 0;
        float btnWidth  = Screen.width * .4f;
        float btnHeight = btnWidth * .2f;
        float margin    = 20.0f;

        if (!patchOpened)
        {
            if (GUI.Button(new Rect(x, y, btnWidth, btnHeight), "Open Patch"))
            {
                patchOpened = true;
                libPd.OpenPatch(patch, id => patchId = id);
                libPd.Subscribe("frequency");

                /*
                 * Microphone stream
                 */
                var audio = GetComponent <AudioSource>();
                audio.clip = Microphone.Start("Built-in Microphone", true, 1, 44100);
                audio.loop = true;
                while (!(Microphone.GetPosition(null) > 0))
                {
                }
                audio.Play();

                libPd.SendFloat("metroOnOff", 1);                  // Turn frequency snapshots ON
            }
        }
        else if (patchId != -1 && GUI.Button(new Rect(x, y, btnWidth, btnHeight), "Close Patch"))
        {
            libPd.ClosePatch(patchId);
            patchOpened = false;
        }

        y += btnHeight + margin;
        GUI.Label(new Rect(x, y, btnWidth, btnHeight), "Pitch:");
        y        += margin;
        inputGain = GUI.HorizontalSlider(new Rect(x, y, btnWidth, btnHeight), inputGain, .0f, 1.0f);
        libPd.SendFloat("inputGain", inputGain);
        Debug.Log("STREAM OF FLOATS: " + LibPD.receivedFloatValue);
    }
Exemplo n.º 12
0
        // Startup audio engine
        public static void Startup()
        {
            LibPD.ReInit();

            LibPD.Print += printCallback;

            LibPD.Float += floatCallback;
            LibPD.Bang  += bangCallback;

            LibPD.OpenAudio(1, 2, 44100);
            LibPD.ComputeAudio(true);
            handle = LibPD.OpenPatch("patch/soundsystem.pd");

            PortAudio.Pa_Initialize();
            PortAudio.Pa_OpenDefaultStream(out stream, 1, 2, (uint)PortAudio.PaSampleFormat.paFloat32,
                                           44100,
                                           256,
                                           renderCallback,
                                           (IntPtr)null);
            PortAudio.Pa_StartStream(stream);
        }
Exemplo n.º 13
0
 public void Start()
 {
     LibPD.OpenPatch(pdPlayer.folderPath + "PDPlayer" + Path.AltDirectorySeparatorChar + "initialize~.pd");
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 14
0
 void Start()
 {
     initPd();
     patchHandle = LibPD.OpenPatch(Application.streamingAssetsPath + "/randomOsc.pd");
     LibPD.ComputeAudio(true);
 }