bach.eval-while-for-in-loop: as clause with multiplication

Discussions, advice, bug reports and much more about the "bach" environment.
Post Reply
sydy
Posts: 155
Joined: Tue Mar 21, 2017 1:34 pm

bach.eval-while-for-in-loop: as clause with multiplication

Post by sydy » Thu Nov 28, 2019 9:05 pm

Hy,

I tried to do a little while loop with a for loop. My goal is simple. I have a central note ($central) and from this note I create a scale defined by a $pattern.
I loop from $central "upwards" till $end by adding the values to $scale.
Then I loop from $central "downwards", same thing but by subtraction.

bach.eval $central = $x1 ; ## central note
$pattern = $x2 ; ## pattern for scale
$scale = $central ; ## initiate scale by central note
$base = $x3; ## Lowest possible note
$end = $x4 ; ## highest possible note
while $scale:-1 < $end do for $i in $pattern as ( $scale:-1 < $end ) do $scale _= $scale:-1 + ($i*100) ; ## looping upwards
while $scale:-1 > $base do for $i in $pattern as ( $scale:-1 > $base ) do $scale _= $scale:-1 - ($i*100) ; ## looping downwards
sort($scale) ## sorting the scale from low to high.

But in order to respect the boundaries (values of $base and $end) I need the as clause in my for loops. (As you can see in the copy compressed the first note of the output is smaller than $base and the highest might be higher if I change the pattern.)
Strangely I can't do the following thing (while loop is hanging):

while $scale:-1 < $end do for $i in $pattern as ( $scale:-1 < $end-($i*100) ) do $scale _= $scale:-1 + ($i*100) ;
while $scale:-1 > $base do for $i in $pattern as ( $scale:-1 < $base+($i*100) ) do $scale _= $scale:-1 - ($i*100) ;

Couldn't figure out what I'm doing wrong or why this wouldn't possible.

Thanks a lot in advance.
m


<pre><code>
----------begin_max5_patcher----------
799.3ocuX0taaBCE82vSgEJ+ncKIx13Py5V2KxZUjA7ZcEXhLNoYppu6yXCM
ePfPZbahDQ95Kbx4dN9Zm7puWPbwFVY.3Vve.ddu564YBUEvqdrWPNcSRFsz
jVP7JkpPDL1N0RpJ4It3wERVhx9XBilBGClfqthIMWAOTeGhU4bQFSYdZnsA
KVoNLJO0fXQ7ySh1BnjlyTL4BlfFmwpx.VOm8Qn92Rl8aRPLU7X.3gpYey2u
5x3AxRA6EMrM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