Forums > MaxMSP

behavior of counters

August 18, 2008 | 12:48 pm

Hi,

I’ve created a little "counterlock" object to be used specifically with multislider. For this particular case, I want to start at 0, first bang outputs 1, etc until it counts up to maximum, turns around and finishes by outputting 0. I have what I think should do the trick (and in most cases does), though sometimes it behaves strangely. Occasionally it counts down from 1 to 0 (instead of up from 1), sometimes it doesn’t unlock with the loadbang, sometimes other problems occur. What is wrong with this patch?

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#N vpatcher 15 55 126 242;
#P window setfont "Sans Serif" 9.;
#P newex 32 63 27 9109513 i $1;
#P newex 32 85 27 9109513 + 1;
#P message 32 107 34 9109513 set $1;
#P inlet 32 43 15 0;
#P outlet 32 129 15 0;
#P connect 1 0 4 0;
#P connect 4 0 3 0;
#P connect 3 0 2 0;
#P connect 2 0 0 0;
#P pop;
#P newobj 107 93 58 9109513 p set-to-min;
#B color 5;
#P newex 100 164 28 9109513 sel 1;
#N comlet bang at max;
#P outlet 100 187 15 0;
#N vpatcher 15 55 125 252;
#P window setfont "Sans Serif" 9.;
#P newex 18 29 45 9109513 loadbang;
#P message 18 119 47 9109513 set $2 $1;
#P newex 18 97 28 9109513 pack;
#P newex 36 75 27 9109513 + 1;
#P newex 18 51 27 9109513 i $1;
#P outlet 18 141 15 0;
#P connect 5 0 1 0;
#P connect 1 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 0 0;
#P connect 1 0 2 0;
#P connect 2 0 3 1;
#P pop;
#P newobj 56 164 42 9109513 p match;
#B color 5;
#P newex 48 209 19 9109513 t 0;
#P newex 48 187 50 9109513 match 1 0;
#P newex 7 69 27 9109513 == 0;
#N comlet count out;
#P outlet 38 235 15 0;
#N comlet set max;
#P inlet 130 116 15 0;
#N comlet reset to min;
#P inlet 107 63 15 0;
#N comlet unlock;
#P inlet 84 44 15 0;
#N comlet bangs to count;
#P inlet 55 27 15 0;
#P window linecount 3;
#P comment 12 290 163 9109513 First and second argument are min and max. Third argument is initial state (1 locks , 0 unlocked is default);
#P window linecount 1;
#P comment 146 116 44 9109513 set max;
#P comment 123 64 60 9109513 reset to min;
#P newex 7 47 27 9109513 i $3;
#P newex 7 25 45 9109513 loadbang;
#P newex 38 69 27 9109513 i 1;
#P toggle 38 97 15 0;
#P newex 38 115 27 9109513 gate;
#N counter 2 $1 $2;
#X flags 0 0;
#P newobj 38 141 104 9109513 counter 2 $1 $2;
#P comment 100 44 41 9109513 unlock;
#P comment 71 27 75 9109513 bangs to count;
#P window linecount 3;
#P comment 12 249 163 9109513 This patch counts up to max , then down to min , then stops. Must be unlocked to count again.;
#P connect 15 0 3 4;
#P connect 14 0 23 0;
#P connect 13 0 6 0;
#P connect 13 0 23 0;
#P connect 22 0 21 0;
#P connect 3 2 22 0;
#P connect 12 0 4 1;
#P connect 18 0 19 0;
#P connect 3 0 16 0;
#P connect 3 0 18 0;
#P connect 20 0 18 0;
#P connect 4 0 3 0;
#P fasten 23 0 3 0 112 137 43 137;
#P connect 5 0 4 0;
#P fasten 19 0 5 0 53 230 32 230 32 93 43 93;
#P connect 6 0 5 0;
#P fasten 17 0 5 0 12 91 43 91;
#P connect 8 0 17 0;
#P connect 7 0 8 0;
#P window clipboard copycount 24;


Viewing 1 post (of 1 total)