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
  Just in: Chez mosc with Twyndyllyngs tonight... Chez Mosc
Please visit the chat
 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: 22569
Location: The Netherlands, Enschede
Audio files: 220
G2 patch files: 319

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
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: 22569
Location: The Netherlands, Enschede
Audio files: 220
G2 patch files: 319

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
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
e-m mkii

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