Hi, I want to make a library of functions that I can call from any chuck script. If I put those functions in one file, how do I access them from another? It would be great if I could make them into a new namespace, akin to Std.X or Math.X (I am using miniAudicle 0.2.0, not command line.) (I checked the language specification for the words "include" and "import" and found nothing relevant.) Thanks, George (I am new to chuck, but not to computer programming, nor computer audio.) PS is there a popular/built-in solution for making exponentially distributed, normally distributed, etc random variables? PPS If not, I'd be happy to share my work - is there a common way for people to share code like this?
George Locke wrote:
I want to make a library of functions that I can call from any chuck script. If I put those functions in one file, how do I access them from another? It would be great if I could make them into a new namespace, akin to Std.X or Math.X (I am using miniAudicle 0.2.0, not command line.)
(I checked the language specification for the words "include" and "import" and found nothing relevant.)
Machine.add("filename.ck"); loads filename.ck on a separate shred. There is no include/import or namespace mechanism in ChucK.
PS is there a popular/built-in solution for making exponentially distributed, normally distributed, etc random variables?
No. I would love to see such. I ported this just recently but haven't tested it yet // // adapted from org.apache.commmons.math3.random.AbstractRandomGenerator, // which implements the Polar Method, due to G.E.P. Box, M.E. Muller and G. Marsaglia, // as described in D. Knuth, _The Art of Computer Programming_, 3.4.1C. // fun static float nextGaussian() { 0.0 => float v1; 0.0 => float v2; 1.0 => float s; while (s >= 1.0) { 2.0 * Std.randf() - 1.0 => v1; 2.0 * Std.randf() - 1.0 => v2; s = v1 * v1 + v2 * v2; } if (s > 0.0) { s = Math.sqrt(-2.0 * Math.log(s)/s); } v2 * s => cached; return v1 * s; }
PPS If not, I'd be happy to share my work - is there a common way for people to share code like this?
This mailing list, or the ChucK wiki http://wiki.cs.princeton.edu/index.php/ChucK or e.g. github https://github.com/heuermh/lick michael
use Machine.add. The docs aren't descriptive, but when you Machine.add a ChucK program, any classes it defines will be available in the runtime for any future chuck programs you add to the VM. The ChucK compiler is single-pass and has no concept of make files or a build system, though, so if you want one file to include another file, you have to have a third file that defines the order to add the files to the VM. http://chuck.cs.princeton.edu/doc/language/spork.html e.g., here's an example of a ChucK program that I invoke that imports a bunch of other utility files: https://github.com/jordanorelli/wii-chuck-synth/blob/master/resin.ck if you look in resin_run.ck, I utilize some of the stuff that is imported in resin.ck. resin_run.ck will fail to compile if those other files aren't already loaded into the VM, so it's resin that I run from the command line. On Mar 5, 2012, at 5:41 PM, George Locke wrote:
Hi,
I want to make a library of functions that I can call from any chuck script. If I put those functions in one file, how do I access them from another? It would be great if I could make them into a new namespace, akin to Std.X or Math.X (I am using miniAudicle 0.2.0, not command line.)
(I checked the language specification for the words "include" and "import" and found nothing relevant.)
Thanks, George
(I am new to chuck, but not to computer programming, nor computer audio.)
PS is there a popular/built-in solution for making exponentially distributed, normally distributed, etc random variables?
PPS If not, I'd be happy to share my work - is there a common way for people to share code like this?
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On Mon, Mar 05, 2012 at 05:41:47PM -0500, George Locke wrote:
Hi,
Hey George!
I want to make a library of functions that I can call from any chuck script. If I put those functions in one file, how do I access them from another? It would be great if I could make them into a new namespace, akin to Std.X or Math.X (I am using miniAudicle 0.2.0, not command line.)
Right now I'd say make a public class called -say- "Lib" and outfit it with static member functions that would be your "x". Then you'd add it using Machine.add(file_with_class.ck) at the start of your session. That way Lib.x() might be exactly equivalent to Math.x() in usage. The downside is the way of loading it, but after that it'd be essentially identical in usage.
(I checked the language specification for the words "include" and "import" and found nothing relevant.)
Yes, clearly the above is a workaround. People were working on exactly this functionality for library style functions. It hasn't been very busy on that front for a while, but recently things are picking up a bit again, I think.
PS is there a popular/built-in solution for making exponentially distributed, normally distributed, etc random variables?
There was something like that, I seem to remember, but I can't remember who did it. Clearly good tools for randomness would be a good idea, maybe even as a build-in library as randomness is quite fundamental to computer-music and synthesis and just having white-noise is a bit limited. We used to collect stuff at the Princeton CS wiki, where (generously) non-students (or students of other insitutions) could also have accounts, then there was a wave of spam and new accounts can no longer be casually created.
PPS If not, I'd be happy to share my work - is there a common way for people to share code like this?
Erm... anyone? This sounds worthwhile. Welcome on board! Kas.
Hi Folks,
On Mon, Mar 5, 2012 at 5:57 PM, Kassen
(I checked the language specification for the words "include" and "import" and found nothing relevant.)
Yes, clearly the above is a workaround. People were working on exactly this functionality for library style functions. It hasn't been very busy on that front for a while, but recently things are picking up a bit again, I think.
Can you elaborate on this, Kas? Are there offline discussions about certain features for the next release? -Mike
PS is there a popular/built-in solution for making exponentially distributed, normally distributed, etc random variables?
There was something like that, I seem to remember, but I can't remember who did it. Clearly good tools for randomness would be a good idea, maybe even as a build-in library as randomness is quite fundamental to computer-music and synthesis and just having white-noise is a bit limited. We used to collect stuff at the Princeton CS wiki, where (generously) non-students (or students of other insitutions) could also have accounts, then there was a wave of spam and new accounts can no longer be casually created.
PPS If not, I'd be happy to share my work - is there a common way for people to share code like this?
Erm... anyone? This sounds worthwhile.
Welcome on board! Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On Mon, Mar 05, 2012 at 06:04:02PM -0500, mike clemow wrote:
Can you elaborate on this, Kas? Are there offline discussions about certain features for the next release?
Oh, sorry, I meant the general vibe of "activeness" and Spencer talking of SVN updates and so on. Not particularly on the importing of library-like classes. kas.
Thanks for all the quick responses!! This is very helpful.
- George
On Mon, Mar 5, 2012 at 6:09 PM, Kassen
On Mon, Mar 05, 2012 at 06:04:02PM -0500, mike clemow wrote:
Can you elaborate on this, Kas? Are there offline discussions about certain features for the next release?
Oh, sorry, I meant the general vibe of "activeness" and Spencer talking of SVN updates and so on. Not particularly on the importing of library-like classes.
kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
George:
I love github as a shared repository of code. To answer your first
questions -- if you have the stomach -- look in:
https://github.com/rdpoor/chuck_performance_setup
The _loadup.ck file loads all the requisite files in the proper order,
and finally calls:
Machine.add(HOME + "_main.ck");
which has the main performance loop. _main's last line is:
1::week => now;
so the main shred runs for a week -- the PatchManager (q.v.) sporks
and kills patch-specific shreds as required.
As for gaussian random numbers, look up
http://en.wikipedia.org/wiki/Box-Muller_transform
... any random number generator plus a couple of trig calls does the trick.
- Rob
2012/3/5 George Locke
Hi,
I want to make a library of functions that I can call from any chuck script. If I put those functions in one file, how do I access them from another? It would be great if I could make them into a new namespace, akin to Std.X or Math.X (I am using miniAudicle 0.2.0, not command line.)
(I checked the language specification for the words "include" and "import" and found nothing relevant.)
Thanks, George
(I am new to chuck, but not to computer programming, nor computer audio.)
PS is there a popular/built-in solution for making exponentially distributed, normally distributed, etc random variables?
PPS If not, I'd be happy to share my work - is there a common way for people to share code like this?
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (6)
-
George Locke
-
Jordan Orelli
-
Kassen
-
Michael Heuer
-
mike clemow
-
Robert Poor