Bob ... i used my kludge which defines some bounds and tests for it... but your idea of stuffing that into a seperate black box as golden in that it made me think of the problem as input --> doit --> result. and made my loops simpler and easier to read... and i use that same gap making typing thing in several loops, so encapsulating that meant that i could make it general purpose, and re-usable and i can add to it later more easily.
Thanks for that suggestion. I ended up with this: # if the flag (random float) is lower than our percentage of rest, we pick # a rest duration and add that to our start time creating a gap between events. def make_rest(event, lowerbound, upperbound, start, rest_percent): restflag = random.random() if (restflag < rest_percent): # This kludge makes sure our last event does not get a rest, and we can # prevent the first few events from getting rests as well to insure # our transitions between sections are seamless & sufficiently busy # NOTE LOWER bound is included if event >= lowerbound and event < upperbound: rest_dur = windex(rest) print "\n", "<>-" * 8, "[ rest : ", rest_dur, "]", "-<>" * 8, "\n" start = start + rest_dur else: print "[bang]" # debug return start then in the master bedroom i just call it: startime = foo.make_rest(event, 1, upperbound, startime, rest_percent) cheers, kevin On Apr 25, 2006, at 11:27 PM, Bob Gailer wrote: > How about separating the body into 2 functions, calling both for > all but the last list element, then calling just the first for the > last element: > : > def step1(sample): > global incr > splt = os.path.split(sample) > rtinput(sample) > loc = random.random() > dur = DUR() > STEREO(startime, inskip, dur, amp, loc) > print "event no. %d @ %.2f (dur: %.2f, end: %.2f) --> sf: %s : > [flag: %.2f]" % (event, startime, dur, startime+dur, splt[1], dry) > incr = (dur * duty_factor) + kptools.windex(kptools.durations) > startime = startime + incr > > def rest(): > global event > restflag = random.random() > if (restflag < rest_percent): > rest = kptools.windex(kptools.rest) > print "\n", "<>-" * 8, "[ rest : ", rest, "]", "-<>" * 8, "\n" > startime = startime + rest > event = event + 1 > > for sample in smpl_lst[:-1]: > step1(sample) > rest() > step1(smpl_lst[-1]) > > > so what i am trying to do its skip that >> if (restflag < rest_percent): >> >> biz on the last item if we are on our last sequence item. The >> rests (which are random) is for padding between events >> and since we have just played our last event, we don't want any >> extra padding so that our next call of the loop >> starts at the proper time (just at the last event of this loop is >> over). The loop function will calculate the >> next start time, and return it so that we can use it as the start >> time argument for our next call of the loop. >> >> so if i want to play 7 items i might get something like: >> >> loop_call_01: >> item_1 >> item_2 >> rest >> item_3 >> rest >> item_4 >> item_5 >> item_6 >> rest >> item_7 (but we don't want any rest here ever! cause we might want >> our next loop to start w/o any pause) >> > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor