Color Highlighting with easyflow ‐ variable wireless connections - HenriAugusto/easyflow GitHub Wiki

Only by using those rectangles and circles you can do wonders to organize your code. But there is one more kind of wireless connection that i like to mark. Let's call it "variable wireless connection". Below is an simple example of how to do it

variableWirelessConnection.png

For this one i will use an example from the Guilla library. It is a in-patch color picker.

color picker demo.gif

I'm not going on the details because they're not needed right know but it works basically as follows:

  • Define a data structure to draw squares with varying colors. When you click one of them it send it's color to the outlet.
  • [loadbang] triggers the scalars creation. [easyflow/hueSaturationLuminosity] is used to find their color.
  • Left to right we have luminosity, from maximum to minimum.
  • Down to up we have saturation, from maximum to minimum.
  • Hue is controlled by an slider.

Here we face an issue.

A lot of those objects are very complex. Every time you load an patch or an abstraction it has to parse the .pd file and load and connect everything. When PD finds an abstractions inside an abstraction then it does the same parsing over the corresponding .pd file. In our case only the abstractions responsible to calculating the colors are somewhat big. Now put a lot of this stuff together with lots of abstractions inside of abstractions and it can take you about 5~15 seconds to simply load an abstraction depending on your computer's speed. How can we minimize that?

At first i've created an abstraction that, given an index (there are 16x16=256 squares, so indexes range from 1 to 256) it would tell the color for the square on that index. There were two of that abstraction. One inside the initialization routine, to get the colors when creating the squares, and the other was on the routine that updates the colors when the slider is changed. While having this abstraction on every place you need it might seem more natural (like calling a function on an textual language) in Pure Data it actually loads everything each time the abstraction is used. How can we load it only a single time?

First things first: i've put it on a subpatch because it doesn't make sense now to have it on an abstraction. What i'm doing now is to send two values to this subpatch.

  1. the index to be processed
  2. a symbol containing where te result should be sent!

here is the main patch

guilla/colorPicker(https://github.com/HenriAugusto/easyflow/raw/master/wikiFiles/ColorPicker.png)

The routine that initialize the scalars is on the right. The [pd initialize] simply clears the data storing subpatch then send a [traverse( message to [pointer]. The rest, as you can see on the main patch:

  1. Gets an index (with [easyflow/for])
  2. send that index to $0-rgbMaker along with the symbol $0-rgbCreate
  3. use the index to calculate the x and y positions of that scalar

Now let's see what happens inside [pd rgbMaker]

colorPickerRgbMaker.png

First the [send] object is set to target $0-rgbCreate (in green on the main patch). Then the index is sent to get the right color for that scalar and finally this color is sent to $0-rgbCreate.

So actually our initializing logic would be

  1. Gets an index (with [easyflow/for])
  2. send that index to $0-rgbMaker along with the symbol $0-rgbCreate
    • a) set the [send] object to deliver the color to $0-rgbCreate
    • b) calculate and deliver the color
  3. use the index to calculate the x and y positions of that scalar

This is our initializing logic. But the subpatch that updates the colors when the hue slider is changed also needs to use [pd rgbMaker]. Here is [pd update]

colorPickerUpdate.png

What it does? Iterates through the scalars. For each, find it's index and send the index packed with $0-rgbUpdater to [pd rgbMaker]. Which in turn sends the result to back to $0-rgbUpdater and the code goes to the next scalar.

Not complicated but not so simple. It's not obvious just by looking that we are using a variable wireless connection. For that purpose i like to add a triangle besides the part of the code that sends the symbol that defines where the information is going to be sent.

Look in the main patch. As you see the green triangle besides [list append $0-rgbCreate] you can see it will trigger information being sent to $0-rgbCreate (green).

The same goes for [list append $0-rgbUpdater] and the yellow triangle.

And still if you look besides the subpatches [pd Update] and [pd rgbMaker] you will see those triangles too to let you know that there are either variable sends or receives there.

And finally note there is one triangle besides the [send] object for each send/receive name it will use.

This way your variable wireless connection become evident in your code.


Prev: Color Highlighting with easyflow ‐ local connections

Next: Color Highlighting with easyflow ‐ the abstractions