Author |
Message |
jbum
Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Thu Nov 02, 2006 4:23 pm Post subject:
Array of StkInstrument Subject description: How to maintain a list of indexed ugens? |
|
|
I'm trying to make a script which references each player via an Index from an array of assorted ugens, but ChucK is crashing. I need to
be able to control an assortment of diverse ugens by playerNumber...
Any ideas?
Code: |
// THIS CODE DOESN"T WORK
StkInstrument players[];
StifKarp v1 => players[0];
Wurley v2 => players[1];
for (0 => int i; i < 2; ++i)
{
players[i] => dac;
440+i*100 => players[i].freq;
1 => players[i].noteOn;
}
5::second => now;
|
_________________ <a href="http://www.krazydad.com/">krazydad.com</a> |
|
Back to top
|
|
|
ge
Joined: Aug 13, 2006 Posts: 108 Location: Palo Alto, CA
|
Posted: Thu Nov 02, 2006 4:29 pm Post subject:
Re: Array of StkInstrument Subject description: How to maintain a list of indexed ugens? |
|
|
I think the problem is the array needs be instantiated, and @=> should be used to do the assignment. (=> will attempt to connect). The crashing is definitely a bug. Gotta track that down.
Try the following:
Code: | StkInstrument players[2];
StifKarp v1 @=> players[0];
Wurley v2 @=> players[1];
for (0 => int i; i < players.cap(); ++i)
{
players[i] => dac;
440+i*100 => players[i].freq;
1 => players[i].noteOn;
}
5::second => now; |
|
|
Back to top
|
|
|
ge
Joined: Aug 13, 2006 Posts: 108 Location: Palo Alto, CA
|
Posted: Thu Nov 02, 2006 4:29 pm Post subject:
|
|
|
Here is a slightly different version:
Code: | [new StifKarp, new Wurley] @=> StkInstrument players[];
for (0 => int i; i < players.cap(); ++i)
{
players[i] => dac;
440+i*100 => players[i].freq;
1 => players[i].noteOn;
}
5::second => now; |
|
|
Back to top
|
|
|
jbum
Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Thu Nov 02, 2006 4:36 pm Post subject:
|
|
|
Beautiful, thanks Ge! _________________ <a href="http://www.krazydad.com/">krazydad.com</a> |
|
Back to top
|
|
|
ge
Joined: Aug 13, 2006 Posts: 108 Location: Palo Alto, CA
|
Posted: Thu Nov 02, 2006 4:38 pm Post subject:
|
|
|
jbum wrote: | Beautiful, thanks Ge! |
You're welcome, Jim! Good to see you here! |
|
Back to top
|
|
|
majutsu
Joined: Jun 18, 2006 Posts: 151 Location: New York
Audio files: 1
|
Posted: Thu Nov 02, 2006 5:06 pm Post subject:
|
|
|
this IS very cool
slick tip
thanks
_________________ All phenomena are atoms in association and dissociation. |
|
Back to top
|
|
|
jbum
Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Thu Nov 02, 2006 5:10 pm Post subject:
|
|
|
Here are two versions of Terry Riley's "In C".
This first version uses a new instrument (StifKarp) for each spork, and seems to work okay...
The second version is using the array of StkInstuments and starts out okay, but then runs into some audio issues...
UPDATE: I changed the event data from floats to ints.
UPDATE: I modified the repeatPhrase function to reduce the number of sporks.
Code: |
// ChucK Performance of Terry Riley's 'In C' (single instrument version)
//
// In this famous canon by composer Terry Riley, each performer is given the
// same set of phrases.
//
// Each performer repeats each phrase a random number of times before moving
// on to the next phrase.
//
// A single player keeps time by playing a pulse beat
// When all the players are done, the pulse continues for a while, and then stops.
//
// ChucK port 11/2006 -- Jim Bumgardner
// Original Perl Program 9/2004 -- Jim Bumgardner
// With these settings, ChucK produces about 14 minutes of music.
// A more typical 'In C' performance is 20-60 minutes. Increase the
// min/max repetitions to achieve this...
//
240 => float bps; // ticks/second
4 => int minRepeats; // minimum times to repeat a phrase
10 => int maxRepeats; // maximum times to repeat a phrase
/* [new StifKarp,
new Wurley, s
new StifKarp,
new StifKarp,
new StifKarp] @=> StkInstrument players[];
players.cap() => int nbrPlayers;
*/
8 => int nbrPlayers;
Math.log(nbrPlayers)/nbrPlayers => float mainGain;
[
// midi pitch, vol, start-ticks, dur-ticks
[72, 32, 0, 48],
[72, 32, 48, 48],
[72, 32, 96, 48],
[72, 32, 144, 48],
[72, 32, 192, 48],
[72, 32, 240, 48],
[72, 32, 288, 48],
[72, 32, 336, 48]
] @=> int pulsePhrase[][];
// Phrases transcribed from 'In C' by Terry Riley
[
[
// midi pitch, vol, start-ticks, dur-ticks
[0, 63, 0, 96]
],
[
[60, 63, 0, 6],
[64, 63, 6, 90],
[60, 63, 96, 6],
[64, 63, 102, 90],
[60, 63, 192, 6],
[64, 63, 198, 90]
],
[
[60, 63, 0, 6],
[64, 63, 6, 42],
[65, 63, 48, 48],
[64, 63, 96, 96]
],
[
[0, 63, 0, 48],
[64, 63, 48, 48],
[65, 63, 96, 48],
[64, 63, 144, 48]
],
[
[0, 63, 0, 48],
[64, 63, 48, 48],
[65, 63, 96, 48],
[67, 63, 144, 48]
],
[
[64, 63, 0, 48],
[65, 63, 48, 48],
[67, 63, 96, 48],
[0, 63, 144, 48]
],
[
[72, 63, 0, 768]
],
[
[0, 63, 0, 336],
[60, 63, 336, 24],
[60, 63, 360, 24],
[60, 63, 384, 48],
[0, 63, 432, 432]
],
[
[67, 63, 0, 576],
[65, 63, 576, 768]
],
[
[71, 63, 0, 24],
[67, 63, 24, 24],
[0, 63, 48, 336]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 63, 0, 48],
[67, 63, 48, 48],
[71, 63, 96, 384],
[72, 63, 480, 96]
],
[
[71, 63, 0, 24],
[67, 63, 24, 72],
[67, 63, 96, 24],
[65, 63, 120, 24],
[67, 63, 144, 48],
[0, 63, 192, 72],
[67, 63, 264, 312]
],
[
[72, 63, 0, 384],
[71, 63, 384, 384],
[67, 63, 768, 384],
[66, 63, 1152, 384]
],
[
[67, 63, 0, 24],
[0, 63, 24, 360]
],
[
[67, 48, 0, 24],
[71, 48, 24, 24],
[72, 48, 48, 24],
[71, 48, 72, 24]
],
[
[71, 48, 0, 24],
[72, 48, 24, 24],
[71, 48, 48, 24],
[72, 48, 72, 24],
[71, 48, 96, 24],
[0, 48, 120, 24]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[64, 48, 96, 72],
[64, 48, 168, 24]
],
[
[0, 63, 0, 144],
[67, 63, 144, 144]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[55, 48, 96, 72],
[64, 48, 168, 24],
[66, 48, 192, 24],
[64, 48, 216, 24],
[66, 48, 240, 24],
[64, 48, 264, 24]
],
[
[66, 63, 0, 288]
],
[
[64, 63, 0, 144],
[64, 63, 144, 144],
[64, 63, 288, 144],
[64, 63, 432, 144],
[64, 63, 576, 144],
[66, 63, 720, 144],
[67, 63, 864, 144],
[69, 63, 1008, 144],
[71, 63, 1152, 48]
],
[
[64, 63, 0, 48],
[66, 63, 48, 144],
[66, 63, 192, 144],
[66, 63, 336, 144],
[66, 63, 480, 144],
[66, 63, 624, 144],
[67, 63, 768, 144],
[69, 63, 912, 144],
[71, 63, 1056, 96]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 144],
[67, 63, 240, 144],
[67, 63, 384, 144],
[67, 63, 528, 144],
[67, 63, 672, 144],
[69, 63, 816, 144],
[71, 63, 960, 48]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 48],
[69, 63, 144, 144],
[69, 63, 288, 144],
[69, 63, 432, 144],
[69, 63, 576, 144],
[69, 63, 720, 144],
[71, 63, 864, 144]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 48],
[69, 63, 144, 48],
[71, 63, 192, 144],
[71, 63, 336, 144],
[71, 63, 480, 144],
[71, 63, 624, 144],
[71, 63, 768, 144]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[67, 48, 96, 48],
[64, 48, 144, 24],
[67, 48, 168, 24],
[66, 48, 192, 24],
[64, 48, 216, 24],
[66, 48, 240, 24],
[64, 48, 264, 24]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[64, 48, 96, 72],
[64, 48, 168, 24]
],
[
[64, 63, 0, 288],
[67, 63, 288, 288],
[72, 63, 576, 288]
],
[
[72, 63, 0, 576]
],
[
[67, 48, 0, 24],
[65, 48, 24, 24],
[67, 48, 48, 24],
[71, 48, 72, 24],
[67, 48, 96, 24],
[71, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[65, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[65, 48, 120, 312],
[67, 48, 432, 144]
],
[
[67, 63, 0, 24],
[65, 63, 24, 24],
[0, 63, 48, 48]
],
[
[67, 48, 0, 24],
[65, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24],
[71, 48, 144, 24],
[67, 48, 168, 24],
[71, 48, 192, 24],
[67, 48, 216, 24],
[0, 48, 240, 336],
[70, 63, 576, 96],
[79, 63, 672, 288],
[81, 63, 960, 48],
[79, 63, 1008, 96],
[83, 63, 1104, 48],
[81, 63, 1152, 144],
[79, 63, 1296, 48],
[76, 63, 1344, 288],
[79, 63, 1632, 48],
[78, 63, 1680, 336],
[0, 63, 2016, 240],
[76, 63, 2256, 240],
[77, 63, 2496, 576]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24],
[65, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[72, 48, 120, 24]
],
[
[71, 48, 0, 24],
[65, 48, 24, 24]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24]
],
[
[72, 63, 0, 384],
[71, 63, 384, 384],
[69, 63, 768, 384],
[72, 63, 1152, 384]
],
[
[65, 48, 0, 96],
[64, 48, 96, 96],
[65, 48, 192, 96],
[64, 48, 288, 96],
[64, 48, 384, 48],
[64, 48, 432, 48],
[64, 48, 480, 48],
[65, 48, 528, 24],
[64, 48, 552, 24]
],
[
[77, 63, 0, 48],
[76, 63, 48, 96],
[76, 63, 144, 48],
[72, 63, 192, 96]
],
[
[74, 63, 0, 96],
[74, 63, 96, 96],
[67, 63, 192, 96]
],
[
[67, 48, 0, 24],
[74, 48, 24, 24],
[76, 48, 48, 24],
[74, 48, 72, 24],
[0, 48, 96, 48],
[67, 48, 144, 48],
[0, 48, 192, 48],
[67, 48, 240, 48],
[0, 48, 288, 48],
[67, 48, 336, 48],
[67, 48, 384, 24],
[74, 48, 408, 24],
[76, 48, 432, 24],
[74, 48, 456, 24]
],
[
[74, 63, 0, 24],
[76, 63, 24, 24],
[74, 63, 48, 48]
],
[
[67, 63, 0, 576],
[67, 63, 576, 384],
[65, 63, 960, 480]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[70, 48, 48, 24],
[67, 48, 72, 24],
[70, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[70, 48, 48, 24]
],
[
[67, 48, 0, 24],
[70, 48, 24, 24]
],
[
[70, 48, 0, 24],
[67, 48, 24, 24]
]
] @=> int phraseList[][][];
nbrPlayers => int playersIn;
1 => int pulseIsPlaying;
fun int phraseLength(int ph[][])
{
return ph[ph.cap()-1][2] + ph[ph.cap()-1][3];
}
// Base frequency for MIDI -> freq conversion
(440/32)*Math.pow(2,0.25) => float noteZero;
fun void playPhrase(int ph[][], int player, StkInstrument voc)
{
// players[player] @=> StkInstrument voc;
for (0 => int i; i < ph.cap(); ++i)
{
if (ph[i][0] > 0) {
// convert midi-note to frequency
noteZero*Math.pow(2,ph[i][0]/12.0) => voc.freq;
// convert midi-vol to gain (and randomize it a bit)
(mainGain*ph[i][1]+Std.rand2(-4,4))/127.0 => voc.gain;
}
else {
// rest
0 => voc.gain;
}
1 => voc.noteOn;
// wait til next note...
(ph[i][3]/bps)::second => now;
1 => voc.noteOff;
if (i+1 < ph.cap())
{
if ((ph[i+1][2] - ph[i][2]) > ph[i][3])
((ph[i+1][2] - (ph[i][2]+ph[i][3]))/bps)::second => now;
}
}
}
// Repeat a particular phrase N times
fun void repeatPhrase(int ph[][], int n, int player)
{
StifKarp voc => dac;
0=>voc.gain;
20=>voc.freq; // this inhibits an error message
phraseLength(ph) => float totBeats;
for (0 => int pp; pp < n; ++pp)
{
// spork ~ playPhrase(ph, player);
// (totBeats/bps)::second => now;
playPhrase(ph, player, voc);
}
}
// Performance by a single player
// play each phrase a random number of times
fun void doRileyPart(int player)
{
for (0 => int p; p < phraseList.cap(); ++p)
{
Std.rand2(minRepeats,maxRepeats) => int nTimes;
repeatPhrase(phraseList[p], nTimes, player);
}
--playersIn; // decrement player counter, so pulse knows when to stop
}
// Performance by the Pulse player
fun void doPulse()
{
do {
repeatPhrase(pulsePhrase, 1,0);
} while (playersIn > 0);
// Do a few more pulses to end the piece
repeatPhrase(pulsePhrase, 8,0);
0 => pulseIsPlaying; // Notification that we have stopped
}
// Performance by all non-pulse players
fun void doRileyParts()
{
for (1 => int p; p < nbrPlayers; ++p)
spork ~ doRileyPart(p);
}
// for (0 => int i; i < nbrPlayers; ++i)
// {
// players[i] => dac;
// }
// Start the Pulse
spork ~ doPulse();
// Let him go for a bit...
(phraseLength(pulsePhrase)*4/bps)::second => now;
// Start up all the players
doRileyParts();
// Let time elapse until the pulse stops
do {
1::second => now;
} while (pulseIsPlaying);
|
Second version follows in next post... _________________ <a href="http://www.krazydad.com/">krazydad.com</a> Last edited by jbum on Fri Nov 03, 2006 3:15 pm; edited 3 times in total |
|
Back to top
|
|
|
jbum
Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Thu Nov 02, 2006 5:10 pm Post subject:
|
|
|
Second (bugged) Version (for varied Ensemble) follows
update: I changed the event data from floats to ints.
Code: |
// ChucK Performance of Terry Riley's 'In C' (broken)
//
// In this famous canon by composer Terry Riley, each performer is given the
// same set of phrases.
//
// Each performer repeats each phrase a random number of times before moving
// on to the next phrase.
//
// A single player keeps time by playing a pulse beat
// When all the players are done, the pulse continues for a while, and then stops.
//
// ChucK port 11/2006 -- Jim Bumgardner
// Original Perl Program 9/2004 -- Jim Bumgardner
// With these settings, ChucK produces about 14 minutes of music.
// A more typical 'In C' performance is 20-60 minutes. Increase the
// min/max repetitions to achieve this...
//
240 => float bps; // ticks/second
4 => int minRepeats; // minimum times to repeat a phrase
10 => int maxRepeats; // maximum times to repeat a phrase
[new Mandolin,
// new Wurley,
// new Wurley,
// new Wurley,
new StifKarp,
new StifKarp,
new StifKarp,
new StifKarp,
new StifKarp,
new StifKarp,
new Mandolin,
new Mandolin,
new Mandolin] @=> StkInstrument players[];
1.0/players.cap() => float mainGain;
[
// midi pitch, vol, start-ticks, dur-ticks
[72, 32, 0, 48],
[72, 32, 48, 48],
[72, 32, 96, 48],
[72, 32, 144, 48],
[72, 32, 192, 48],
[72, 32, 240, 48],
[72, 32, 288, 48],
[72, 32, 336, 48]
] @=> int pulsePhrase[][];
// Phrases transcribed from 'In C' by Terry Riley
[
[
// midi pitch, vol, start-ticks, dur-ticks
[0, 63, 0, 96]
],
[
[60, 63, 0, 6],
[64, 63, 6, 90],
[60, 63, 96, 6],
[64, 63, 102, 90],
[60, 63, 192, 6],
[64, 63, 198, 90]
],
[
[60, 63, 0, 6],
[64, 63, 6, 42],
[65, 63, 48, 48],
[64, 63, 96, 96]
],
[
[0, 63, 0, 48],
[64, 63, 48, 48],
[65, 63, 96, 48],
[64, 63, 144, 48]
],
[
[0, 63, 0, 48],
[64, 63, 48, 48],
[65, 63, 96, 48],
[67, 63, 144, 48]
],
[
[64, 63, 0, 48],
[65, 63, 48, 48],
[67, 63, 96, 48],
[0, 63, 144, 48]
],
[
[72, 63, 0, 768]
],
[
[0, 63, 0, 336],
[60, 63, 336, 24],
[60, 63, 360, 24],
[60, 63, 384, 48],
[0, 63, 432, 432]
],
[
[67, 63, 0, 576],
[65, 63, 576, 768]
],
[
[71, 63, 0, 24],
[67, 63, 24, 24],
[0, 63, 48, 336]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 63, 0, 48],
[67, 63, 48, 48],
[71, 63, 96, 384],
[72, 63, 480, 96]
],
[
[71, 63, 0, 24],
[67, 63, 24, 72],
[67, 63, 96, 24],
[65, 63, 120, 24],
[67, 63, 144, 48],
[0, 63, 192, 72],
[67, 63, 264, 312]
],
[
[72, 63, 0, 384],
[71, 63, 384, 384],
[67, 63, 768, 384],
[66, 63, 1152, 384]
],
[
[67, 63, 0, 24],
[0, 63, 24, 360]
],
[
[67, 48, 0, 24],
[71, 48, 24, 24],
[72, 48, 48, 24],
[71, 48, 72, 24]
],
[
[71, 48, 0, 24],
[72, 48, 24, 24],
[71, 48, 48, 24],
[72, 48, 72, 24],
[71, 48, 96, 24],
[0, 48, 120, 24]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[64, 48, 96, 72],
[64, 48, 168, 24]
],
[
[0, 63, 0, 144],
[67, 63, 144, 144]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[55, 48, 96, 72],
[64, 48, 168, 24],
[66, 48, 192, 24],
[64, 48, 216, 24],
[66, 48, 240, 24],
[64, 48, 264, 24]
],
[
[66, 63, 0, 288]
],
[
[64, 63, 0, 144],
[64, 63, 144, 144],
[64, 63, 288, 144],
[64, 63, 432, 144],
[64, 63, 576, 144],
[66, 63, 720, 144],
[67, 63, 864, 144],
[69, 63, 1008, 144],
[71, 63, 1152, 48]
],
[
[64, 63, 0, 48],
[66, 63, 48, 144],
[66, 63, 192, 144],
[66, 63, 336, 144],
[66, 63, 480, 144],
[66, 63, 624, 144],
[67, 63, 768, 144],
[69, 63, 912, 144],
[71, 63, 1056, 96]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 144],
[67, 63, 240, 144],
[67, 63, 384, 144],
[67, 63, 528, 144],
[67, 63, 672, 144],
[69, 63, 816, 144],
[71, 63, 960, 48]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 48],
[69, 63, 144, 144],
[69, 63, 288, 144],
[69, 63, 432, 144],
[69, 63, 576, 144],
[69, 63, 720, 144],
[71, 63, 864, 144]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 48],
[69, 63, 144, 48],
[71, 63, 192, 144],
[71, 63, 336, 144],
[71, 63, 480, 144],
[71, 63, 624, 144],
[71, 63, 768, 144]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[67, 48, 96, 48],
[64, 48, 144, 24],
[67, 48, 168, 24],
[66, 48, 192, 24],
[64, 48, 216, 24],
[66, 48, 240, 24],
[64, 48, 264, 24]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[64, 48, 96, 72],
[64, 48, 168, 24]
],
[
[64, 63, 0, 288],
[67, 63, 288, 288],
[72, 63, 576, 288]
],
[
[72, 63, 0, 576]
],
[
[67, 48, 0, 24],
[65, 48, 24, 24],
[67, 48, 48, 24],
[71, 48, 72, 24],
[67, 48, 96, 24],
[71, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[65, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[65, 48, 120, 312],
[67, 48, 432, 144]
],
[
[67, 63, 0, 24],
[65, 63, 24, 24],
[0, 63, 48, 48]
],
[
[67, 48, 0, 24],
[65, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24],
[71, 48, 144, 24],
[67, 48, 168, 24],
[71, 48, 192, 24],
[67, 48, 216, 24],
[0, 48, 240, 336],
[70, 63, 576, 96],
[79, 63, 672, 288],
[81, 63, 960, 48],
[79, 63, 1008, 96],
[83, 63, 1104, 48],
[81, 63, 1152, 144],
[79, 63, 1296, 48],
[76, 63, 1344, 288],
[79, 63, 1632, 48],
[78, 63, 1680, 336],
[0, 63, 2016, 240],
[76, 63, 2256, 240],
[77, 63, 2496, 576]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24],
[65, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[72, 48, 120, 24]
],
[
[71, 48, 0, 24],
[65, 48, 24, 24]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24]
],
[
[72, 63, 0, 384],
[71, 63, 384, 384],
[69, 63, 768, 384],
[72, 63, 1152, 384]
],
[
[65, 48, 0, 96],
[64, 48, 96, 96],
[65, 48, 192, 96],
[64, 48, 288, 96],
[64, 48, 384, 48],
[64, 48, 432, 48],
[64, 48, 480, 48],
[65, 48, 528, 24],
[64, 48, 552, 24]
],
[
[77, 63, 0, 48],
[76, 63, 48, 96],
[76, 63, 144, 48],
[72, 63, 192, 96]
],
[
[74, 63, 0, 96],
[74, 63, 96, 96],
[67, 63, 192, 96]
],
[
[67, 48, 0, 24],
[74, 48, 24, 24],
[76, 48, 48, 24],
[74, 48, 72, 24],
[0, 48, 96, 48],
[67, 48, 144, 48],
[0, 48, 192, 48],
[67, 48, 240, 48],
[0, 48, 288, 48],
[67, 48, 336, 48],
[67, 48, 384, 24],
[74, 48, 408, 24],
[76, 48, 432, 24],
[74, 48, 456, 24]
],
[
[74, 63, 0, 24],
[76, 63, 24, 24],
[74, 63, 48, 48]
],
[
[67, 63, 0, 576],
[67, 63, 576, 384],
[65, 63, 960, 480]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[70, 48, 48, 24],
[67, 48, 72, 24],
[70, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[70, 48, 48, 24]
],
[
[67, 48, 0, 24],
[70, 48, 24, 24]
],
[
[70, 48, 0, 24],
[67, 48, 24, 24]
]
] @=> int phraseList[][][];
players.cap() => int playersIn;
1 => int pulseIsPlaying;
fun int phraseLength(int ph[][])
{
return ph[ph.cap()-1][2] + ph[ph.cap()-1][3];
}
// Base frequency for MIDI -> freq conversion
(440/32)*Math.pow(2,0.25) => float noteZero;
fun void playPhrase(int ph[][], int player)
{
players[player] @=> StkInstrument voc;
if (player >= players.cap())
{
<<< "Bad Player!" >>>;
}
0=>voc.gain;
20=>voc.freq; // this inhibits an error message
for (0 => int i; i < ph.cap(); ++i)
{
if (ph[i][0] > 0) {
// convert midi-note to frequency
noteZero*Math.pow(2,ph[i][0]/12.0) => voc.freq;
// convert midi-vol to gain (and randomize it a bit)
(mainGain*ph[i][1]+Std.rand2(0,9)-4)/127.0 => float gain;
if (gain <= 0)
0 => gain;
gain => voc.gain;
}
else {
// rest
0 => voc.gain;
}
1 => voc.noteOn;
// wait til next note...
(ph[i][3]/bps)::second => now;
1 => voc.noteOff;
if (i+1 < ph.cap())
((ph[i+1][2] - (ph[i][2]+ph[i][3]))/bps)::second => now;
}
}
// Repeat a particular phrase N times
fun void repeatPhrase(int ph[][], int n, int player)
{
phraseLength(ph) => float totBeats;
for (0 => int pp; pp < n; ++pp)
{
spork ~ playPhrase(ph, player);
(totBeats/bps)::second => now;
}
}
// Performance by a single player
// play each phrase a random number of times
fun void doRileyPart(int player)
{
for (0 => int p; p < phraseList.cap(); ++p)
{
Std.rand2(minRepeats,maxRepeats) => int nTimes;
repeatPhrase(phraseList[p], nTimes, player);
}
--playersIn; // decrement player counter, so pulse knows when to stop
}
// Performance by the Pulse player
fun void doPulse()
{
do {
repeatPhrase(pulsePhrase, 1,0);
} while (playersIn > 0);
// Do a few more pulses to end the piece
repeatPhrase(pulsePhrase, 8,0);
0 => pulseIsPlaying; // Notification that we have stopped
}
// Performance by all non-pulse players
fun void doRileyParts()
{
for (1 => int p; p < players.cap(); ++p)
spork ~ doRileyPart(p);
}
for (0 => int i; i < players.cap(); ++i)
{
players[i] => dac;
0 => players[i].gain;
}
// Start the Pulse
spork ~ doPulse();
// Let him go for a bit...
(phraseLength(pulsePhrase)*4/bps)::second => now;
// Start up all the players
doRileyParts();
// Let time elapse until the pulse stops
do {
1::second => now;
} while (pulseIsPlaying);
|
_________________ <a href="http://www.krazydad.com/">krazydad.com</a> Last edited by jbum on Fri Nov 03, 2006 2:45 pm; edited 1 time in total |
|
Back to top
|
|
|
jesusgollonet
Joined: Aug 29, 2006 Posts: 5 Location: Barcelona
|
Posted: Fri Nov 03, 2006 1:20 pm Post subject:
|
|
|
wow, that's really cool.
I've been thinking of doing a chuck version of In C for quite a long time. I believe trying to emulate minimal composers is great for learning computer music (i began with a version of clapping music by steve reich).
I'll dig into your code. Thanks for sharing. |
|
Back to top
|
|
|
jbum
Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Fri Nov 03, 2006 2:47 pm Post subject:
|
|
|
Hmmmm... "Violin Phase" would be cool, eh? _________________ <a href="http://www.krazydad.com/">krazydad.com</a> |
|
Back to top
|
|
|
jbum
Joined: Oct 24, 2006 Posts: 26 Location: Los Angeles
|
Posted: Fri Nov 03, 2006 3:14 pm Post subject:
|
|
|
This 3rd version seems to have fixed the major sound problems. I modified the repeatPhrase function to reduce the number of sporks, and eliminated an array out-of-bounds error.
There is still a bit of a problem with the pulse phrases, as compared to the single-instrument version - it seems to drop notes periodically.
Most of the STK instruments don't work very well for this piece if I use the default settings, and simple noteOn/noteOff to play them. So, I'm limiting it to plucked sounds for now. It would be nice to come up with a more diverse sounding ensemble...
Code: |
// ChucK Performance of Terry Riley's 'In C' (Ensemble Version - Fixed)
//
// In this famous canon by composer Terry Riley, each performer is given the
// same set of phrases.
//
// Each performer repeats each phrase a random number of times before moving
// on to the next phrase.
//
// A single player keeps time by playing a pulse beat
// When all the players are done, the pulse continues for a while, and then stops.
//
// ChucK port 11/2006 -- Jim Bumgardner
// Original Perl Program 9/2004 -- Jim Bumgardner
// With these settings, ChucK produces about 14 minutes of music.
// A more typical 'In C' performance is 20-60 minutes. Increase the
// min/max repetitions to achieve this...
//
240 => float bps; // ticks/second
4 => int minRepeats; // minimum times to repeat a phrase
10 => int maxRepeats; // maximum times to repeat a phrase
[new StifKarp,
new StifKarp,
new StifKarp,
new StifKarp,
new StifKarp,
new StifKarp,
new Mandolin,
new Mandolin,
new Mandolin,
new Mandolin,
new Mandolin] @=> StkInstrument players[];
1.0/players.cap() => float mainGain;
[
// midi pitch, vol, start-ticks, dur-ticks
[72, 32, 0, 48],
[72, 32, 48, 48],
[72, 32, 96, 48],
[72, 32, 144, 48],
[72, 32, 192, 48],
[72, 32, 240, 48],
[72, 32, 288, 48],
[72, 32, 336, 48]
] @=> int pulsePhrase[][];
// Phrases transcribed from 'In C' by Terry Riley
[
[
// midi pitch, vol, start-ticks, dur-ticks
[0, 63, 0, 96]
],
[
[60, 63, 0, 6],
[64, 63, 6, 90],
[60, 63, 96, 6],
[64, 63, 102, 90],
[60, 63, 192, 6],
[64, 63, 198, 90]
],
[
[60, 63, 0, 6],
[64, 63, 6, 42],
[65, 63, 48, 48],
[64, 63, 96, 96]
],
[
[0, 63, 0, 48],
[64, 63, 48, 48],
[65, 63, 96, 48],
[64, 63, 144, 48]
],
[
[0, 63, 0, 48],
[64, 63, 48, 48],
[65, 63, 96, 48],
[67, 63, 144, 48]
],
[
[64, 63, 0, 48],
[65, 63, 48, 48],
[67, 63, 96, 48],
[0, 63, 144, 48]
],
[
[72, 63, 0, 768]
],
[
[0, 63, 0, 336],
[60, 63, 336, 24],
[60, 63, 360, 24],
[60, 63, 384, 48],
[0, 63, 432, 432]
],
[
[67, 63, 0, 576],
[65, 63, 576, 768]
],
[
[71, 63, 0, 24],
[67, 63, 24, 24],
[0, 63, 48, 336]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 63, 0, 48],
[67, 63, 48, 48],
[71, 63, 96, 384],
[72, 63, 480, 96]
],
[
[71, 63, 0, 24],
[67, 63, 24, 72],
[67, 63, 96, 24],
[65, 63, 120, 24],
[67, 63, 144, 48],
[0, 63, 192, 72],
[67, 63, 264, 312]
],
[
[72, 63, 0, 384],
[71, 63, 384, 384],
[67, 63, 768, 384],
[66, 63, 1152, 384]
],
[
[67, 63, 0, 24],
[0, 63, 24, 360]
],
[
[67, 48, 0, 24],
[71, 48, 24, 24],
[72, 48, 48, 24],
[71, 48, 72, 24]
],
[
[71, 48, 0, 24],
[72, 48, 24, 24],
[71, 48, 48, 24],
[72, 48, 72, 24],
[71, 48, 96, 24],
[0, 48, 120, 24]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[64, 48, 96, 72],
[64, 48, 168, 24]
],
[
[0, 63, 0, 144],
[67, 63, 144, 144]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[55, 48, 96, 72],
[64, 48, 168, 24],
[66, 48, 192, 24],
[64, 48, 216, 24],
[66, 48, 240, 24],
[64, 48, 264, 24]
],
[
[66, 63, 0, 288]
],
[
[64, 63, 0, 144],
[64, 63, 144, 144],
[64, 63, 288, 144],
[64, 63, 432, 144],
[64, 63, 576, 144],
[66, 63, 720, 144],
[67, 63, 864, 144],
[69, 63, 1008, 144],
[71, 63, 1152, 48]
],
[
[64, 63, 0, 48],
[66, 63, 48, 144],
[66, 63, 192, 144],
[66, 63, 336, 144],
[66, 63, 480, 144],
[66, 63, 624, 144],
[67, 63, 768, 144],
[69, 63, 912, 144],
[71, 63, 1056, 96]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 144],
[67, 63, 240, 144],
[67, 63, 384, 144],
[67, 63, 528, 144],
[67, 63, 672, 144],
[69, 63, 816, 144],
[71, 63, 960, 48]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 48],
[69, 63, 144, 144],
[69, 63, 288, 144],
[69, 63, 432, 144],
[69, 63, 576, 144],
[69, 63, 720, 144],
[71, 63, 864, 144]
],
[
[64, 63, 0, 48],
[66, 63, 48, 48],
[67, 63, 96, 48],
[69, 63, 144, 48],
[71, 63, 192, 144],
[71, 63, 336, 144],
[71, 63, 480, 144],
[71, 63, 624, 144],
[71, 63, 768, 144]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[67, 48, 96, 48],
[64, 48, 144, 24],
[67, 48, 168, 24],
[66, 48, 192, 24],
[64, 48, 216, 24],
[66, 48, 240, 24],
[64, 48, 264, 24]
],
[
[64, 48, 0, 24],
[66, 48, 24, 24],
[64, 48, 48, 24],
[66, 48, 72, 24],
[64, 48, 96, 72],
[64, 48, 168, 24]
],
[
[64, 63, 0, 288],
[67, 63, 288, 288],
[72, 63, 576, 288]
],
[
[72, 63, 0, 576]
],
[
[67, 48, 0, 24],
[65, 48, 24, 24],
[67, 48, 48, 24],
[71, 48, 72, 24],
[67, 48, 96, 24],
[71, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[65, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[65, 48, 120, 312],
[67, 48, 432, 144]
],
[
[67, 63, 0, 24],
[65, 63, 24, 24],
[0, 63, 48, 48]
],
[
[67, 48, 0, 24],
[65, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24],
[71, 48, 144, 24],
[67, 48, 168, 24],
[71, 48, 192, 24],
[67, 48, 216, 24],
[0, 48, 240, 336],
[70, 63, 576, 96],
[79, 63, 672, 288],
[81, 63, 960, 48],
[79, 63, 1008, 96],
[83, 63, 1104, 48],
[81, 63, 1152, 144],
[79, 63, 1296, 48],
[76, 63, 1344, 288],
[79, 63, 1632, 48],
[78, 63, 1680, 336],
[0, 63, 2016, 240],
[76, 63, 2256, 240],
[77, 63, 2496, 576]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[71, 48, 48, 24]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24],
[65, 48, 48, 24],
[67, 48, 72, 24],
[71, 48, 96, 24],
[72, 48, 120, 24]
],
[
[71, 48, 0, 24],
[65, 48, 24, 24]
],
[
[71, 48, 0, 24],
[67, 48, 24, 24]
],
[
[72, 63, 0, 384],
[71, 63, 384, 384],
[69, 63, 768, 384],
[72, 63, 1152, 384]
],
[
[65, 48, 0, 96],
[64, 48, 96, 96],
[65, 48, 192, 96],
[64, 48, 288, 96],
[64, 48, 384, 48],
[64, 48, 432, 48],
[64, 48, 480, 48],
[65, 48, 528, 24],
[64, 48, 552, 24]
],
[
[77, 63, 0, 48],
[76, 63, 48, 96],
[76, 63, 144, 48],
[72, 63, 192, 96]
],
[
[74, 63, 0, 96],
[74, 63, 96, 96],
[67, 63, 192, 96]
],
[
[67, 48, 0, 24],
[74, 48, 24, 24],
[76, 48, 48, 24],
[74, 48, 72, 24],
[0, 48, 96, 48],
[67, 48, 144, 48],
[0, 48, 192, 48],
[67, 48, 240, 48],
[0, 48, 288, 48],
[67, 48, 336, 48],
[67, 48, 384, 24],
[74, 48, 408, 24],
[76, 48, 432, 24],
[74, 48, 456, 24]
],
[
[74, 63, 0, 24],
[76, 63, 24, 24],
[74, 63, 48, 48]
],
[
[67, 63, 0, 576],
[67, 63, 576, 384],
[65, 63, 960, 480]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[70, 48, 48, 24],
[67, 48, 72, 24],
[70, 48, 96, 24],
[67, 48, 120, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24]
],
[
[65, 48, 0, 24],
[67, 48, 24, 24],
[70, 48, 48, 24]
],
[
[67, 48, 0, 24],
[70, 48, 24, 24]
],
[
[70, 48, 0, 24],
[67, 48, 24, 24]
]
] @=> int phraseList[][][];
players.cap() => int playersIn;
1 => int pulseIsPlaying;
fun int phraseLength(int ph[][])
{
return ph[ph.cap()-1][2] + ph[ph.cap()-1][3];
}
// Base frequency for MIDI -> freq conversion
(440/32)*Math.pow(2,0.25) => float noteZero;
fun void playPhrase(int ph[][], int player, StkInstrument voc)
{
// voc => dac;
if (player >= players.cap())
{
<<< "Bad Player!" >>>;
}
for (0 => int i; i < ph.cap(); ++i)
{
if (ph[i][0] > 0) {
// convert midi-note to frequency
noteZero*Math.pow(2,ph[i][0]/12.0) => voc.freq;
// convert midi-vol to gain (and randomize it a bit)
(mainGain*ph[i][1]+Std.rand2(0,9)-4)/127.0 => voc.gain;
}
else {
// rest
0 => voc.gain;
}
1 => voc.noteOn;
// wait til next note...
(ph[i][3]/bps)::second => now;
1 => voc.noteOff;
if (i+1 < ph.cap())
{
if ((ph[i+1][2] - ph[i][2]) > ph[i][3])
((ph[i+1][2] - (ph[i][2]+ph[i][3]))/bps)::second => now;
}
}
}
// Repeat a particular phrase N times
fun void repeatPhrase(int ph[][], int n, int player)
{
players[player] @=> StkInstrument voc;
0 => voc.gain;
20 => voc.freq;
phraseLength(ph) => float totBeats;
for (0 => int pp; pp < n; ++pp)
{
playPhrase(ph, player, voc);
}
}
// Performance by a single player
// play each phrase a random number of times
fun void doRileyPart(int player)
{
for (0 => int p; p < phraseList.cap(); ++p)
{
Std.rand2(minRepeats,maxRepeats) => int nTimes;
repeatPhrase(phraseList[p], nTimes, player);
}
--playersIn; // decrement player counter, so pulse knows when to stop
}
// Performance by the Pulse player
fun void doPulse()
{
do {
repeatPhrase(pulsePhrase, 1,0);
} while (playersIn > 0);
// Do a few more pulses to end the piece
repeatPhrase(pulsePhrase, 8,0);
0 => pulseIsPlaying; // Notification that we have stopped
}
// Performance by all non-pulse players
fun void doRileyParts()
{
for (1 => int p; p < players.cap(); ++p)
spork ~ doRileyPart(p);
}
for (0 => int i; i < players.cap(); ++i)
{
players[i] => dac;
0 => players[i].gain;
}
// Start the Pulse
spork ~ doPulse();
// Let him go for a bit...
(phraseLength(pulsePhrase)*4/bps)::second => now;
// Start up all the players
doRileyParts();
// Let time elapse until the pulse stops
do {
1::second => now;
} while (pulseIsPlaying);
|
_________________ <a href="http://www.krazydad.com/">krazydad.com</a> |
|
Back to top
|
|
|
|