| 1 |
//---------------------------------------------------------------------- |
| 2 |
// name: young.ck |
| 3 |
// desc: an interactive ChucK rendition of |
| 4 |
// La Monte Young's Composition 1960 #7 |
| 5 |
// |
| 6 |
// note: one possible, non-interactive, alternative implementation: |
| 7 |
// |
| 8 |
// SawOsc b(Std.mtof(59)) => Gain b_gain(0.5) => dac; |
| 9 |
// SawOsc fs(Std.mtof(66)) => Gain fs_gain(0.5) => dac; |
| 10 |
// |
| 11 |
// Math.randomf()::eon => dur a_very_long_time; |
| 12 |
// a_very_long_time => now; |
| 13 |
// |
| 14 |
// author: Nick Shaheed (https://nicholasshaheed.com/) |
| 15 |
// date: Fall 2025 |
| 16 |
//---------------------------------------------------------------------- |
| 17 |
|
| 18 |
Hid hi; |
| 19 |
HidMsg msg; |
| 20 |
|
| 21 |
// open keyboard |
| 22 |
if( !hi.openKeyboard( 0 ) ) me.exit(); |
| 23 |
|
| 24 |
SawOsc b(Std.mtof(59)) => Gain b_gain(0.5) => Envelope b_env => dac; |
| 25 |
SawOsc fs(Std.mtof(66)) => Gain fs_gain(0.5) => Envelope fs_env => dac; |
| 26 |
|
| 27 |
// print out piece title and instruction |
| 28 |
"Composition 1960 #7" => string title; |
| 29 |
print(title); |
| 30 |
500::ms => now; |
| 31 |
|
| 32 |
"[spacebar] to be held for a long time" => string instr; |
| 33 |
print(instr); |
| 34 |
|
| 35 |
// tracking whether the spacebar has been pressed yet |
| 36 |
false => int holding; |
| 37 |
|
| 38 |
// infinite event loop |
| 39 |
while( true ) |
| 40 |
{ |
| 41 |
// wait on event |
| 42 |
hi => now; |
| 43 |
|
| 44 |
// get one or more messages |
| 45 |
while( hi.recv( msg ) ) |
| 46 |
{ |
| 47 |
// respond to spacebar, if it's pressed begin play fifth, if |
| 48 |
// it's released, the piece is over. |
| 49 |
if( msg.which == 44 ) |
| 50 |
{ |
| 51 |
if( !holding && msg.isButtonDown() ) |
| 52 |
{ |
| 53 |
true => holding; |
| 54 |
b_env.keyOn(); |
| 55 |
fs_env.keyOn(); |
| 56 |
} |
| 57 |
if( holding && msg.isButtonUp() ) |
| 58 |
{ |
| 59 |
b_env.keyOff(); |
| 60 |
fs_env.keyOff(); |
| 61 |
|
| 62 |
chout <= IO.newline(); |
| 63 |
500::ms => now; |
| 64 |
" La Monte Young" => string composer; |
| 65 |
" July 1960" => string date; |
| 66 |
|
| 67 |
print(composer); |
| 68 |
print(date); |
| 69 |
500::ms => now; |
| 70 |
|
| 71 |
me.exit(); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
// incrementally print out characters in a string |
| 78 |
fun void print(string str) |
| 79 |
{ |
| 80 |
// iterate |
| 81 |
for( int i:Std.range(str.length()) ) |
| 82 |
{ |
| 83 |
chout <= str.substring(i,1); |
| 84 |
// we need to flush the stdout buffer after every |
| 85 |
// character so that it actually prints |
| 86 |
chout.flush(); |
| 87 |
50::ms => now; |
| 88 |
} |
| 89 |
// endline |
| 90 |
chout <= IO.newline(); |
| 91 |
} |