twist3d
Joined: Apr 27, 2010 Posts: 6 Location: uk
|
Posted: Mon May 10, 2010 5:02 am Post subject:
note offs not working |
|
|
hi all, i'm doing a rendition of tetris using chuck for a uni project, but i can't seem to get the note offs to work. can someone help me with this please?
Thanks in advance
here's my code so far:
Code: |
// Declarations
Envelope EnvMaster;
Envelope EnvChanOne;
Envelope EnvChanTwo;
Envelope EnvChanThree;
Envelope EnvChanFour;
Envelope EnvChanFive;
Envelope EnvChanSix;
//Filter Declarations
HPF HiPassOne;
//Filter Configurations
1 => HiPassOne.Q;
//Instrument Declarations:
Clarinet Clari1;
Clarinet Clari2;
Saxofony Sax1;
//Instrument Configurations
.2 => Clari1.gain;
.2 => Clari2.gain;
.2 => Sax1.gain;
//Event Declarations
Event e1;
Event allFinished;
// Master Effects Patch
EnvMaster => dac;
// Channel Effects Patch
EnvChanOne => EnvMaster;
EnvChanTwo => EnvMaster;
EnvChanThree => EnvMaster;
EnvChanFour => EnvMaster;
EnvChanFive => EnvMaster;
EnvChanSix => EnvMaster;
//Instrument Patches
Clari1 => HiPassOne => EnvChanOne;
Clari2 => EnvChanTwo;
Sax1 => HiPassOne => EnvChanThree;
//Open Master Envelope
EnvMaster.keyOn();
// the notes
// MIDI note constants.
60 => int c; 72 => int C;
61 => int cs; 73 => int Cs;
62 => int d; 74 => int D;
63 => int ds; 75 => int Ds;
64 => int e; 76 => int E;
65 => int f; 77 => int F;
66 => int fs; 78 => int Fs;
67 => int g; 79 => int G;
68 => int gs; 80 => int Gs;
69 => int a; 81 => int A;
70 => int as; 82 => int As;
71 => int b; 83 => int B;
// We use musical tempo, and symbolic durations
240 => int tempo;
// integers 1,2,4,8 mean musical figures
dur duration[9];
240000::ms / ( 1 * tempo ) => duration[1]; // whole
240000::ms / ( 2 * tempo ) => duration[2]; // half
240000::ms / ( 4 * tempo ) => duration[4]; // quarter
240000::ms / ( 8 * tempo ) => duration[8]; // eighth
(duration[4] + duration[8]) => duration[5]; // dotted quarter
(duration[2] + duration[4]) => duration[3]; // dotted half
//1st part
[[E,2],[b,4],[C,4],[D,4],[E,8],
[D,8],[C,4],[b,4],[a,2],[a,4],
[C,4],[E,2],[D,4],[C,4],[b,3],
[C,4],[D,2],[E,2],[C,2],[a,2],
[a,1]
] @=> int v1a[][];
//second part
[[0,4],[D,2],[F,4],[A,2],[G,4],
[F,4],[E,3],[C,4],[E,2],[D,4],
[C,4],[b,2],[b,4],[C,4],[D,2],
[E,2],[C,2],[a,2],[a,2]
] @=> int v2a[][];
// Play a fragment
fun void playVoice(StkInstrument m, int voice[][], int transpose)
{
for( 0 => int i; i < voice.cap(); i++)
{
if ( voice[i][0] > 0 )
{
Std.mtof( voice[i][0] + transpose ) => m.freq;
1.0 => m.noteOn;
}
duration[voice[i][1]] => now;
m.noteOff;
}
}
fun void playVoice(StkInstrument m, int voice[][], int transpose)
{
for( 0 => int i; i < voice.cap(); i++)
{
if ( voice[i][0] > 0 )
{
Std.mtof( voice[i][0] + transpose ) => m.freq;
1.0 => m.noteOn;
}
duration[voice[i][1]] => now;
m.noteOff;
}
}
fun void playv1()
{
EnvChanOne.keyOn();
playVoice(Clari1, v1a, 0);
EnvChanOne.keyOff();
EnvChanOne =< EnvMaster;
e1.signal();
}
fun void playv2()
{
EnvChanThree.keyOn();
playVoice(Sax1, v2a, 0);
EnvChanThree.keyOff();
e1.signal();
}
fun void playv3()
{
EnvChanOne.keyOn();
playVoice(Clari1, v1a, 0);
EnvChanOne.keyOff();
e1.signal();
}
fun void playv4()
{
EnvChanOne.keyOn();
playVoice(Clari2, v2a, 0);
EnvChanOne.keyOff();
allFinished.signal();
}
fun void SineWaveFilter(FilterBasic filter)
{
float t;
while( true )
{
20 + Std.fabs(Math.sin(t)) * 5000 => filter.freq;
.002 +=> t;
10::ms => now;
}
}
spork ~ playv1();
spork ~ SineWaveFilter(HiPassOne);
e1 => now;
spork ~ playv2();
e1 => now;
spork ~ playv3();
e1 => now;
spork ~ playv4();
allFinished => now;
|
|
|