I posted this to the puredata.hurleur.com forum, but didn't get any responses.
I'm brand new to pd.
I'd like to make a template that represents the midi channel by color. So I'd like to change the channel number to one between 0-999, say
[channel]
|
[* 171]
|
[mod 1000]
|
[drawpolygon $1 .....]
The problem is, how do I call the channel field of the struct from inside the template? I know I can call channel directly inside [drawpolygon ....], but then I can't do any arithmetic on it before using it as a color.
I know I could define a new field in the struct, say clr, set up an abstraction to define it correctly from channel, then call clr inside [drawpolygon ....], but that seems ugly.
hi andrew, welcome to the pd-list you want to use data structures to draw shapes, which is maybe a bit of overkill for what you want to do, but I am not sure what exactly you want to do, so I will just explain... the drawpolygon itself does not accept input like you patched it together. it uses special data that has to be entered in a special way. have a look at the example patches for data structures, esp. 3.setting. so what you need to do is:
create data, 2. change data
to create data use "append".
set a pointer to the window where you want to create the data
[traverse pd-dw1, bang(
|
[pointer]
\ (connect to right inlet)
[append temp1 col]
dw1 is the patchwindow where you want to draw. this can be a subwindow or the patch itself [traverse pd-mypatch.pd(. temp1 is the name of your struct and col is one variable of the struct (see below). and then create one dataset by sending one single message to the left inlet of append
[900( | [append temp1 col]
if you have a struct and a drawpolygon, this will draw the polygon. [struct temp1 float col] [drawpolygon col 1 20 20 60 20 40 40 20 20] which would draw a polygon with points at 20 20, 60 20 and 40 40, line thickness 1 and color 900, which is red.
once the data is created it will be stored with your patch, and you don't have to repeat that again., you just change the color via set. but you must set a pointer message again and also a "next" message!
[traverse pd-dw1, next(
|
[pointer]
\ (connect to right inlet)
[set temp1 col]
finally you can connect a number box to the left inlet and change the color of your polygon. [channel] | [* 171] | [mod 1000] | [set temp1 col]
that's it. I attach a patch called ds1.pd. marius.
Andrew Dabrowski wrote:
I posted this to the puredata.hurleur.com forum, but didn't get any responses.
I'm brand new to pd.
I'd like to make a template that represents the midi channel by color. So I'd like to change the channel number to one between 0-999, say
[channel] | [* 171] | [mod 1000] | [drawpolygon $1 .....]
The problem is, how do I call the channel field of the struct from inside the template? I know I can call channel directly inside [drawpolygon ....], but then I can't do any arithmetic on it before using it as a color.
I know I could define a new field in the struct, say clr, set up an abstraction to define it correctly from channel, then call clr inside [drawpolygon ....], but that seems ugly.
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
#N canvas 654 396 692 341 10; #X obj 443 132 pointer; #X obj 403 162 set temp1 col; #X obj 44 211 struct temp1 float col; #X msg 580 82 next; #X floatatom 399 137 5 0 0 0 - - -; #X obj 162 146 append temp1 col; #X msg 445 82 traverse pd-ds1.pd; #X obj 44 235 drawpolygon col 1 20 20 60 20 40 40 20 20; #X msg 213 60 traverse pd-ds1.pd; #X msg 340 62 bang; #X obj 213 88 pointer; #X text 202 33 1; #X text 338 32 2; #X text 171 100 3; #X text 462 57 4; #X msg 162 123 900; #X text 584 58 5; #X text 397 113 6; #X connect 0 0 1 1; #X connect 3 0 0 0; #X connect 4 0 1 0; #X connect 6 0 0 0; #X connect 8 0 10 0; #X connect 9 0 10 0; #X connect 10 0 5 1; #X connect 15 0 5 0;