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 
Live streaming at radio.electro-music.com

  host / artist show at your time
<on air> bingsatellites Mostly Ambient
Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
LFOs and removal of sporked functions after time...
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
christorb



Joined: Feb 09, 2010
Posts: 17
Location: Cambridge, UK

PostPosted: Wed May 05, 2010 4:21 pm    Post subject: LFOs and removal of sporked functions after time... Reply with quote  Mark this post and the followings unread

Hi all,

I'm still beavering away with old ChucKlington McChucKery (and enjoying it too)! I've written a really simple (and pretty silly sounding) tune with it, still experimenting and trying to learn the code.

I was just wondering if there's a way to get sporked functions removed after a period of time - this kind of follows on from my previous post the 'Chuck composition question' - I couldn't quite figure out Scott's multidimensional array properly, so I'm afraid I've abandoned the idea in favor of something easier for my pea brain to understand. I'll have a proper go with it sometime though...

One other thing - my LFO's don't seem to be having any effect - I must have set them up wrong, but I'm unsure how...

The code ought to make it pretty obvious what I'm trying to do!
Code:

Hid hid;
HidMsg msg;
hid.openMouse( 0 );

//tempo and note lengths
80 => float bpm;    // BPM
(60/bpm)::second    => dur crotchet => dur c;;

crotchet*2       => dur minim => dur m;
crotchet/2       => dur quaver => dur q;
quaver/2         => dur semiquaver => dur sq;
1.5*quaver       => dur dottedquaver => dur dq;
crotchet/3       => dur tripletquaver => dur tq;
quaver/3         => dur tripletsemiquaver => dur tsq;
crotchet*3       => dur bar;
3*quaver         => dur dc;
1.75*crotchet    => dur ddc;
quaver/12        => dur jiffy;
crotchet*4       => dur fourbars;
quaver/4         => dur qq;

//oscillators
SinOsc basstone;
SawOsc padtone;
SawOsc melody1;
PulseOsc melody2;

//paning
Pan2 pan1;
Pan2 pan2;

//envelopes
ADSR padenv;

//highpass filter
LPF f1;
HPF f2;
HPF f3;

//chorus
Chorus c1;

//reverbs
PRCRev r1;
JCRev r2;

//Delays
Echo e1;
Echo e2;

//lfo
SinOsc lfo1 => blackhole;
20  => lfo1.freq;
SinOsc lfo2 => blackhole;
10 => lfo2.freq;

//defining pans
-1  => pan1.pan;
1  => pan2.pan;

//defining filters
1000 => f1.freq;
2000 => float f2_frequency;
1000 => float f3_frequency;

//defining chorus
1 => c1.modFreq;
.15  => c1.modDepth;
.5   => c1.mix;

//defining reverb
.4 => r1.mix;
.2 => r2.mix;

//defining delays
1.5 * sq => e1.delay;
5   * sq => e1.max;
.3       => e1.mix;

.75 * sq => e2.delay;
3   * sq => e2.max;
.6       => e2.mix;

//defining pad envelope
padenv.set  ( 500::ms, 300::ms, .8, 500::ms );

int bassline;
int padline;
int mel1line;
int mel2line;

fun void lfo1_to_filter2()
{
    while ( true )
    {
    ( lfo1.last() ) + f2_frequency => f2.freq;
    100::ms => now;
    }
}

fun void lfo2_to_filter3()
{
    while ( true )
    {
        ( lfo2.last() ) + f3_frequency => f3.freq;
        100::ms => now;
    }
}

//Bassline notes/lengths
[44, 50, 44, 52, 44, 50, 44, 52] @=> int bassnotes [];
[sq, sq, sq, sq, sq, sq, sq, sq] @=> dur basslengths [];

//Padline notes/lengths
[64, -9999, 70, -9999] @=> int padnotes [];
[ m,     m,  m,     m] @=> dur padlengths [];

//melody1 notes/lengths
[66, 68, 70, -9999, 70, 68, 66, -9999] @=> int mel1notes [];
[sq, sq, sq,    sq, sq, sq, sq,    sq] @=> dur mel1lengths [];

//melody2 notes/lengths
[80, 82, 86, 82, 88, 84] @=> int mel2notes [];
[sq, sq,  q, sq, sq,  q] @=> dur mel2lengths [];

//Playthrough functions
fun void PlayBass( SinOsc tone, int notes [], dur lengths [] )
{
    tone => f1 => dac;
    while ( true )
    {
        for( 0 => int i; i < notes.size(); i++ )
        {
        Std.mtof(notes[i]) => basstone.freq;
        lengths [i] => now;         
        }
    }
}
fun void PlayPad( SawOsc tone, int notes [], dur lengths [] )
{
    tone => padenv => c1 => r1 => f1 => dac;
    while ( true )
    {
        for( 0 => int i; i < notes.size(); i++ )
        {
        Std.mtof(padnotes[i]) => padtone.freq;
        padlengths [i] => now;       
        } 
    }   
}

fun void PlayMel1( SawOsc tone, int notes [], dur lengths [] )
{
    tone => e1 => f2 => pan1 => dac;
    while ( true )
    {
        for( 0 => int i; i < notes.size(); i++ )
        {
            Std.mtof(mel1notes[i]) => melody1.freq;
            mel1lengths [i] => now;
        }
    }
}
fun void PlayMel2( PulseOsc tone, int notes [], dur lengths [] )
{
    tone => f3 => r2 => pan2 => dac;
    while ( true )
    {
        for( 0 => int i; i < notes.size(); i++ )
        {
            Std.mtof(mel2notes[i]) => melody2.freq;
            mel2lengths [i] => now;
        }
    }
}

spork~ lfo1_to_filter2();
spork~ lfo2_to_filter3();
spork~ PlayBass( basstone, bassnotes, basslengths );
fourbars => now;
spork~ PlayPad( padtone, padnotes, padlengths );
fourbars * 2 => now;
spork~ PlayMel1( melody1, mel1notes, mel1lengths );
fourbars * 2 => now;
spork~ PlayMel2( melody2, mel2notes, mel2lengths );
1::week => now;

fun void DisconnectPad()
{
    padtone =< padenv =< c1 =< r1 =< f1 =< dac;
}
fun void DisconnectMel1()
{
   
}
fun void DisconnectMel2()
{
   
}

spork~ DisconnectPad();
fourbars => now;
//spork~ DisconnectMel1();
//spork~ DisconnectMel2();


I basically would like to be able to removed some sporked functions whilst keeping others going...

Thanks

Chris
Back to top
View user's profile Send private message
witt0191



Joined: Feb 13, 2008
Posts: 23
Location: UK

PostPosted: Thu May 06, 2010 6:19 am    Post subject: Reply with quote  Mark this post and the followings unread

With the code you have all ready written one option would be to put variables in the while loops rather than just 'true'

Code:
SinOsc s => dac;
1 => int control;
function void demo()
{
    while(control)
    {
        0.5 => s.gain;
        Std.rand2f(440,500) => s.freq;
        400::ms => now;
        0.0 => s.gain;
        400::ms => now;
    }
}

spork ~ demo();
5000::ms => now;
//stops while loop
0 => control;
2000::ms => now;
Back to top
View user's profile Send private message
christorb



Joined: Feb 09, 2010
Posts: 17
Location: Cambridge, UK

PostPosted: Thu May 06, 2010 9:03 am    Post subject: Reply with quote  Mark this post and the followings unread

It's OK - I managed to come up with something... Thanks anyway. Just need to get the LFOs working really...

Code:

//tempo and note lengths
80 => float bpm;    // BPM
(60/bpm)::second    => dur crotchet => dur c;;

crotchet*2       => dur minim => dur m;
crotchet/2       => dur quaver => dur q;
quaver/2         => dur semiquaver => dur sq;
1.5*quaver       => dur dottedquaver => dur dq;
crotchet/3       => dur tripletquaver => dur tq;
quaver/3         => dur tripletsemiquaver => dur tsq;
crotchet*3       => dur bar;
3*quaver         => dur dc;
1.75*crotchet    => dur ddc;
quaver/12        => dur jiffy;
crotchet*4       => dur fourbars;
quaver/4         => dur qq;

//oscillators
SinOsc basstone;
SawOsc padtone;
TriOsc melody1;
PulseOsc melody2;
TriOsc melody3;
PulseOsc melody4;

//oscillator levels
.5  => basstone.gain;
.5  => padtone.gain;
1.5 => melody1.gain;
.2  => melody2.gain;
1.7 => melody3.gain;
.4  => melody4.gain;

//paning
Pan2 pan1;
Pan2 pan2;
Pan2 pan3;
Pan2 pan4;

//envelopes
ADSR padenv;

//highpass filter
LPF f1;
HPF f2;
HPF f3;

//chorus
Chorus c1;

//reverbs
PRCRev r1;
JCRev r2;

//Delays
Echo e1;
Echo e2;

//lfo
SinOsc lfo1 => blackhole;
20  => lfo1.freq;
SinOsc lfo2 => blackhole;
10 => lfo2.freq;

//defining pans
-1   => pan1.pan;
 1   => pan2.pan;
 0.5 => pan3.pan;
-0.5 => pan4.pan;

//defining filters
1000 => f1.freq;
2000 => float f2_frequency;
1000 => float f3_frequency;

//defining chorus
1    => c1.modFreq;
.15  => c1.modDepth;
.5   => c1.mix;

//defining reverb
.4 => r1.mix;
.2 => r2.mix;

//defining delays
1.5 * sq => e1.delay;
5   * sq => e1.max;
.3       => e1.mix;

.75 * sq => e2.delay;
3   * sq => e2.max;
.6       => e2.mix;

//defining pad envelope
padenv.set  ( 500::ms, 300::ms, .8, 500::ms );

1 => int play1;
1 => int play2;
1 => int play3;
1 => int play4;
1 => int play5;
1 => int play6;
1 => int play7;
1 => int play8;

fun void lfo1_to_filter2()
{
    while ( true )
    {
    ( lfo1.last() ) + f2_frequency => f2.freq;
    100::ms => now;
    }
}

fun void lfo2_to_filter3()
{
    while ( true )
    {
        ( lfo2.last() ) + f3_frequency => f3.freq;
        100::ms => now;
    }
}

//Note run 1
//Bassline notes/lengths
[44, 50, 44, 52, 44, 50, 44, 52, 42, 48, 44, 52, 42, 46, 44, 52] @=> int bassnotes [];
[sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq] @=> dur basslengths [];

//Padline notes/lengths
[64, -9999, 70, -9999, 76, -9999, 72, -9999] @=> int padnotes [];
[ m,     m,  m,     m,  m,     m,  m,     m] @=> dur padlengths [];

//melody1 notes/lengths
[66, 68, 70, -9999, 70, 68, 66, -9999, 62, 68, 64, -9999, 68, 70, 64, -9999] @=> int mel1notes [];
[sq, sq, sq,    sq, sq, sq, sq,    sq, sq, sq, sq,    sq, sq, sq, sq,    sq] @=> dur mel1lengths [];

//melody2 notes/lengths
[80, 82, 86, 82, 88, 84, 82, 86, 84, 78, 84, 88] @=> int mel2notes [];
[sq, sq,  q, sq, sq,  q, sq, sq,  q, sq, sq,  q] @=> dur mel2lengths [];

//Note run 2
//Bassline2 notes/lengths
[44, 48, 46, 40, 44, 46, 48, 50, 42, 48, 46, 50, 48, 42, 48, 50] @=> int bassnotes2 [];
[sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq, sq] @=> dur basslengths2 [];

//Padline2 notes/lengths
[60, 64, 68, 72, 60, 66, 64, 68] @=> int padnotes2 [];
[ m,  m,  m,  m,  m,  m,  m,  m] @=> dur padlengths2 [];

//melody1 -2- notes/lengths
[66, -9999, 70, -9999, 68, -9999, 66, -9999, 62, -9999, 58, -9999, 64, -9999, 66, -9999] @=> int mel1notes2 [];
[sq,    sq, sq,    sq, sq,    sq, sq,    sq, sq,    sq, sq,    sq, sq,    sq, sq,    sq] @=> dur mel1lengths2 [];

//melody2 -2- notes/lengths
[84, 82, 80, 82, 80, 76, 84, 86, 88, 86, 88, 90] @=> int mel2notes2 [];
[sq, sq,  q, sq, sq,  q, sq, sq,  q, sq, sq,  q] @=> dur mel2lengths2  [];

//Playthrough functions
//First 4 Melodys
fun void PlayBass( SinOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play1 == 1 )
        {
            tone => f1 => dac;
            for( 0 => int i; i <notes> basstone.freq;
                lengths [i] => now;         
            }
            tone =< f1 =<dac> now;
            }
        }
    }
}

fun void PlayPad( SawOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play2 == 1 )
        {
            tone => padenv => c1 => r1 => f1 => dac;
            padenv.keyOn;
            for( 0 => int i; i <notes> padtone.freq;
                padlengths [i] => now;       
            }
            tone =< padenv =< c1 =< r1 =< f1 =<dac> now; 
            }   
        }
    }
}

fun void PlayMel1( TriOsc tone, int notes [], dur lengths [] )
{
     while ( true )
    {
        if( play3 == 1 )
        {
            tone => e1 => f2 => pan1 => dac;
            for( 0 => int i; i <notes> melody1.freq;
                mel1lengths [i] => now;
            }
            tone =< e1 =< f2 =< pan1 =<dac> now;
            }
        }
    }
}

fun void PlayMel2( PulseOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play4 == 1 )
        {
            tone => f3 => r2 => pan2 => dac;
            for( 0 => int i; i <notes> melody2.freq;
                mel2lengths` [i] => now;
            }
            tone =< f3 =< r2 =< pan2 =<dac> now;
            }
        }
    }
}

//Next 4 melodys
fun void PlayBass2( SinOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play5 == 1 )
        {
            tone => f1 => dac;
            for( 0 => int i; i <notes> basstone.freq;
                lengths [i] => now;         
            }
            tone =< f1 =<dac> now;
            }
        }
    }
}

fun void PlayPad2( SawOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play6 == 1 )
        {
            tone => padenv => c1 => r1 => f1 => dac;
           
            for( 0 => int i; i <notes> padtone.freq;
                padlengths2 [i] => now;       
            }
            tone =< padenv =< c1 =< r1 =< f1 =<dac> now; 
            }   
        }
    }
}

fun void PlayMel12( TriOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play7 == 1 )
        {
            tone => e1 => f2 => pan3 => dac;
            for( 0 => int i; i <notes> melody3.freq;
                mel1lengths2 [i] => now;
            }
            tone =< e1 =< f2 =< pan3 =<dac> now;
            }
        }
    }
}

fun void PlayMel22( PulseOsc tone, int notes [], dur lengths [] )
{
    while ( true )
    {
        if( play8 == 1 )
        {
            tone => f3 => r2 => pan4 => dac;
            for( 0 => int i; i <notes> melody4.freq;
                mel2lengths2 [i] => now;
            }
            tone =< f3 =< r2 =< pan4 =<dac> now;
            }
        }
    }
}

spork~ lfo1_to_filter2();
spork~ lfo2_to_filter3();
spork~ PlayBass( basstone, bassnotes, basslengths );
spork~ PlayPad( padtone, padnotes, padlengths );
spork~ PlayMel1( melody1, mel1notes, mel1lengths );
spork~ PlayMel2( melody2, mel2notes, mel2lengths );

1 => play1; //bass
0 => play2; //pad
0 => play3; //mel1
0 => play4; //mel2
0 => play5; //bass2
0 => play6; //pad2
0 => play7; //mel1 - 2
0 => play8; //mel2 - 2
fourbars * 2 => now;

1 => play1; //bass
1 => play2; //pad
0 => play3; //mel1
0 => play4; //mel2 - 2
fourbars * 4 => now;

1 => play1; //bass
1 => play2; //pad
1 => play3; //mel1
0 => play4; //mel2
fourbars * 2 => now;

1 => play1; //bass
0 => play2; //pad
0 => play3; //mel1
1 => play4; //mel2
fourbars * 2 => now;

1 => play1; //bass
1 => play2; //pad
1 => play3; //mel1
1 => play4; //mel2
fourbars * 4 => now;

spork~ PlayBass2( basstone, bassnotes2, basslengths2 );
spork~ PlayPad2 ( padtone, padnotes, padlengths );
spork~ PlayMel12( melody3, mel1notes2, mel1lengths2 );
spork~ PlayMel22( melody4, mel2notes2, mel2lengths2 );

0 => play1; //bass
0 => play2; //pad
1 => play3; //mel1
0 => play4; //mel2
1 => play5; //bass2
0 => play6; //pad2
0 => play7; //mel1 - 2
0 => play8; //mel2 - 2
fourbars * 2 => now;

0 => play1; //bass
0 => play2; //pad
0 => play3; //mel1
0 => play4; //mel2
1 => play5; //bass2
1 => play6; //pad2
1 => play7; //mel1 - 2
1 => play8; //mel2 - 2
fourbars * 4 => now;

0 => play1; //bass
0 => play2; //pad
0 => play3; //mel1
0 => play4; //mel2
1 => play5; //bass2
1 => play6; //pad2
0 => play7; //mel1 - 2
0 => play8; //mel2 - 2
fourbars * 2 => now;

0 => play1; //bass
0 => play2; //pad
0 => play3; //mel1
0 => play4; //mel2
1 => play5; //bass2
0 => play6; //pad2
0 => play7; //mel1 - 2
0 => play8; //mel2 - 2
fourbars * 2 => now;

0 => play1; //bass
0 => play2; //pad
0 => play3; //mel1
0 => play4; //mel2
1 => play5; //bass2
0 => play6; //pad2
0 => play7; //mel1 - 2
0 => play8; //mel2 - 2
fourbars => now;
Back to top
View user's profile Send private message
vrachnasormora



Joined: Mar 22, 2007
Posts: 42
Location: Preveza,Greece

PostPosted: Thu May 06, 2010 11:42 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi Chris, in the lfo functions lfo.last() will output values from -1.0 to 1.0 so you need to scale it to bigger width by multiplying with a value not greater than filter's center frequency in order to exclude negative values for the frequency.If for example maximum of f2_frequency is 1000 then:

Code:
800. => float wide;
( lfo1.last() * wide ) + f2_frequency => f2.freq;
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 [4 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
Niio2

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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