electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
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
lfo frequency cutoff controlled by mouse?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 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: Mon Apr 26, 2010 11:39 am    Post subject: lfo frequency cutoff controlled by mouse?
Subject description: changing the frequency cutoff of an lfo with mouse movement?
Reply with quote  Mark this post and the followings unread

Hi all,

I'm pretty new to Chuck and am just experimenting with it at the moment. I was wondering if there's a way to get Chuck to enable you to control the cutoff of an LFO by mouse movement - perhaps by moving the mouse up, you increase the cutoff, and obviously when you move it down you'd decrease the cutoff...

Thanks,

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



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

PostPosted: Mon Apr 26, 2010 12:45 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi Chris, can you please show me your code so far?By cutoff you mean the frequency of a filter modulated by an LFO or the speed of the LFO itself?Show me where you are so I can help you or I can send you some code if you like, but first I need to know what you mean by cutoff.Using the mouse it's very easy to control any parameter.

Andreas
Back to top
View user's profile Send private message
christorb



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

PostPosted: Tue Apr 27, 2010 2:55 am    Post subject: Reply with quote  Mark this post and the followings unread

Ok, here's my code -

[10,13,15,12,15,17,16,18,15,13,11] @=> int notes[];

1::second => dur T;
T - (now % T) => now;

int i;

Phasor o1 => HPF f1 => JCRev r1 => dac;

//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000 => f1.freq;

//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;

//infinite loop
while (true)
{

for (0 => int i; i <notes> o1.freq;

150::ms => now;
}
if(Std.randf() > -.01) .01::T => now;
else .01::T => now;
(lfo1.last()*500) + 1000 => f1.freq;
}

What I actually meant was that I'd like to be able to use mouse movement to control the frequency of the filter - my brain wasn't having a good day yesterday! I've got an lfo here, but it doesn't seem to work properly - it changes the filter frequency only after every cycle of notes...

I'm not very good at this stuff :S!

Cheers
Back to top
View user's profile Send private message
vrachnasormora



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

PostPosted: Tue Apr 27, 2010 5:35 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi Chris, here I use a variable named center_filter_freq in order to modulate the filter frequency by LFO and by mouse in two diffrerent functions sporked together before the main loop.So if this is what you are after:
Code:
Hid hid;
HidMsg msg;

hid.openMouse( 0 );

[10,13,15,12,15,17,16,18,15,13,11] @=> int notes[];

1::second => dur T;
T - (now % T) => now;

int i;

Phasor o1 => HPF f1 => JCRev r1 => dac;

//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000. => float center_filter_freq;

//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;

spork~ lfo_to_filter();
spork~ mouse_to_filter( 500, 5000 );
//infinite loop
while (true)
{
   
    for (0 => int i; i <notes> o1.freq;
        150::ms => now;
    }
}
//if(Std.randf() > -.01) .01::T => now;
//else .01::T => now;
fun void lfo_to_filter()
{
    while ( true )
    {
        (lfo1.last()*500) + center_filter_freq => f1.freq;
        100::ms => now;
    }
}

fun void mouse_to_filter( float min, float max )
{
    while ( true )
    {
        hid => now;
       
        while ( hid.recv( msg ) )
        {
            if ( msg.isMouseMotion() )
            {
                if ( msg.deltaY )
                {
                    if ( msg.deltaY <0> center_filter_freq;
                        if ( center_filter_freq > max )
                            max => center_filter_freq;
                    }
                    if ( msg.deltaY > 0 )
                    {
                        10 -=> center_filter_freq;
                        if ( center_filter_freq <min> center_filter_freq;
                    }
                   
                    <<<center_filter_freq>>>;
                }
            }
        }
    }
}
Back to top
View user's profile Send private message
vrachnasormora



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

PostPosted: Tue Apr 27, 2010 5:51 am    Post subject: Reply with quote  Mark this post and the followings unread

I'm sorry I forgot to disable HTML in the previous post.So that would be:
Code:
Hid hid;
HidMsg msg;

hid.openMouse( 0 );

[10,13,15,12,15,17,16,18,15,13,11] @=> int notes[];

1::second => dur T;
T - (now % T) => now;

int i;

Phasor o1 => HPF f1 => JCRev r1 => dac;

//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000. => float center_filter_freq;

//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;

spork~ lfo_to_filter();
spork~ mouse_to_filter( 500, 5000 );
//infinite loop
while (true)
{
   
    for (0 => int i; i <notes.size(); i++ )
    {
        Std.mtof(notes[i]) => o1.freq;
        150::ms => now;
    }
}
//if(Std.randf() > -.01) .01::T => now;
//else .01::T => now;
fun void lfo_to_filter()
{
    while ( true )
    {
        (lfo1.last()*500) + center_filter_freq => f1.freq;
        100::ms => now;
    }
}

fun void mouse_to_filter( float min, float max )
{
    while ( true )
    {
        hid => now;
       
        while ( hid.recv( msg ) )
        {
            if ( msg.isMouseMotion() )
            {
                if ( msg.deltaY )
                {
                    if ( msg.deltaY < 0 )
                    {
                        10 +=> center_filter_freq;
                        if ( center_filter_freq > max )
                            max => center_filter_freq;
                    }
                    if ( msg.deltaY > 0 )
                    {
                        10 -=> center_filter_freq;
                        if ( center_filter_freq < min )
                            min => center_filter_freq;
                    }
                   
                    <<< center_filter_freq >>>;
                }
            }
        }
    }
}
Back to top
View user's profile Send private message
christorb



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

PostPosted: Tue Apr 27, 2010 6:15 am    Post subject: Reply with quote  Mark this post and the followings unread

That's cool Smile, I can hear the effect of moving the mouse on the filter cutoff, though for some reason the notes have disappeared, replaced by what seems to be a rapid series of impulses. Would it be better do you think to remove the lfo, and just have the mouse control the filter frequency cutoff?
Sorry, I know I'm a bit of a noob with all this!
Back to top
View user's profile Send private message
vrachnasormora



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

PostPosted: Tue Apr 27, 2010 6:32 am    Post subject: Reply with quote  Mark this post and the followings unread

Well it seems that you also forgot to disable HTML in your post with the code so I modified the main loop with Std.mtof but of course the values in the array are low for midi notes ( I guess ) so they could be heard as pulses.You don't need to remove the lfo ,its contribution is subtle
Back to top
View user's profile Send private message
christorb



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

PostPosted: Tue Apr 27, 2010 7:30 am    Post subject: Reply with quote  Mark this post and the followings unread

Ah, yeah - the notes were too low! This is exactly what I was looking for!
Might see if I can get something else going with the x axis of the mouse too...

Many thanks Smile
Back to top
View user's profile Send private message
Antimon



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

PostPosted: Tue Apr 27, 2010 11:09 am    Post subject: Reply with quote  Mark this post and the followings unread

Just want to mention that ChucK can actually identify several different mice (at least in my experiments on the Mac). Example:

    mouse 1 Y controls cutoff of a filter
    mouse 1 X controls resonance of same filter
    mouse 2 Y controls frequency of oscillator 1
    mouse 2 X controls frequency of oscillator 2


You do this by incrementing the argument to hid.openMouse(), so hid.openMouse(0) accesses one mouse and hid.openMouse(1) accesses another.

/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
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 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