Hey list, Basically, I want a static function that holds a tuning map in it (sort of an alternative to mtof). This (issue 1): float tuning_map[128]; Gives me: [Rational_io.ck]:line(45): non-static member 'tuning_map' used from static function... [Rational_io.ck]: ...in function 'read' and this (issue 2): static float tuning_map[128]; gives me: [Rational_io.ck]:line(16): cannot declare static non-primitive objects (yet)... [Rational_io.ck]:line(16): ...(hint: declare as ref (@) & initialize outside for now) and this (issue 3): static float @ tuning_map[128]; gives me: [Rational_io.ck]:line(16): cannot declare references (@) of primitive type 'float'... [Rational_io.ck]:line(16): ...(primitive types: 'int', 'float', 'time', 'dur') So, I'm just at an impasse. I can't figure out how to do this, because it won't let me declare things. To get around issue 2 in an earlier segment, I did: static FileIO @ tuning; new FileIO @=> tuning; which worked perfectly (tests well, too). But I can't do it with my float array because of issue 3. Any solutions? Andrew
Andrew C. Smith wrote:
static FileIO @ tuning; new FileIO @=> tuning;
This works... [.1] @=> static float tuning_map[]; Couldn't figure out how to declare an empty one, though :-( -- Atte http://atte.dk http://modlys.dk http://virb.com/atte
Andrew;
[Rational_io.ck]:line(16): cannot declare static non-primitive objects (yet)... [Rational_io.ck]:line(16): ...(hint: declare as ref (@) & initialize outside for now)
Yeah, that's a bit tricky. Have a look at this; //========================= class war { //define array static float foo[]; //fill it and return it fun static float[] bar() { for (int n; n< foo.cap(); n++) n => foo[n]; return foo; } } //initiate the array outside of the class new float[10] @=> war.foo; // test, should print "3.0000" <<< war.bar()[3] >>>; //======================== With arrays of primitives the syntax somehow becomes a bit differently from the more regular static Event @ my_event; ...and we have to define them as normal except not set the length, the length will be set at initiation, which seems somewhat logical considering the nature of the issue but it took me a while to figure it out as well. We might consider having some examples in the /examples/ dir to illustrate this kind of thing as it leads to a lot of questions. yours, Kas.
Kas,
Thanks, that works perfectly. How does setting the length at
initialization make logical sense? I mean that in a curious, not a
critical way. I'm just not sure what the nature of the issue is,
because it seems like declaring a single primitive is the same as
declaring 128 of them, right? (clearly wrong).
And anyway, who needs examples when you have a list? Think of all the
people we would never meet (figuratively) in a world of perfect
documentation.
David: I like what you're doing there, and I've done something like
that in the past. My goal for this project is to have a global static
scale so that I can have one shred repeating some figure, then have
its intonation changed by another shred. Right now it's using FileIO
to read in tunings from outside, so that I can add new tuning options
without re-compiling the class (since you can only spork a public
class once per VM load). Still pretty theoretical, but I needed
something better and more flexible than this:
http://www.andrewchristophersmith.com/machines/chuck/scalar.ck
2009/9/15 Kassen
Andrew;
[Rational_io.ck]:line(16): cannot declare static non-primitive objects (yet)... [Rational_io.ck]:line(16): ...(hint: declare as ref (@) & initialize outside for now)
Yeah, that's a bit tricky. Have a look at this; //========================= class war { //define array static float foo[];
//fill it and return it fun static float[] bar() { for (int n; n< foo.cap(); n++) n => foo[n];
return foo; } }
//initiate the array outside of the class new float[10] @=> war.foo;
// test, should print "3.0000" <<< war.bar()[3] >>>; //========================
With arrays of primitives the syntax somehow becomes a bit differently from the more regular
static Event @ my_event;
...and we have to define them as normal except not set the length, the length will be set at initiation, which seems somewhat logical considering the nature of the issue but it took me a while to figure it out as well.
We might consider having some examples in the /examples/ dir to illustrate this kind of thing as it leads to a lot of questions.
yours, Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Andrew,
Thanks, that works perfectly. How does setting the length at initialization make logical sense? I mean that in a curious, not a critical way. I'm just not sure what the nature of the issue is, because it seems like declaring a single primitive is the same as declaring 128 of them, right? (clearly wrong).
Yes, in the case of primitives. However arrays are objects and i think it's the object that needs to be initialised. Remember that instead of floats we might have a array of "fozzbobs" where a "fozzbob" is some class that consists of 10k lines. I think ChucK treats those as more or less the same here. I agree that it feels a bit "unfair" here but remember that a array of floats is more than just a series of primitives. You also get .cap(), .size(), you can append to it, etc. It's a real object.
And anyway, who needs examples when you have a list? Think of all the people we would never meet (figuratively) in a world of perfect documentation.
Well, now you had to wait for a answer for me to get round to "morning coffee", that's one side. I think another is that not all users are on the list and that perhaps some are too shy/modest to email questions. I'm not sure why that is but I suspect it's so. For a third reason; this is just a simple trick to get around the issue, it's not very exciting. I'd rather stuff stuff like that in the examples dir so we could get round to exciting things like how, when and why we would actually do things like this. Yours, Kas.
Well, now you had to wait for a answer for me to get round to "morning coffee", that's one side.
Yes, but on the plus side, I got to sleep, which I somehow can only do
when I hit an intractable problem.
The object thing makes much more sense now. I tell all my friends to
join the chuck list, and I think they did but I've never seen one ask
a question. I think they were angry about overloading the => operator
or something. Who knows why. Anyway, I'll ask something again around 1
a.m. tonight probably, so get ready. Thanks again,
Andrew
2009/9/15 Kassen
Andrew,
Thanks, that works perfectly. How does setting the length at initialization make logical sense? I mean that in a curious, not a critical way. I'm just not sure what the nature of the issue is, because it seems like declaring a single primitive is the same as declaring 128 of them, right? (clearly wrong).
Yes, in the case of primitives. However arrays are objects and i think it's the object that needs to be initialised. Remember that instead of floats we might have a array of "fozzbobs" where a "fozzbob" is some class that consists of 10k lines. I think ChucK treats those as more or less the same here.
I agree that it feels a bit "unfair" here but remember that a array of floats is more than just a series of primitives. You also get .cap(), .size(), you can append to it, etc. It's a real object.
And anyway, who needs examples when you have a list? Think of all the people we would never meet (figuratively) in a world of perfect documentation.
Well, now you had to wait for a answer for me to get round to "morning coffee", that's one side. I think another is that not all users are on the list and that perhaps some are too shy/modest to email questions. I'm not sure why that is but I suspect it's so. For a third reason; this is just a simple trick to get around the issue, it's not very exciting. I'd rather stuff stuff like that in the examples dir so we could get round to exciting things like how, when and why we would actually do things like this.
Yours, Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Andrew,
Yes, but on the plus side, I got to sleep, which I somehow can only do when I hit an intractable problem.
Ah, well, for a modest fee a slower response time could be arranged as well. Think of the time you will be able to use to digest dinner, perhaps even see your family and friends! Act now! :-p
The object thing makes much more sense now. I tell all my friends to join the chuck list, and I think they did but I've never seen one ask a question. I think they were angry about overloading the => operator or something. Who knows why. Anyway, I'll ask something again around 1 a.m. tonight probably, so get ready. Thanks again,
They were angry about the operator overloading? I never saw anyone respond like that. Actually I find it quite remarkable how people that I explain ChucK to tend to grasp quite intuitively what's going on as all the uses seem conceptually related. In fact people often seem to desire *more* overloading as the concept seems so general. Admittedly I never use the word "overloading" in those situations to avoid overloading my audience with information, they typically are more interested in working with sound than in being able to talk to CS vocabulary. Oh, well. If your friends would define this; fun void wait (dur arg) { arg => now;} ...And a few more related functions (for stuff like setting primitive array elements), then only use the => operator like a inter-UGen patch-cable I think they will be able to get by with normal C-style function notation most of the time for nearly all common tasks. It would probably look less readable but I think you could. It seems a bit of a non-issue to me, I've been advocating enabling users to further overload the => operator, but I'm cartainly open to hearing about any issues that this overloading might lead to. Yours, Kas.
2009/9/15 Andrew C. Smith
Basically, I want a static function that holds a tuning map in it (sort of an alternative to mtof).
For what it's worth, I created a Pitchmap class to abstract around this problem, but I also wanted to have a slightly more complex mapping from notes to frequencies. I then sub-classed Pitchmap to have ArrayPitchmap which I use for certain funky Just and Indian intonations. As Below public class Pitchmap { fun float freq(int spec[]) { return Math.pow(2, spec[0] / 1200.0); }} public class ArrayPitchmap extends Pitchmap { 440 => float root; float notes[]; fun float freq(int spec[]) { 0 => int octave; if(spec[0] > notes.size()) return root; if(spec.size() >= 2) spec[1] => octave; return root * Math.pow(2.0, octave) * notes[spec[0]]; }} ArrayPitchmap Just2357; [1.0, 0.14285714285714285, 0.2, 0.2857142857142857, 0.3333333333333333, 0.4, 0.42857142857142855, 0.5, 0.5833333333333334, 0.6, 0.625, 0.6666666666666666, 0.7, 0.7142857142857143, 0.75, 0.8333333333333334, 0.875 ] @=> Just2357.notes; ArrayPitchmap MaGrama; [1.40625, 1.5, 1.6666666666666667, 1.875, 2.0, 2.1333333333333333, 2.25, 2.5, 2.6666666666666665 ] @=> MaGrama.notes; david rush -- GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
participants (4)
-
Andrew C. Smith
-
Atte Andre Jensen
-
David Rush
-
Kassen