[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Re: badly needing refactoring



If you check out the Ctk Quark, I have a number of classes for PitchClass and PitchCollection, and one of the features of PitchCollection is called filterKeynum, that does what you are trying to do. I remember spending quite a bit of time on getting that to work... maybe the method will help you figure out what you need to do, or maybe it will even work for you.

Best,

Josh

On Dec 13, 2007, at 2:06 AM, Dan Stowell wrote:

You need curly brackets around what your while statement is checking.

while(pitches[inPitch - downShift % 12] == 0, {downShift = downShift + 1});

should be

while({pitches[inPitch - downShift % 12] == 0}, {downShift = downShift + 1});

Remember how important *functions* are in supercollider. In the second
version, {pitches[inPitch - downShift % 12] == 0} is a function  -
that's how it can be evaluated again and again. If it's not a
function, it gets evaluated once and never tested again so the loop
never terminates.

Dan



2007/12/13, Greg Sabo <gregsabo@xxxxxxxxx>:
Just to make this clear, even this simplified version crashes:

var downShift = 0;
var inPitch = 61;
var pitches = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

while(pitches[inPitch - downShift % 12] == 0, {downShift = downShift + 1});
downShift.postln



On Dec 13, 2007 2:26 AM, Greg Sabo <gregsabo@xxxxxxxxx> wrote:
Wow, this function should be ungodly simple, but it always hangs...why?

This is in a PitchClassSet Class, the pitches are represented by an array
of 0s and 1s. (1 means that pitch is present)
The user passes an midi note value and the function should return the
nearest pitch that is present in the PC set.
the .isEmpty function does as expected...if the PC set is empty then it
won't be able to find the
nearest present value, of course.
What's wrong with my code?
Thanks!

   findNearest { arg inPitch;
       var upShift = 0;
       var downShift = 0;

       if(this.isEmpty, {^inPitch});
while(pitches[inPitch + upShift % 12] != 1, {upShift = upShift +
1});
       while(pitches[inPitch - downShift % 12] != 1, {downShift =
downShift + 1});
if(upShift > downShift, {^(inPitch - downShift)}, {^(inPitch +
upShift)});
   }



_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users




--
http://www.mcld.co.uk
________________________

******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own interpretation of how modern society is structured: whether actively or passively, consciously or unconsciously, he makes choices in this regard. He may be conservative or he may subject himself to continual renewal; or he may strive for a revolutionary, historical or social palingenesis." - Luigi Nono
*/