示例#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);
    }
示例#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);
 }
示例#3
0
 public void Receive(string sendName, MessageReceiveCallback messageReceiver, bool asynchronous = false)
 {
     if (!sendNameMessageReceiverDict.ContainsKey(sendName))
     {
         LibPD.Subscribe(sendName);
         sendNameMessageReceiverDict[sendName] = new List <PureDataMessageReceiver>();
     }
     sendNameMessageReceiverDict[sendName].Add(new PureDataMessageReceiver(sendName, messageReceiver, asynchronous, pureData));
 }
示例#4
0
 public void SubscribeDebug()
 {
     LibPD.Subscribe("Debug");
     LibPD.Bang    += ReceiveDebugBang;
     LibPD.Float   += ReceiveDebugFloat;
     LibPD.Symbol  += ReceiveDebugSymbol;
     LibPD.List    += ReceiveDebugList;
     LibPD.Message += ReceiveDebugMessage;
 }
示例#5
0
    void Start()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        Screen.orientation = ScreenOrientation.Landscape;
#endif

        // subscribing to receive
        LibPD.Subscribe("note");
        LibPD.Float += receiveFloat;
    }
 public void SubscribeDebug()
 {
     LibPD.Subscribe("Debug");
     LibPD.Subscribe("Command");
     LibPD.Bang    += ReceiveBang;
     LibPD.Float   += ReceiveFloat;
     LibPD.Symbol  += ReceiveSymbol;
     LibPD.List    += ReceiveList;
     LibPD.Message += ReceiveMessage;
 }
示例#7
0
 public void SubscribeDebug()
 {
     LibPD.Subscribe("debug");
     LibPD.Subscribe("uaudiosource_fadeout");
     LibPD.Subscribe("uaudiosource_stop");
     LibPD.Bang    += ReceiveBang;
     LibPD.Float   += ReceiveFloat;
     LibPD.Symbol  += ReceiveSymbol;
     LibPD.List    += ReceiveList;
     LibPD.Message += ReceiveMessage;
 }
示例#8
0
 public virtual void testSubscription()
 {
     Assert.False(LibPD.Exists("baz"));
     Assert.False(LibPD.Subscribe(null));
     Assert.True(LibPD.Subscribe("baz"));
     Assert.True(LibPD.Exists("baz"));
     Assert.False(LibPD.Unsubscribe(null));
     Assert.False(LibPD.Unsubscribe(""));
     Assert.True(LibPD.Unsubscribe("baz"));
     Assert.False(LibPD.Exists("baz"));
 }
示例#9
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);
 }
示例#10
0
 void SetLibPD()
 {
     LibPD.Subscribe("Debug");
     LibPD.Bang    += ReceiveDebugBang;
     LibPD.Float   += ReceiveDebugFloat;
     LibPD.Symbol  += ReceiveDebugSymbol;
     LibPD.List    += ReceiveDebugList;
     LibPD.Message += ReceiveDebugMessage;
     sampleRate     = AudioSettings.outputSampleRate;
     AudioSettings.GetDSPBufferSize(out bufferSize, out bufferAmount);
     LibPD.SendFloat("BufferSize", bufferSize);
     LibPD.SendFloat("BufferAmount", bufferAmount);
     LibPD.SendFloat("SampleRate", sampleRate);
 }
示例#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);
    }
示例#12
0
        public static void SubscribeBang(string name, Action handler)
        {
            LibPD.Subscribe(name);

            bangHandlers[name] = handler;
        }
示例#13
0
        public static void SubscribeFloat(string name, Action <float> handler)
        {
            LibPD.Subscribe(name);

            floatHandlers[name] = handler;
        }
示例#14
0
        public virtual void testReceive()
        {
            var receiver = "spam";
            var listArgs = new object[] { "hund", 1, "katze", 2.5, "maus", 3.1f };
            var msgName  = "testing";
            var msgArgs  = new object[] { "one", 1, "two", 2 };

            LibPD.Subscribe(receiver);

            var n = 0;

            LibPDBang delBang = delegate(string recv) {
                Assert.AreEqual(receiver, recv);
                n++;
            };

            LibPD.Bang += delBang;

            LibPDFloat delFloat = delegate(string recv, float x) {
                Assert.AreEqual(receiver, recv);
                Assert.AreEqual(42, x);
                n++;
            };

            LibPD.Float += delFloat;

            LibPDSymbol delSymbol = delegate(string recv, string sym) {
                Assert.AreEqual(receiver, recv);
                Assert.AreEqual("hund katze maus", sym);
                n++;
            };

            LibPD.Symbol += delSymbol;

            LibPDList delList = delegate(string recv, object[] args) {
                Assert.AreEqual(receiver, recv);
                Assert.AreEqual(listArgs.Length, args.Length);

                for (int i = 0; i < args.Length; i++)
                {
                    Assert.AreEqual(listArgs [i], args [i]);
                }
                n++;
            };

            LibPD.List += delList;

            LibPDMessage delMessage = delegate(string recv, string msg, object[] args) {
                Assert.AreEqual(receiver, recv);
                Assert.AreEqual(msgName, msg);
                Assert.AreEqual(msgArgs.Length, args.Length);

                for (int i = 0; i < args.Length; i++)
                {
                    Assert.AreEqual(msgArgs [i], args [i]);
                }
                n++;
            };

            LibPD.Message += delMessage;

            LibPD.SendBang(receiver);
            LibPD.SendFloat(receiver, 42);
            LibPD.SendSymbol(receiver, "hund katze maus");
            LibPD.SendList(receiver, listArgs);
            LibPD.SendMessage(receiver, msgName, msgArgs);

            Assert.AreEqual(5, n);

            LibPD.Bang    -= delBang;
            LibPD.Float   -= delFloat;
            LibPD.Symbol  -= delSymbol;
            LibPD.List    -= delList;
            LibPD.Message -= delMessage;
        }