electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
note offs not working
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
twist3d



Joined: Apr 27, 2010
Posts: 6
Location: uk

PostPosted: Mon May 10, 2010 5:02 am    Post subject: note offs not working Reply with quote  Mark this post and the followings unread

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 Smile

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;
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4146
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Mon May 10, 2010 6:25 am    Post subject: Reply with quote  Mark this post and the followings unread

Since the noteOn() and noteOff() methods in StkInstruments shared the same kind of declaration, I think you need to call them in the same way:

Code:
1.0 => m.noteOn;


and

Code:
1.0 => m.noteOff;


You could also do the equivalent C-style calls:

Code:
 m.noteOn(1.0);


and

Code:
m.noteOff(1.0);


...possibly. I'm honestly not sure if ChucK has some way of dealing with a bracketless function name all by itself, not being assigned to. Worth a try anyway.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
twist3d



Joined: Apr 27, 2010
Posts: 6
Location: uk

PostPosted: Mon May 10, 2010 6:29 am    Post subject: Reply with quote  Mark this post and the followings unread

ahh brilliant. kinda feel a bit stupid for not adding that really, considering it's been used in that format for the note ons!

problem that has now appeared from changing that is the event "AllFinished" doesn't removed the shreds from the VM

many thanks for your help Stefan
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use