| Author |
Message |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Thu Apr 29, 2010 11:43 am Post subject:
Code runs, but not quite to plan... Subject description: Panning and Echo.. |
 |
|
Hi all,
I've been playing around with ChucK quite a bit more, and have managed (with some help from this forum) to get my code so that the filter cutoff and filter resonance changes with the motion of the mouse.
Following on from that, I've tried to make it so that the mouse wheel will alter the panning of the oscillator, as well as having three different echo effects that can be chosen with the keyboard - ie, pressing 1 will change it to echo 1, pressing 2 will change it to echo 2 and finally, yup, you guessed it, pressing 3 changes it to echo 3...
The thing is, although the patch seems to run without any errors, the panning with the mouse wheel and echo chosen by the keyboard doesn't work... I've been trying to decipher why, but as a pretty new user to ChucK I can't figure it out. It's probably something simple, but I thought I'd post my code on here, if someone can be kind enough to point out to me where I've gone wrong...
| Code: |
Hid hid;
HidMsg msg;
Hid Keys;
HidMsg KeyPress;
//which keyboard
0 => int deviceK;
hid.openMouse( 0 );
140 => float bpm; // BPM
(60/bpm)::second => dur crotchet => dur c;;
crotchet*2 => dur minim;
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;
//note array and note lengths
[70,68,66,-9999,70,68,66,-9999,70,68,66,-9999,70,68,70,76] @=> int notes[];
[sq,sq,sq, sq,sq,sq,sq, sq,sq,sq,sq, sq, q,dq,sq,sq] @=> dur duration[];
int i;
int DelayChoose;
SawOsc o1 => HPF f1 => JCRev r1 => Pan2 p => dac;
//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000 => float centre_filter_freq;
//filter resonance
10 => float centre_filter_resonance;
//pan
0 => float central_pan;
//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;
spork~ lfo_to_filter();
spork~ mouse_to_filter( 500, 5000 );
spork~ mouse_to_resonance( 1, 51 );
spork~ mousewheel_to_pan( -1, 1 );
//infinite loop - run through array
while (true)
{
for (0 => int i; i <notes> o1.freq;
duration [i] => now;
}
}
fun void lfo_to_filter()
{
while ( true )
{
(lfo1.last()*500) + centre_filter_freq => f1.freq;
100::ms => now;
}
}
fun void mouse_to_filter( float min, float max )
{
while ( true )
{
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if ( msg.isMouseMotion() )
{
//move mouse on y axis
if ( msg.deltaY )
{
//if mouse is moved up on y axis
if ( msg.deltaY <0> centre_filter_freq;
//do not let filter frequency exceed max value
if ( centre_filter_freq > max )
max => centre_filter_freq;
}
//if mouse is moved down on y axis
if ( msg.deltaY > 0 )
{
//decrease centre filter frequency in increments of 10
10 -=> centre_filter_freq;
//do not let centre filter frequency go beneath min value
if ( centre_filter_freq <min> centre_filter_freq;
}
}
}
}
}
}
fun void mouse_to_resonance( float min, float max )
{
while ( true )
{
centre_filter_resonance => f1.Q;
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if (msg.isMouseMotion() )
{
//move mouse on x axis
if ( msg.deltaX )
{
//if mouse is moved right
if ( msg.deltaX > 0 )
{
//increase centre filter resonance in increments of 5
5 +=> centre_filter_resonance;
//do not let resonance exceed max value
if ( centre_filter_resonance > max )
max => centre_filter_resonance;
}
//if mouse is moved left
if ( msg.deltaX <0> centre_filter_resonance;
//do not let resonance go beneath min value
if ( centre_filter_resonance <min> centre_filter_resonance;
}
//state the values
<<< "Filter FREQUENCY is:", centre_filter_freq, "Filter RESONANCE is:", centre_filter_resonance >>>;
}
}
}
}
}
fun void mousewheel_to_pan( float min, float max )
{
while ( true )
{
central_pan => p.pan;
hid => now;
while ( hid.recv( msg ) )
{
if (msg.isWheelMotion() )
{
if( msg.deltaY )
{
if ( msg.deltaY <0> central_pan;
if ( central_pan > max )
max => central_pan;
}
if ( msg.deltaY > 0 )
{
.1 -=> central_pan;
if ( central_pan <min> central_pan;
}
<<< "Panning is:", central_pan >>>;
}
}
}
}
}
//ECHO 1 Parameters and routing
fun void Echo1()
{
SawOsc o1 => HPF f1 => JCRev r1 => Pan2 pan => Echo e1 => dac;
.25::second => e1.delay;
1::second => e1.max;
2 => e1.mix;
}
//ECHO 2 Parameters and routing
fun void Echo2()
{
SawOsc o1 => HPF f1 => JCRev r1 => Pan2 pan => Echo e2 => dac;
.5::second => e2.delay;
1 ::second => e2.max;
2 => e2.mix;
}
//ECHO 3 Parameters and routing
fun void Echo3()
{
SawOsc o1 => HPF f1 => JCRev r1 => Pan2 pan => Echo e3 => dac;
.75::second => e3.delay;
1 ::second => e3.max;
2 => e3.mix;
}
//Delay Choosings!
30 => DelayChoose; //initial delay when starting!
fun void DelaySelect()
{
while( true )
{
if( DelayChoose == 30 )
{
spork~ Echo1();
100::ms => now;
}
else if( DelayChoose == 31 )
{
spork~ Echo2();
100::ms => now;
}
else if( DelayChoose == 32 )
{
spork~ Echo3();
100::ms => now;
}
}
}
//Keyboard inputs to choose Echo
fun void KeyControl()
{
//get from command line
if( me.args()) me.arg(0) => Std.atoi => deviceK;
if(!Keys.openKeyboard(deviceK)) me.exit();
<<< "keyboard '" + Keys.name() + "' ready", "" >>>;
while( true )
{
Keys => now;
while( Keys.recv(KeyPress) )
{
if( KeyPress.isButtonDown())
{
if( KeyPress.which >= 30 )
{
if( 32 >= KeyPress.which )
{
KeyPress.which => DelayChoose;
<<<"You are now using",KeyPress.which-29>>>;
}
else
{
<<<"Unrecognised parameter, please use 1 - 3","">>>;
}
}
else
{
<<<"Unrecognised parameter , please use 1 - 3","">>>;
}
}
}
}
}
//Run the keyboard function
spork~ KeyControl();
1::week => now;
|
Hopefully you'll be able to see what I'm getting at. One day I'll be able to write code with my eyes closed... one day!
Thanks,
Chris |
|
|
Back to top
|
|
 |
vrachnasormora

Joined: Mar 22, 2007 Posts: 42 Location: Preveza,Greece
|
Posted: Thu Apr 29, 2010 3:03 pm Post subject:
|
 |
|
Hi Chris,
when you first declare and connect UGens like:
| Code: | | SawOsc o1 => HPF f1 => JCRev r1 => Pan2 p => dac; |
break that in two separate lines like:
| Code: | SawOsc o1 => HPF f1 => JCRev r1;
Pan2 p => dac; |
and declare each Echo and their parameters before connecting them to anything:
| Code: | Echo e1;
.25::second => e1.delay;
1::second => e1.max;
2 => e1.mix; |
and so on for Echo e2 and e3.
So don't connect JCRev to Pan2 just yet, because when you are then going to introduce e1,e2,e3 to the signal flow, you can do this:
| Code: | fun void echecker()
{
if ( r1.isConnectedTo(e1) )
{
r1 =< e1;
e1 =< p;
}
if ( r1.isConnectedTo(e2) )
{
r1 =< e2;
e2 =< p;
}
if ( r1.isConnectedTo(e3) )
{
r1 =< e3;
e3 =< p;
}
}
fun void Echo1()
{
r1 => e1 => p;
}
fun void Echo2()
{
r1 => e2 => p;
}
fun void Echo3()
{
r1 => e3 => p;
}
fun void KeyControl()
{
//get from command line
if( me.args()) me.arg(0) => Std.atoi => deviceK;
if(!Keys.openKeyboard(deviceK)) me.exit();
<<< "keyboard '" + Keys.name() + "' ready", "" >>>;
while( true )
{
Keys => now;
while( Keys.recv(KeyPress) )
{
if( KeyPress.isButtonDown())
{
if( KeyPress.which >= 30 && KeyPress.which <= 32 )
{
KeyPress.which => DelayChoose;
<<<"You are now using",KeyPress.which-29>>>;
echecker();
if ( DelayChoose == 30 ) Echo1();
if ( DelayChoose == 31 ) Echo2();
if ( DelayChoose == 32 ) Echo3();
}
else
{
<<<"Unrecognised parameter , please use 1 - 3","">>>;
}
}
}
}
} |
The function I called "echecker" checks if an echo is connected to r1, and if there is, disconnects it.And I didn't use your DelaySelect function because events are probably needed there.Also be aware to leave Pan2 UGen last in the chain just before the DAC;Mind you I didn't run this code but I hope you get the idea. |
|
|
Back to top
|
|
 |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Thu Apr 29, 2010 3:46 pm Post subject:
|
 |
|
Thanks . I'll try and incorporate that into my code and make changes where necessary... Fingers crossed... |
|
|
Back to top
|
|
 |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Thu Apr 29, 2010 4:04 pm Post subject:
|
 |
|
Nearly there I think... though for some reason now I'm getting no audio at all. I'll keep plugging away to try and find out what I've done wrong, though chances are I won't find it as I've been staring at this code for hours now, trying to learn the ropes and debug.
When I try to run it, I get the following error message:
[chuck](via STK): Echo: setDelay parameter is greater than delay length!
...not quite sure what it's complaining about!
Here's the code as it stands now:
| Code: |
Hid hid;
HidMsg msg;
Hid Keys;
HidMsg KeyPress;
//which keyboard
0 => int deviceK;
hid.openMouse( 0 );
140 => float bpm; // BPM
(60/bpm)::second => dur crotchet => dur c;;
crotchet*2 => dur minim;
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;
//note array and note lengths
[70,68,66,-9999,70,68,66,-9999,70,68,66,-9999,70,68,70,76] @=> int notes[];
[sq,sq,sq, sq,sq,sq,sq, sq,sq,sq,sq, sq, q,dq,sq,sq] @=> dur duration[];
int i;
int DelayChoose;
SawOsc o1 => HPF f1 => JCRev r1;
Pan2 p => dac;
//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000 => float centre_filter_freq;
//filter resonance
10 => float centre_filter_resonance;
//pan
0 => float central_pan;
//Echoes
Echo e1;
.25::second => e1.delay;
1::second => e1.max;
.3 => e1.mix;
Echo e2;
.5::second => e2.delay;
1 ::second => e2.max;
.3 => e2.mix;
Echo e3;
.75::second => e3.delay;
1 ::second => e3.max;
.3 => e3.mix;
//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;
spork~ lfo_to_filter();
spork~ mouse_to_filter( 500, 5000 );
spork~ mouse_to_resonance( 1, 51 );
spork~ mousewheel_to_pan( -1, 1 );
//infinite loop - run through array
while (true)
{
for (0 => int i; i <notes> o1.freq;
duration [i] => now;
}
}
fun void lfo_to_filter()
{
while ( true )
{
(lfo1.last()*500) + centre_filter_freq => f1.freq;
100::ms => now;
}
}
fun void mouse_to_filter( float min, float max )
{
while ( true )
{
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if ( msg.isMouseMotion() )
{
//move mouse on y axis
if ( msg.deltaY )
{
//if mouse is moved up on y axis
if ( msg.deltaY <0> centre_filter_freq;
//do not let filter frequency exceed max value
if ( centre_filter_freq > max )
max => centre_filter_freq;
}
//if mouse is moved down on y axis
if ( msg.deltaY > 0 )
{
//decrease centre filter frequency in increments of 10
10 -=> centre_filter_freq;
//do not let centre filter frequency go beneath min value
if ( centre_filter_freq <min> centre_filter_freq;
}
}
}
}
}
}
fun void mouse_to_resonance( float min, float max )
{
while ( true )
{
centre_filter_resonance => f1.Q;
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if (msg.isMouseMotion() )
{
//move mouse on x axis
if ( msg.deltaX )
{
//if mouse is moved right
if ( msg.deltaX > 0 )
{
//increase centre filter resonance in increments of 5
5 +=> centre_filter_resonance;
//do not let resonance exceed max value
if ( centre_filter_resonance > max )
max => centre_filter_resonance;
}
//if mouse is moved left
if ( msg.deltaX <0> centre_filter_resonance;
//do not let resonance go beneath min value
if ( centre_filter_resonance <min> centre_filter_resonance;
}
//state the values
<<< "Filter FREQUENCY is:", centre_filter_freq, "Filter RESONANCE is:", centre_filter_resonance >>>;
}
}
}
}
}
fun void mousewheel_to_pan( float min, float max )
{
while ( true )
{
central_pan => p.pan;
hid => now;
while ( hid.recv( msg ) )
{
if (msg.isWheelMotion() )
{
if( msg.deltaY )
{
if ( msg.deltaY <0> central_pan;
if ( central_pan > max )
max => central_pan;
}
if ( msg.deltaY > 0 )
{
.1 -=> central_pan;
if ( central_pan <min> central_pan;
}
<<< "Panning is:", central_pan >>>;
}
}
}
}
}
fun void echecker()
{
if ( r1.isConnectedTo(e1) )
{
r1 =< e1;
e1 =< p;
}
if ( r1.isConnectedTo(e2) )
{
r1 =< e2;
e2 =< p;
}
if ( r1.isConnectedTo(e3) )
{
r1 =< e3;
e3 =<p> e1 => p;
}
fun void Echo2()
{
r1 => e2 => p;
}
fun void Echo3()
{
r1 => e3 => p;
}
fun void KeyControl()
{
//get from command line
if( me.args()) me.arg(0) => Std.atoi => deviceK;
if(!Keys.openKeyboard(deviceK)) me.exit();
<<< "keyboard '" + Keys.name() + "' ready", "" >>>;
while( true )
{
Keys => now;
while( Keys.recv(KeyPress) )
{
if( KeyPress.isButtonDown())
{
if( KeyPress.which >= 30 && KeyPress.which <32> DelayChoose;
<<<"You are now using",KeyPress.which-29>>>;
echecker();
if ( DelayChoose == 30 ) Echo1();
if ( DelayChoose == 31 ) Echo2();
if ( DelayChoose == 32 ) Echo3();
}
else
{
<<<"Unrecognised parameter , please use 1 - 3","">>>;
}
}
}
}
}
//Run the keyboard function
spork~ KeyControl();
1::week => now;
|
|
|
|
Back to top
|
|
 |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Thu Apr 29, 2010 4:13 pm Post subject:
|
 |
|
| OOPS! Sorry, I forgot to spork in the echecker and echoes! That's done now, and the audio is back, but the keyboard and mousewheel still have no effect... |
|
|
Back to top
|
|
 |
vrachnasormora

Joined: Mar 22, 2007 Posts: 42 Location: Preveza,Greece
|
Posted: Thu Apr 29, 2010 5:08 pm Post subject:
|
 |
|
Hey Chris,
just spork KeyControl() end Echo1() before the main loop
| Code: | spork~ lfo_to_filter();
spork~ mouse_to_filter( 500, 5000 );
spork~ mouse_to_resonance( 1, 51 );
spork~ mousewheel_to_pan( -1, 1 );
spork~ KeyControl();
Echo1();
//infinite loop - run through array |
and next time when you post code please don't forget to check the "Disable HTML in this post" box underneath the text window.Bye |
|
|
Back to top
|
|
 |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Thu Apr 29, 2010 5:17 pm Post subject:
|
 |
|
Ah, sorry - I'll remember next time. Just out of interest, what difference does disabling html do?
Thanks for the help! |
|
|
Back to top
|
|
 |
vrachnasormora

Joined: Mar 22, 2007 Posts: 42 Location: Preveza,Greece
|
Posted: Thu Apr 29, 2010 5:26 pm Post subject:
|
 |
|
| Try reading your last post with code.There are some errors in the for loops and other places and I don't believe you created them.It's just ChucK code mistaken for HTML by the forum engine or something like that. |
|
|
Back to top
|
|
 |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Fri Apr 30, 2010 7:07 am Post subject:
|
 |
|
One final question - Everything seems to work great, but for some reason the mousewheel_to_pan function seems to be not working. I can't really understand why - as far as I can see, there's nothing wrong with the code:
| Code: |
Hid hid;
HidMsg msg;
Hid Keys;
HidMsg KeyPress;
//which keyboard
0 => int deviceK;
hid.openMouse( 0 );
//tempo and note lengths (from Doug's code)
130 => float bpm; // BPM
(60/bpm)::second => dur crotchet => dur c;;
crotchet*2 => dur minim;
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;
//note array and note lengths
[ 70,68,66,-9999,70,68,66,-9999,70,68,66,-9999 ] @=> int notes[];
[ sq,sq,sq, sq,sq,sq,sq, sq,sq,sq,sq, sq ] @=> dur duration[];
int i;
int DelayChoose;
//routing
SawOsc o1 => HPF f1 => JCRev r1;
Pan2 p => dac;
//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000 => float centre_filter_freq;
//filter resonance
10 => float centre_filter_resonance;
//panning position
0 => float central_pan => p.pan;
//Echoes
Echo e1;
.25 ::second => e1.delay;
2 ::second => e1.max;
.7 => e1.mix;
Echo e2;
.5 ::second => e2.delay;
2 ::second => e2.max;
.5 => e2.mix;
Echo e3;
.75 ::second => e3.delay;
2 ::second => e3.max;
.4 => e3.mix;
//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;
spork~ lfo_to_filter();
spork~ mouse_to_filter( 500, 5000 ); //min frequency will be 500, max frequency will be 5000
spork~ mouse_to_resonance( 1, 51 ); //min resonance will be 1, max resonance will be 51
spork~ mousewheel_to_pan( -1, 1 ); //min pan will be hard left, max pan will be hard right
spork~ KeyControl();
Echo1();
//infinite loop - run through array
while ( true )
{
for ( 0 => int i; i <notes.size(); i++ )
{
Std.mtof(notes[i]) => o1.freq;
duration [i] => now;
}
}
//LFO function
fun void lfo_to_filter()
{
while ( true )
{
( lfo1.last()*500 ) + centre_filter_freq => f1.freq;
100::ms => now;
}
}
//Mouse control
fun void mouse_to_filter( float min, float max )
{
while ( true )
{
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if ( msg.isMouseMotion() )
{
//move mouse on y axis
if ( msg.deltaY )
{
//if mouse is moved up on y axis
if ( msg.deltaY < 0 )
{
//increase centre filter frequency in increments of 10
10 +=> centre_filter_freq;
//do not let filter frequency exceed max value
if ( centre_filter_freq > max )
max => centre_filter_freq;
}
//if mouse is moved down on y axis
if ( msg.deltaY > 0 )
{
//decrease centre filter frequency in increments of 10
10 -=> centre_filter_freq;
//do not let centre filter frequency go beneath min value
if ( centre_filter_freq < min )
min => centre_filter_freq;
}
}
}
}
}
}
fun void mouse_to_resonance( float min, float max )
{
while ( true )
{
centre_filter_resonance => f1.Q;
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if ( msg.isMouseMotion() )
{
//move mouse on x axis
if ( msg.deltaX )
{
//if mouse is moved right
if ( msg.deltaX > 0 )
{
//increase centre filter resonance in increments of 5
5 +=> centre_filter_resonance;
//do not let resonance exceed max value
if ( centre_filter_resonance > max )
max => centre_filter_resonance;
}
//if mouse is moved left
if ( msg.deltaX < 0 )
{
//decrease centre filter resonance in increments of 5
5 -=> centre_filter_resonance;
//do not let resonance go beneath min value
if ( centre_filter_resonance < min )
min => centre_filter_resonance;
}
}
}
}
}
}
fun void mousewheel_to_pan( float min, float max )
{
while ( true )
{
central_pan => p.pan;
hid => now;
while ( hid.recv( msg ) )
{
if ( msg.isWheelMotion() )
{
if( msg.deltaY )
{
if ( msg.deltaY < 0 )
{
0.1 +=> central_pan;
if ( central_pan > max )
max => central_pan;
}
if ( msg.deltaY > 0 )
{
0.1 -=> central_pan;
if ( central_pan < min )
min => central_pan;
}
//state the values
<<< "Filter FREQUENCY is:", centre_filter_freq, "Filter RESONANCE is:", centre_filter_resonance, "Panning is:", central_pan >>>;
}
}
}
}
}
fun void echecker()
{
//if reverb is connected to echo, disconnect it - makes sure only 1 delay is connected at any time!
if ( r1.isConnectedTo(e1) )
{
r1 =< e1;
e1 =< p;
}
if ( r1.isConnectedTo(e2) )
{
r1 =< e2;
e2 =< p;
}
if ( r1.isConnectedTo(e3) )
{
r1 =< e3;
e3 =< p;
}
}
//routing for the delays
fun void Echo1()
{
r1 => e1 => p;
}
fun void Echo2()
{
r1 => e2 => p;
}
fun void Echo3()
{
r1 => e3 => p;
}
fun void KeyControl()
{
//get from command line
if( me.args()) me.arg(0) => Std.atoi => deviceK;
//state that keyboard is ready
if(!Keys.openKeyboard(deviceK)) me.exit();
<<< "keyboard '" + Keys.name() + "' ready", "" >>>;
while( true )
{
Keys => now;
//when we recieve a message from the keyboard...
while( Keys.recv(KeyPress) )
{
//when we press down on a key
if( KeyPress.isButtonDown() )
{
if( KeyPress.which >= 30 && KeyPress.which <= 32 )
{
KeyPress.which => DelayChoose;
<<<"You are now using delay",KeyPress.which-29>>>;
echecker();
//echo 1 when key '1' is pressed (ascii value = 30)
if ( DelayChoose == 30 ) Echo1();
//echo 2 when key '2' is pressed (ascii value = 31)
if ( DelayChoose == 31 ) Echo2();
//echo 3 when key '3' is pressed (ascii value = 32)
if ( DelayChoose == 32 ) Echo3();
}
else
{
//if any other keys are pressed, give error message
<<<"Unrecognised parameter , please use 1 - 3","">>>;
}
}
}
}
}
//Run the keyboard function
spork~ KeyControl();
1::week => now;
|
Have I missed something obvious here? It seems like the mousewheel_to_pan function is being bypassed somehow... I've made several attempts in editing the code to get it to work, but no success so far.
Thanks again to all who've helped - it's really helping me with getting to grips with the language of ChucK! Oh, and HTML is disabled this time  |
|
|
Back to top
|
|
 |
vrachnasormora

Joined: Mar 22, 2007 Posts: 42 Location: Preveza,Greece
|
Posted: Fri Apr 30, 2010 10:58 am Post subject:
|
 |
|
Hi again Chris.It seems it wasn't only pan control not working but resonance too.I think the problem was multiple waiting for mouse events "hid => now;" loops.So instead:
| Code: | Hid hid;
HidMsg msg;
Hid Keys;
HidMsg KeyPress;
//which keyboard
0 => int deviceK;
hid.openMouse( 0 );
//tempo and note lengths (from Doug's code)
130 => float bpm; // BPM
(60/bpm)::second => dur crotchet => dur c;;
crotchet*2 => dur minim;
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;
//note array and note lengths
[ 70,68,66,-9999,70,68,66,-9999,70,68,66,-9999 ] @=> int notes[];
[ sq,sq,sq, sq,sq,sq,sq, sq,sq,sq,sq, sq ] @=> dur duration[];
int i;
int DelayChoose;
//routing
SawOsc o1 => HPF f1 => JCRev r1;
Pan2 p => dac;
//osc gain
.5 => o1.gain;
//reverb 'amount'
.1 => r1.mix;
//filter frequency
1000 => float centre_filter_freq;
//filter resonance
10 => float centre_filter_resonance;
//panning position
0 => float central_pan => p.pan;
//Echoes
Echo e1;
.25 ::second => e1.delay;
2 ::second => e1.max;
.7 => e1.mix;
Echo e2;
.5 ::second => e2.delay;
2 ::second => e2.max;
.5 => e2.mix;
Echo e3;
.75 ::second => e3.delay;
2 ::second => e3.max;
.4 => e3.mix;
//lfo oscillator
SinOsc lfo1 => blackhole;
5 => lfo1.freq;
spork~ lfo_to_filter();
spork~ MouseControl( 500, 5000, 1, 51, -1, 1 );
spork~ KeyControl();
Echo1();
//infinite loop - run through array
while ( true )
{
for ( 0 => int i; i <notes.size(); i++ )
{
Std.mtof(notes[i]) => o1.freq;
duration [i] => now;
}
}
//LFO function
fun void lfo_to_filter()
{
while ( true )
{
( lfo1.last()*500 ) + centre_filter_freq => f1.freq;
100::ms => now;
}
}
//Mouse control
fun void MouseControl( float min_f, float max_f, float min_r, float max_r, float min_p, float max_p )
{
while ( true )
{
hid => now;
while ( hid.recv( msg ) )
{
//when we recieve message from mouse motion...
if ( msg.isMouseMotion() )
{
//move mouse on y axis
if ( msg.deltaY )
{
//if mouse is moved up on y axis
if ( msg.deltaY < 0 )
{
//increase centre filter frequency in increments of 10
10 +=> centre_filter_freq;
//do not let filter frequency exceed max value
if ( centre_filter_freq > max_f )
max_f => centre_filter_freq;
}
//if mouse is moved down on y axis
if ( msg.deltaY > 0 )
{
//decrease centre filter frequency in increments of 10
10 -=> centre_filter_freq;
//do not let centre filter frequency go beneath min value
if ( centre_filter_freq < min_f )
min_f => centre_filter_freq;
}
}
if ( msg.deltaX )
{
//if mouse is moved right
if ( msg.deltaX > 0 )
{
//increase centre filter resonance in increments of 5
5 +=> centre_filter_resonance;
//do not let resonance exceed max value
if ( centre_filter_resonance > max_r )
max_r => centre_filter_resonance;
}
//if mouse is moved left
if ( msg.deltaX < 0 )
{
//decrease centre filter resonance in increments of 5
5 -=> centre_filter_resonance;
//do not let resonance go beneath min value
if ( centre_filter_resonance < min_r )
min_r => centre_filter_resonance;
}
centre_filter_resonance => f1.Q;
}
}
if ( msg.isWheelMotion() )
{
if( msg.deltaY )
{
if ( msg.deltaY < 0 )
{
0.1 +=> central_pan;
if ( central_pan > max_p )
max_p => central_pan;
}
if ( msg.deltaY > 0 )
{
0.1 -=> central_pan;
if ( central_pan < min_p )
min_p => central_pan;
}
central_pan => p.pan;
}
}
}
//state the values
<<< "Filter FREQUENCY is:", centre_filter_freq, "Filter RESONANCE is:", centre_filter_resonance, "Panning is:", central_pan >>>;
}
}
fun void echecker()
{
//if reverb is connected to echo, disconnect it - makes sure only 1 delay is connected at any time!
if ( r1.isConnectedTo(e1) )
{
r1 =< e1;
e1 =< p;
}
if ( r1.isConnectedTo(e2) )
{
r1 =< e2;
e2 =< p;
}
if ( r1.isConnectedTo(e3) )
{
r1 =< e3;
e3 =< p;
}
}
//routing for the delays
fun void Echo1()
{
r1 => e1 => p;
}
fun void Echo2()
{
r1 => e2 => p;
}
fun void Echo3()
{
r1 => e3 => p;
}
fun void KeyControl()
{
//get from command line
if( me.args()) me.arg(0) => Std.atoi => deviceK;
//state that keyboard is ready
if(!Keys.openKeyboard(deviceK)) me.exit();
<<< "keyboard '" + Keys.name() + "' ready", "" >>>;
while( true )
{
Keys => now;
//when we recieve a message from the keyboard...
while( Keys.recv(KeyPress) )
{
//when we press down on a key
if( KeyPress.isButtonDown() )
{
if( KeyPress.which >= 30 && KeyPress.which <= 32 )
{
KeyPress.which => DelayChoose;
<<<"You are now using delay",KeyPress.which-29>>>;
echecker();
//echo 1 when key '1' is pressed (ascii value = 30)
if ( DelayChoose == 30 ) Echo1();
//echo 2 when key '2' is pressed (ascii value = 31)
if ( DelayChoose == 31 ) Echo2();
//echo 3 when key '3' is pressed (ascii value = 32)
if ( DelayChoose == 32 ) Echo3();
}
else
{
//if any other keys are pressed, give error message
<<<"Unrecognised parameter , please use 1 - 3","">>>;
}
}
}
}
} |
|
|
|
Back to top
|
|
 |
christorb
Joined: Feb 09, 2010 Posts: 17 Location: Cambridge, UK
|
Posted: Fri Apr 30, 2010 11:45 am Post subject:
|
 |
|
That's awesome. I realise where I've gone wrong now. Instead of having all my mouse control parts as separate functions I should have put them all within one function! It all makes sense now!
You rock,
Thanks for spending so much time on helping me. I'll be attempting to write another ChucK program soon, and this has given me some good foundations to build upon  |
|
|
Back to top
|
|
 |
|