FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

chuck update

On-the-fly Programming

On-the-fly programming

by Adam Tindale

Navigate to the examples folder in the ChucK distribution then run the following command:

%>chuck moe.ck
In this case, ChucK will run whatever is in moe.ck. You can replace moe.ck with the name of
another ChucK file. If this script is a just a loop that never ends then we need to stop ChucK
eventually. Simply press CTRL-C (hold control and press c). This is the ”kill process” hotkey in
the terminal.
Some first things to try is to test the concurrency (running multiple ChucK files in parallel) are
moe, larry, and curly. First, run them each individually ( run chuck on moe.ck, larry.ck, or
curly.ck as shown above). Then, run them all in parallel, like this:
%>chuck moe.ck larry.ck curly.ck
They are written to go in and out of phase with each other. Again, if any of these scripts will go
on forever then you have to use CTRL-C to halt ChucK. Give it a try.
Also try the improved versions of our little friends: larry++.ck curly++.ck moe++.ck

Two Window ChucK

Now lets roll up our sleeves a little bit and see some real ChucK power! We are going to run two window ChucK, and on-the-fly! This section will walk you through a ChucK session.

2term_600wide.png

Here is what you do: open another terminal window just like this one. In this new window type:

%>chuck --loop

This will start ChucK running. ChucK is now waiting for something to do. Go back to your original window where you are in your ChucK home. Be careful. If you type chuck test1.ck you will start a second ChucK running test1.ck. What we want to do is add a script to the ChucK that we set running in our second window. We will use the + operator to add a script to our ChucK and the - operator to remove a script.

%>chuck + test1.ck
%>chuck - 1
%>chuck test.ck
%>chuck test.ck
%>chuck test.ck

What happened? That is the power of on-the-fly programming. We added test1.ck. It was added as the first shred in our ChucK. Since we knew it was shred 1 we removed it by typing chuck - 1. Great. Next we added three copies of the same script! Isn’t that cool? You can also do this chuck + test1.ck test1.ck test1.ck How do you keep track of shreds?

You can ask ChucK how he is doing by typing chuck --status The shortcut is chuck ˆ ChucK will answer in the other window where we left him running. He will tell you what shreds there are and what their id numbers are. He will also tell you how long he has been running.

When you have had enough of ChucK you can go to the other window and use your fancy CTRL-C trick or you can type chuck - -kill in your original window.

%>chuck --kill

One Window ChucK

So you think you're pretty good? One window ChucK is only for the hardest of hardcore.1 You have been warned.

The concept is pretty similar to two window ChucK: first, you start a ChucK going, then you manage the adding and removal of scripts to it. How do you start a ChucK and get the command prompt to return, you ask? In your shell you can add an ampersand (&) after the command and that will tell the shell to run the command as a background process and give you the prompt back.

%>chuck --loop &

The rest is as it should be. You will have to be careful when writing your patches to not put too many print statements. When you print you will temporarily lose control of the prompt as the shell prints. This can be bad when are you are printing MIDI input. The same applies when you use the --status command to ChucK. It can also be fun to fight for your command line. Who will win?

Note that the "&" sytax is part of UNIX terminals like BASH, as found on Linux and OSX, and not a part of the MS Windows prompt.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.