Wiki

Clone wiki

Pd++ / Home

Welcome to Pd++

Pd++ is a C++ emulation of Pure Data objects. Pure Data is audio synthesis software intended for computer musicians and functions as a standalone application, (http://www.puredata.info) and also as an embedded library known as libpd, (http://www.libpd.cc). Pd++ is meant to separate the functionality of the Pd object code from the Pd application code into an object oriented system which can be used with existing projects or into new applications.

Pd++ classes are designed to function very much like their graphical Pd representations. More so, much of the same code is used from Pd to Pd++ with some adaptations and variations. Some major differences will be the concept of inlets, outlets and arguments. First, there is no difference between signal and control. Everything is scheduled in the same way. You could write your own scheduler to handle other types of events.

Inlets are simulated with a perform(arg1, arg2...) function where the args would be the input (inlet) to the function. The output or return value of this function would be the same as the outlet(s) in Pd. If there are more than one outlet in a Pd object most often the Pd++ class will return a struct or a pointer to a struct that represents the data being processed. The documentation and the class header files should hopefully clarify these items.

Not all Pd objects exist as Pd++ classes. One important difference is that all of the math functions of Pd are not separate classes in Pd++. So +, - , * and / would just be their C++ equivalent. Also, most of the logic or relational objects are left out as most of that can be easily programmed within your algorithm and will probably function better. For example objects like [select], [moses] or [route] are left out in favor of you programming that logic yourself. If you think about it your code will read much better if you don't have too many classes doing very common C++ things like if statements and relational logic.

For a comprehensive list of all classes see the MasterObjectList.h file.

Pd++ repository

To clone the repository try:

$ git clone https://resler@bitbucket.org/resler/pd.git

Documentation

A doxygen documentation comes with the repository. Open the index.html file to get started. You can also find the not as frequently updated web version here: http://www.robertesler.com/pd. I am planning on no longer using Doxygen anymore for updates to the API documentation. Unless someone notifies me of a good reason otherwise, all documentation will live in the code samples from now own.

Basic How-To:

The main class of Pd++ is PdAlgorithm. The runAlgorithm() function would be where all of your code would need to go. You could still use other classes, and non-static member functions to represent your Pd "subpatches" or "abstractions". Depending on which audio API you use, I use portaudio (http://www.portaudio.com), you would call the runAlgorithm() function in the audio callback. There is an example of my portaudio wrapper in paRender++.cpp.

The repository comes with two main() functions. One is setup to test audio output using portaudio, the other is setup to only print the data stream. Running audio and printing the stream at the same time may cause interruptions so I don't recommend it. Also, make sure when testing audio to have your volume all the way down and then bring it up. Many times have I hurt my ears because of a bad value and not realizing my volume was full blast.

Here's an example of the runAlgorithm() function from the Pd++ code:

#!cpp

Buffer PdAlgorithm::runAlgorithm(double input1, double input2) {    
    Buffer theBuffer;

    /*This is the audio input stream*/
    theBuffer.inbuf1 = input1;
    theBuffer.inbuf2 = input2;
    double signal = 0;
    double signal2 = 0;

    // variable delay example showing doppler
    double n = osc2.perform(689.0625);
    double d = (osc.perform(5) + 10) * 3;
    vd.delayWrite(n);
    signal = .2*vd.perform(d);
    signal2 = signal;


    /*write output to theBuffer.outbufL, theBuffer.outbufR*/
    theBuffer.outbufL =  signal;
    theBuffer.outbufR =  signal2;

     return theBuffer;

}

Pd++ possibilities

Originally this library was meant for my own purposes of creating applications that need audio synthesis. If you have searched around there are not many open source C++ options for audio synthesis libraries short from those that support audio file manipulation. STK (https://ccrma.stanford.edu/software/stk/download.html) is one of the closest but does not conform to the conventions of Pd. There are few others as well, but again they typically are not an open license (like JUCE, or SuperPowered Audio), and do not contain the same conventions as Pd. Thus, Pd++.

Pd++ is not trying to be like libpd (https://github.com/libpd) or the Heavy Compiler (https://github.com/enzienaudio/hvcc). Pd++ is an alternative to Pd. There are lots of things you cannot do with Pd like dynamic memory, parallel processing, object inheritance, multi-threading, etc. As well basic logic in Pd can be very cumbersome at time consuming (try to create a state machine in Pd!) I have had the most success in creating AU/VST plugins with Pd++. There is an example of Pd++ as an Audio Unit plug-in here. Pd++ and Audio Unit Programming

Aside from this I also wanted something to teach basic programming to audio engineers and computer musicians. Those of us that are already familiar with Max or Pd can benefit from knowing a programming language like C++. Pd++ is being developed with education in mind.

There is no code generation for Pd++, like Max and Gen~ or the Heavy Compiler. If those products work for you, then keep using them. Pd++ is meant to be a different paradigm from regular Pd.

License and other information:

This library is released under the same license as Pure Data. See the license information below.

This software is copyrighted by Robert Esler, some parts by Miller Puckette and others. The following terms (the "Standard Improved BSD License") apply to all files associated with the software unless explicitly disclaimed in individual files:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above
    copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Updated