Csound Csound-dev Csound-tekno Search About

[Csnd] Python script for OLPC

Date2009-05-28 19:12
From"Art Hunkins"
Subject[Csnd] Python script for OLPC
Andres, Victor, Brian, Michael et al -

I have worked most of the way through the task of sending key-press events 
in my OLPC Python script to a .csd.

Basically I'm working with the code below, which sends (for my versions 2 
and 4) a keycode (keypress) through the "ascii2" or "ascii4" channels to 
Csound. So far so good - even though these keycodes are completely different 
set of numbers from ASCII codes.

My problem is this: the keycodes are the same for shifted and unshifted 
keypresses. My question: Instead of event.hardware_keycode, is there a 
property of event that can return the *ASCII character* - something like 
"event.hardware_ASCII"?

In some places I need to identify shifted characters.

Otherwise I'm going to have to test keypresses *and keyreleases* for the 
SHIFT key, and incorporate a keyrelease channel into my .csd code. I'd 
rather not introduce this complication  (or do the additional coding).

 def onKeyPress(self, widget, event):
   if self.w.ver == 2:
     self.w.set_channel("ascii2", event.hardware_keycode)
   elif self.w.ver == 4:
     self.w.set_channel("ascii4", event.hardware_keycode)

 def playcsd(self, widget):
   if not self.w.on:
     self.w.on = True
     self.w.play()
     self.but.set_label("STOP !")
     if self.w.ver == 2 or self.w.ver == 4:
       self.connect("key-press-event", self.onKeyPress)

Art Hunkins 


Date2009-06-08 03:26
FromAndres Cabrera
Subject[Csnd] Re: Python script for OLPC
Hi Art

On Thu, May 28, 2009 at 1:12 PM, Art Hunkins wrote:
> Andres, Victor, Brian, Michael et al -
>
> I have worked most of the way through the task of sending key-press events
> in my OLPC Python script to a .csd.
>
> Basically I'm working with the code below, which sends (for my versions 2
> and 4) a keycode (keypress) through the "ascii2" or "ascii4" channels to
> Csound. So far so good - even though these keycodes are completely different
> set of numbers from ASCII codes.
>
> My problem is this: the keycodes are the same for shifted and unshifted
> keypresses. My question: Instead of event.hardware_keycode, is there a
> property of event that can return the *ASCII character* - something like
> "event.hardware_ASCII"?
>
> In some places I need to identify shifted characters.
>
> Otherwise I'm going to have to test keypresses *and keyreleases* for the
> SHIFT key, and incorporate a keyrelease channel into my .csd code. I'd
> rather not introduce this complication  (or do the additional coding).
>

You can have a variable in python which stores the state of the shift
key, and check whether the shift key is currently pressed before
sending the code to Csound.

Cheers,
Andrés