Author |
Message |
tz877398
Joined: May 03, 2018 Posts: 2 Location: west chester, pa
|
Posted: Thu May 03, 2018 12:43 pm Post subject:
Question about Using Laptop Keyboard as a Controller |
|
|
Hi everyone! It's my first time here. I'm pretty new at chuck, just started this January when I enrolled in a class that teaches it. For my final project, I'm using my laptop keyboard as a controller. (for example, when I press the Z key, a C is sounded. When I press the S key, a C# is sounded).
Here is the a simplified version of the code I am working on, with only Z and S keys involved:
Code: | SqrOsc s => dac;
0 => s.gain;
Hid hi;
HidMsg msg;
0 => int device;
if( me.args() ) me.arg(0) => Std.atoi => device;
if (!hi.openKeyboard( device ) ) me.exit();
while ( true ){
hi => now;
while ( hi.recv( msg ) ){
if( msg.isButtonDown() ){
if (msg.which == 29){//Press Z
Std.mtof(48) => s.freq;//Play a C
0.2 => s.gain;
}
if (msg.which == 22){//Press S
Std.mtof(49) => s.freq;//Play a C#
0.2 => s.gain;
}
}
if (msg.isButtonUp() ){ 0 => s.gain;//when a key goes up, silence
}
}
} |
My big question I am trying to figure out: If I release any key my gain goes back to 0. For example, I can press Z, hold it down, press S, now with two keys held down a C# is sounding. This is how I want it. But, if I release Z, even if I am still holding down S, my gain goes back to zero. I want the C# to be sounding until I release it's corresponding key, regardless of if a different key is released. Do any of you guys have any ideas about how I can accomplish this? Thanks in advance! |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Thu May 03, 2018 4:31 pm Post subject:
|
|
|
Welcome,
For a school thingie eh .. okay .. a hint then :-)
Assuming that for msg.IsButtonUp there also is a msg.which identifying which key went up ... you could keep state for the keys you'd want to handle. The state could could be or could include which key was the last one pressed (assuming you want last note priority, but there are more possible schemes once you keep state, possibly a per key state). _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
tz877398
Joined: May 03, 2018 Posts: 2 Location: west chester, pa
|
Posted: Thu May 03, 2018 5:11 pm Post subject:
|
|
|
Blue Hell wrote: |
Assuming that for msg.IsButtonUp there also is a msg.which identifying which key went up ... you could keep state for the keys you'd want to handle. The state could could be or could include which key was the last one pressed (assuming you want last note priority, but there are more possible schemes once you keep state, possibly a per key state). |
I think I understand what you are telling me, but I'm not quite sure how to use msg.isButtonUp for a specific key... any time i use if(msg.isButtonUp()) 0 => s.gain it sets the gain to 0, regardless of which button goes up. Are there other commands i'm not aware of?
I'm planning on meeting with my professor tomorrow, but i'm not certain he will know the answer either...he is a composer of electronic and computer music but from my understanding he is still learning how to use chuck as well. he encouraged the class to post on forums if we had any questions. |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Fri May 04, 2018 1:04 am Post subject:
|
|
|
How about ...
Code: |
if( msg.isButtonUp() ){
if (msg.which == 29){ //Released Z
// etc ...
|
... I would expect that to work. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
|