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
Question about Using Laptop Keyboard as a Controller
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
tz877398



Joined: May 03, 2018
Posts: 2
Location: west chester, pa

PostPosted: Thu May 03, 2018 12:43 pm    Post subject: Question about Using Laptop Keyboard as a Controller Reply with quote  Mark this post and the followings unread

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! Smile
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Thu May 03, 2018 4:31 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
tz877398



Joined: May 03, 2018
Posts: 2
Location: west chester, pa

PostPosted: Thu May 03, 2018 5:11 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Fri May 04, 2018 1:04 am    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
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 [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


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