PD-2-ThoughtMap (a patch and its children as a plantuml-usecase) (Linux Shell Script/Package) (v0.1.1 update below)
Background:
The project I have been working on, for over a year now, began to be more complex than I was able to visualize.
As such, I was required to build something which would allow me to "see" it in its entirety.
NOT the audio stream, passing from one object to another, nor the variables, nor sends.
But rather, I needed to see my objects, i.e. subpatches and abstractions themselves. And how they were embedded within one another. I needed to see the "programmatic-flow" from one sub-object to the next.
Which is how this came about. Examples:
simple example
1.poly.synth
Preface:
Miller's bi-recursive/toroidal loop function, i.e. going "../" up and/or going down "/x/y/z.pd" the embedded object-tree has (thus far eluded me. So the patch for now only recurses down the tree.
Purpose:
By setting up a "Send-To" link to ".pd" filetypes (within Linux), one is able to right-click and send any ".pd" file to the pd2thoughtmap shell script and after a brief time (depending on the complexity of the patch). the "defaultbrowser" will open with a plantuml (http:///www.plantuml.com) usecase diagram showing the "object-flow" from one nested object to the next (clipping branches which have no embedded abstractions).
My hope has been the benefit I have/can gain from this tool, will also benefit the pd community and folks in being able to better "see" what they have done. And how to better organize their patches to suit their vision, the need of the project, or just plain Efficiency.
Instructions:
1-Download the pd2thoughtmap.zip file: pd2thoughtmapv0.1.zip
2-Unzip the file into the /root/pd-externals directory;
3-Right-click on a ".pd" file and go to ~"Configure Send-To" or the equivalent for your linux system;
4-Symlink from the /root/pd-externals/pd2thoughtmap/pd2thoughtmap shell script to the Send-To folder for ".pd" files
5-Right-click on a .pd file and "Send-To pd2thoughtmap";
6-After a pause, your default browser will open with the thoughtmap in a tab. (If your browser is already open it will just open another tab).
note: file processing is managed in the /tmp/pd2thoughtmap folder so unloaded at shutdown.
May this tool expedite your auditory "vision" and make it easier for you to comprehend.
Peace, Love, and Music through us all,
Scott
Footnotes:
It recurses down (the directory-tree finding descendants) just fine but will not go up (find predecessors/ancestors).
It will not recurse abstractions if the filenames have more than one period (i.e. the one in the ".pd" suffix).
It Excludes native pd abstractions/classes, ex. [adc~], etc., if they are 1) on the res/objectlist.txt, 2) a ".pd_linux" file in the pure data paths, i.e. "/root/pd-externals/", "/usr/lib/pd/extra/", or "/usr/lib/puredata/". or 3) manually entered into the "res/exclude.txt" file (in the case where one abstraction is repeated many times and you want to ignore it).
If using the command line, there are four total parameters available (to be used all together): $1=the absolute path to the file, $2={0|1|2,3} to indicate if you want "abs and subpatches", "abs only", "subpatches only", or all pd object types, ex. messages, floatatoms, etc; and $3=the height of the image in pixels, and $4=the width of the image in pixels.
If you want me to debug something, please, attach the outputted .png and the /tmp/pd2plantuml/log.txt to your post.
If you find it outputting things that should have been excluded, you can try to eliminate them by adding the object name to the exclude.txt file. This inconsistency is derived from my complete knowledge of the pd file structure. Perhaps I will address it in the future.
I need to work on the original patch for a while, so will update this patch over time and get back with you when I can.
Tally-Ho! And Joy!
-S
Matrices and reallocating memory
I tried to find all my errors, corrected them and now it seemes to work.
(The method init_array is still missing a check if allocations failed.)
Do I really have to free the colums before reallocating the rows? Isn't it the other way around?
#include "m_pd.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
static t_class *average_tilde_class;
typedef struct _average_tilde {
t_object x_obj;
t_int len_avg;
t_int block_size;
t_int pos;
t_sample **sampel_arr;
t_sample *avg;
t_inlet* x_in;
t_outlet* x_out;
} t_average_tilde;
void average_tilde_free (t_average_tilde *x)
{
// Deallocate rows
for (int i = 0; i < x->len_avg; ++i)
free(x->sampel_arr[i]);
// Deallocate columns
free(x->sampel_arr);
// Deallocate avg
free(x->avg);
}
t_int *average_tilde_perform(t_int *w)
{
t_average_tilde *x = (t_average_tilde *)(w[1]);
t_sample *in = (t_sample *)(w[2]);
t_sample *out = (t_sample *)(w[3]);
//int block = (int)(w[4]);
t_sample val;
for (int n = 0; n < x->block_size; n++) {
x->avg[n] -= x->sampel_arr[x->pos][n];
val = in[n] / x->block_size;
x->avg[n] += val;
x->sampel_arr[x->pos][n] = val;
*out++ = x->avg[n];
}
x->pos++;
if (x->pos == x->len_avg) x->pos = 0;
return (w + 5);
}
void resize_avg_array(t_average_tilde *x, int len_avg_new)
{
int i,j;
int success = 1;
t_sample **temp = NULL;
t_sample *temp2 = NULL;
do {
success = 1;
// Allocate the columns
temp = realloc(temp, len_avg_new * sizeof(t_sample*));
if (temp == NULL) {
len_avg_new--;
free(temp);
success = 0;
}
else {
// The new column's pointer must be initialised to NULL
for (i = 0; i < len_avg_new; i++)
temp[i] = NULL;
// Allocate the rows
for (i = 0; i < len_avg_new; i++) {
temp[i] = realloc(temp[i], x->block_size * sizeof(t_sample));
if (temp[i] == NULL) {
len_avg_new--;
success = 0;
break;
}
else {
// Initialize the element(s)
for (j = 0; j < x->block_size; j++)
temp[i][j] = 0.0;
}
}
if (success == 1) {
// Initialize avg-array
temp2 = realloc(temp2, x->block_size * sizeof(t_sample));
if (temp2 == NULL) {
len_avg_new--;
success = 0;
free(temp2);
}
else {
// Initialize the element(s)
for (i = 0; i < x->block_size; i++)
temp2[i] = 0.0;
}
if (success == 1) {
// Deallocate rows
for (i = 0; i < x->len_avg; ++i)
free(x->sampel_arr[i]);
// Deallocate columns
free(x->sampel_arr);
// Copy temps to arrays
x->len_avg = len_avg_new;
x->sampel_arr = temp;
free(x->avg);
x->avg = temp2;
x->pos = 0;
}
}
}
} while (success = 0 && len_avg_new > 0);
if (success = 0) {
post("length of avg-vector stayed at %i samples", x->len_avg);
}
}
void average_tilde_dsp(t_average_tilde *x, t_signal **sp)
{
x->block_size = sp[0]->s_n;
float arr_size = sizeof(x->sampel_arr) / sizeof(x->sampel_arr[0][0]);
if (x->block_size * x->len_avg != arr_size)
resize_avg_array(x, 10);
dsp_add(average_tilde_perform, 4,
x,
sp[0]->s_vec,
sp[1]->s_vec,
sp[0]->s_n);
}
void set_len_avg(t_average_tilde *x, t_floatarg f)
{
if ((int)f > 0)
resize_avg_array(x, f);
}
void init_array(t_average_tilde *x)
{
int i = 0, j = 0;
// Allocate the columns
x->sampel_arr = (t_sample**)calloc(x->len_avg, sizeof(t_sample*));
// Allocate the rows
for (i = 0; i < x->len_avg; i++)
x->sampel_arr[i] = (t_sample*)calloc(x->block_size, sizeof(t_sample));
// Initialize the element(s)
for (i = 0; i < x->len_avg; i++)
for (j = 0; j < x->block_size; j++)
x->sampel_arr[i][j] = 0.0;
// Initialize avg-array
x->avg = realloc(x->avg, x->block_size * sizeof(t_sample));
for (j = 0; j < x->block_size; j++)
x->avg[j] = 0.0;
}
void *average_tilde_new(t_floatarg f)
{
t_average_tilde *x = (t_average_tilde *)pd_new(average_tilde_class);
// initialize values with defaults
x->len_avg = ((int)f > 0) ? (int)f : 10;
x->block_size = 64;
x->pos = 0;
init_array(x);
x->x_out = outlet_new(&x->x_obj, &s_signal);
return (void *)x;
}
void init_average(void) {
average_tilde_class = class_new(gensym("r_avg~"),
(t_newmethod)average_tilde_new,
(t_method)average_tilde_free,
sizeof(t_average_tilde),
CLASS_DEFAULT,
A_DEFFLOAT, 0);
class_addmethod(average_tilde_class,
(t_method)average_tilde_dsp, gensym("dsp"), 0);
CLASS_MAINSIGNALIN(average_tilde_class, t_average_tilde, len_avg);
class_addfloat(average_tilde_class, set_len_avg);
}
void helloworld_setup(void) {
init_average();
}
EDIT: Corrected some logical errors in the code.
The variable success has to be set to 1 in each do while loop
The arrays x->sampel_arr and x->avg have to be freed inside the do while loop
libpd on mac: clarification requested on expected behavior of cpp sample
Thanks for those links Monetus. I'm pretty close with my existing setup and will first try to work with that when I have some more time. Some of the output from the samples/cpp/pdtest appears to be as expected.
However, from main.cpp
cout << endl << "BEGIN Patch Test" << endl;
// open patch
Patch patch = pd.openPatch("pd/test.pd", ".");
cout << patch << endl;
// close patch
pd.closePatch(patch);
cout << patch << endl;
// open patch again
patch = pd.openPatch(patch);
cout << patch << endl;
// process any received messages
//
// in a normal case (not a test like this), you would call this in
// your application main loop
pd.processFloat(1, inbuf, outbuf);
pd.receiveMessages();
cout << "FINISH Patch Test" << endl;
the response
BEGIN Patch Test
Patch: "pd/test.pd" $0: 1003 valid: 1
Patch: "pd/test.pd" $0: 0 valid: 0
Patch: "pd/test.pd" $0: 1005 valid: 1
PD: PATCH OPENED: 1003
print: 0
PD: PATCH OPENED: 1005
print: 0
FINISH Patch Test
seems right but no patch was opened and if I already opened that patch before running the executable, none of the print messages (called later in the code) showed up in the console of pd. I'll focus on this and try to repost to the forum when I have a better idea of what is going on.
Loading a pure data patch ( .pd file ) within a pure data patch ( .pd file )
HI!
Quick version:
My folder structure:
/mother-patch.pd ( main pure data patch first loaded and running... )
/patches/1/main.pd
/patches/2/main.pd
/patches/3/main.pd
...
How i could open /patches/1/main.pd triggered by some action in the mother-patch.pd?
How i could close /patches/1/main.pd triggered by some action in the mother-patch.pd?
Long read
I'm attempting to clone the Critter and Guitari organelle ( link ).
This instrument is basically a computer running libpd and running very cool pure data patches
You can read more about my project here ( link )
I have a mother pure data patch that it's first loaded when the device is on, this patch is doing some [send] and [receive] operations related to the knobs/keyboard/volume/led and it should be also managing the loading ( opening and closing ) of the child pure data patches ( mentioned above ). This child patches are receiving the actions from the mother patch.
If I open the mother patch and the child patches manually, everything works fine. But now I need to OPEN this CHILD PURE DATA patches with a object within the mother patch.
I've been testing [open] , for opening the main.pd of the child patches but it does not work.
I've been testing [pd] , for opening the main.pd of the child patches but it does not work.
I wouldn't like to modify the original organelle patches.
I wouldn't like to end up loading all the patches using [pd ...] and inserting a [switch] object inside every main.pd file in the patches in order to enable only the dsp of the desired patch.
It would be perfect If i could have a folder with all the patches and load them within the mother patch with some kind of object. And I would also want to be able to CLOSE the pure data patch and open another ( changing patches... )
Every little and big help woul be MUCH APRECIATED!
THANKS!!!!!!!
How To Install pd on Windows 10?
@wmullaney There are instructions in the "install.txt" file in "pd-0.46-7.msw\pd" but I have never tried.
However, you can open the "pd.com" program (or pd.exe if you wish) in the " .............pd-0.46-7.msw\pd\bin" folder, and then when the console opens you must go to "edit" "preferences" "path" and put (by pressing the "new" button) the paths to the "bin" folder and the path to your "working" folder (where you want to keep your patches)......
That will get you up and running in a sort of "portable" mode........
David.
Using savepanel
@sylvain Hello Sylvain.......
Here is a way to do what you want (extended only I think). It was built for another purpose (obviously) and used principally [iem_pbank_csv] and [slist] as I wanted shared lists throughout my patch without needing to write them to a file all the time........... only when I really wanted to save the data.......
In this example a list of 17 pieces of data is saved within [iem_pbank_csv] at the line corresponding to the "number" (index) of the bus_control whenever any data is changed within that control. The bus names are shared to [slist tablets] for other parts of the patch....... to allow dynamic message routing. The data set is stored to a text file with the same name when that "name" is sent to "save_busses". Send and recall any name you wish and it will create/overwrite and read the file.
[iem_pbank_csv] is set to write a text file with 64 lines of 17 atoms using "blank" as the atom delimeter and "return" as the "end of line" delimeter....... (hence the "br" in the messages that it is sent)......
The lists are named for ease of human recall......."start" "hum" ("foo" "woof" if you wish)......
Open "top_patch.pd".......
list storage.zip
Otherwise there is [qlist] for vanilla..... and [value] could be used to share saved values until saving the lists.......
I think that might be easier..... but I didn't ask the question on the forum at the time..... doh!.......
David.
pd "could'nt load" extra
ok, I removed the chmod a-x and now it is working
has the Makefile been tested for windows ? how can I change it so that instruction is only executed on linux ?
I found it here https://puredata.info/docs/developer/LibraryTemplate
I am creating an interactive tutorial for a data flow workshop, anyone care to share ideas?
Hello again Gummi...... good idea..... a few thoughts.
So your (first) workshop will be "data-flow"......
I tried a while ago to build a patch that might demonstrate "what is a dataflow language". When I first came across Pd it reminded me of a very brief lesson at school (long long ago) where I learnt (a little) about the data-flow diagram. But Pd is more sophisticated than that, and I had some trouble demonstrating the possibilities without just chaining a whole load of spigots together. I suppose I tried to make it too simple. I will be very interested to see your patch!
However, I think you should start with this.........a simple drawing.....in traditional "diamond" boxes.....
Is there a good film on?... yes/no
shall we go?.......yes/no
Is it raining?......yes/no
Do we have 2 umbrella?.........yes/no
etc.
There will be no need to resolve the chart..... but it gives a hint about how Pd works. That is the bit I forget every day....... that Pd also deals much of the time with logic...... 1 and 0..... true and false...
Because Pure Data is in fact a formidable system engineering platform........... that is used most of the time for audio and music.
And then I agree with @Liam about all of the points he made, but I think you will need to "whet their appetites" before you deal with "nitty gritty". They should be given http://puredata.info/docs/manuals/pd/x2.htm for absolutely compulsory homework
I think I would start with an osc control and not an [osc~] sound....... and show them how you can have a touch fader on a tablet sending osc messages that controls a gui in Pd via udp binary packets (maybe not too much detail there at first though?) over a wi-fi connection and then transform that data into some visuals and sounds so as to get them excited.......... because.......
....... if you can see the beginning and the end of the journey before you start it is much easier to understand all of the decisions that were taken on the "rocky road" in between.......
If Pd was a system for growing vegetables I would have said "and then show them some vegetables". I am a fan of the data-flow more than the vegetables..... sorry, more than the audio-visual...... even though I am an audio-visual engineer. Pd does all of the "stuff" that you cannot do elsewhere with audio-visual software.
Make sure as @Liam says that you have trigger and route and other important objects in the chain (unavoidable really), and go through the whole chain with "magic glass" showing them what is going on in the "string" (of course you will need a "slow metro" at the head of the chain for that). Don't bother showing them how you generate the sounds and visuals.... that will be too much for day one....... but explain how you got the "data" to "flow"..............
And then finish up with more of the bin ops and [expr] maybe to show the "power at your fingertips".........
I wish I had better understood list from day one (and float symbol anything pointer).
My favourite tools are the list tools..... split, drip etc. and I cannot live without [cxc_split] and especially [slist] !
David.