Csound Csound-dev Csound-tekno Search About

Re: [Csnd] Sensekey and ASCII key-up

Date2011-07-08 20:49
From"Art Hunkins"
SubjectRe: [Csnd] Sensekey and ASCII key-up
And a big thanks from me for all those who responded with suggestions both 
for my ASCII key-up issue and the k-time filelen bugaboo.

My solutions:
To ASCII key-up
Abandon (Lou's solution ;) ) as too difficult to implement cross-platform 
and in various GUI settings. I'm fine just with triggering samples and 
letting them play out (stopping them prematurely would have been the point 
of "key-up"; a second ASCII key-down to stop prematurely was even more 
impractical).

To k-time filelen
Reinit was the winner here. It had been a long time since I'd used reinit, 
and once I got the format clear in my mind again, it works wondrously. I 
really struggled with a table solution; I know this should also work, but it 
wasn't doing so for me this past week. Coding-wise the reinit is more 
compact as well, if not more efficient.

Again, many thanks.

Art Hunkins

----- Original Message ----- 
From: "joachim heintz" 
To: 
Sent: Friday, July 08, 2011 3:13 PM
Subject: Re: [Csnd] Sensekey and ASCII key-up


> thanks!
> j
>
> Am 08.07.2011 20:41, schrieb Justin Smith:
>> As I mentioned in another message, the ansi terminal protocol does not
>> have any way to provide keyup info. since qtecsound uses the windowing
>> system for input rather than an ansi terminal, it can get keyup events.
>>
>> ----- Original message -----
>>> very cool ... i have installed pygame on ubuntu 10.10 via the synaptic
>>> package manager, and your .csd worked perfectly.
>>> what i cannot understand right now: i have a simple .csd (see
>>> attachment) which works perfectly in qutecsound, but not in the
>>> terminal. in qutecsound i get the "space bar released" as expected, but
>>> not in the terminal. this is not related to the automatic key
>>> repetitions - i disabled it before. i have tested it on ubuntu and osx,
>>> it's the same. does anyone know what is different here between
>>> qutecsound and the terminal in this respect?
>>> in general, it would be nice if we could have a "keyup" opcode like, for
>>> instance, in pd.
>>>
>>>     joachim
>>>
>>>
>>>
>>> Am 08.07.2011 10:24, schrieb Tarmo Johannes:
>>> > Hello,
>>> >
>>> > there can be one solution - one thing that makes csound really
>>> > unlimited is the possibility to embed python programming and thususe
>>> > python modules -  so basically you can do whatever.
>>> >
>>> > See a great article about it by Andrés Cabrera at
>>> > http://www.csounds.com/journal/issue6/pythonOpcodes.html
>>> >
>>> > I made a quick search and first python library that enables reading
>>> > key-releases is pygame http://pygame.org/docs/index.html It was very
>>> > easy to install on linux, I assume it should not be a prblem in  OSX
>>> > or Windows.
>>> >
>>> > A little drawback is that pygame needs to create a separate window and
>>> > you have to click on it to tell the module to read the keys. It can be
>>> > very clumsy when you have to do something for example with qutecsound
>>> > widgets. It is just an example, I am sure there must be also a way to
>>> > read raw keyboard events.
>>> >
>>> > here is the example (+ in attachment for any case):
>>> >
>>> > --------
>>> > 
>>> > 
>>> > -odac -d
>>> > 
>>> > 
>>> >
>>> > sr=44100
>>> > ksmps=32
>>> > nchnls=2
>>> > 0dbfs=1
>>> >
>>> > ; python in csound -
>>> > http://www.csounds.com/journal/issue6/pythonOpcodes.html ;pygame -
>>> > http://pygame.org/docs/
>>> >
>>> > pyinit
>>> > ; a strange thing about pyrun - the next line and last }} have to be
>>> > in the beginning of line, not indented pyruni {{
>>> > import pygame
>>> > from pygame.locals import *
>>> >
>>> > pygame.init()
>>> > pygame.display.set_caption('ESC to close!')
>>> > screen = pygame.display.set_mode((200, 20), )
>>> > }} ; this opens a small window, you have to focus to that (klick on
>>> > it), otherwise the keys are not read
>>> >
>>> >
>>> > instr 1
>>> >
>>> >     pyrun {{
>>> > key=0.0
>>> > keypress=0.0
>>> > keylift=0.0
>>> > for event in pygame.event.get():
>>> > if (event.type == KEYDOWN):
>>> >     key=float(event.key)
>>> >     keypress=1.0
>>> >     if (event.key == K_ESCAPE):
>>> > pygame.display.quit()
>>> >
>>> > if (event.type == KEYUP):
>>> >     key=float(event.key)
>>> >     keylift=1.0
>>> > }}
>>> >     kkeypress pyeval "keypress"
>>> >     kkeylift pyeval "keylift"
>>> >     kkey pyeval "key"
>>> >
>>> >     if (kkeypress==1 && kkey!=27) then ; 27 -ESCAPE key used for
>> closing
>>> > the window        printks "Key %d pressed",1,kkey
>>> >         Sline1 sprintfk "i 2.%d 0 -1 %f",kkey,kkey*2 ;make the
>> instrument
>>> > number in form 2. to be able to turn it off later
>> scoreline
>>> > Sline1, kkeypress        pyassign "keypress",0 ; reset the flag
>>> >     endif
>>> >
>>> >     if (kkeylift==1 ) then
>>> >         printks "Key %d lifted",1, kkey
>>> >         Sline2 sprintfk "i -2.%d 0 0 ",kkey ; turn the not according
>> to key
>>> > off        scoreline Sline2, kkeylift
>>> >         pyassign "keylift",0 ; reset
>>> >     endif
>>> >
>>> > endin
>>> >
>>> >
>>> > instr 2
>>> >     ifreq=p4
>>> >     kenv madsr 0.2, 0.3, 0.5,0.5 ;
>>> >     asig oscil kenv, ifreq, 1
>>> >     outs asig,asig
>>> > endin
>>> >
>>> >
>>> > 
>>> > 
>>> > f 1 0 8192 10 1 0.6 0.7 0.4 0.3 0.2 ; sine with some harmonics
>>> >
>>> > i 1 0 60
>>> >
>>> > 
>>> > 
>>> >
>>> >
>>> > ---------
>>> >
>>> > greetings,
>>> > tarmo
>>> >
>>> >
>>> > On Wednesday 06 July 2011 18:38:50 Louis Cohen wrote:
>>> > > I had the same experience on MacOSX, with MacCsound and QTCsound. I
>>> > > gave up trying to sense when a key is released, and found a
>>> > > different    musical solution.
>>> > >
>>> > > At one point I thought of using FLTK, which had somewhat more
>>> > > promising support of the keyboard. But other problems about FLTK
>>> > > were    too hard to deal with, so I just decided that great art
>>> > > didn't always    need to know when a key was released.
>>> > >
>>> > > -Lou
>>> > >
>>> > > On Jul 5, 2011, at 7:29 PM, Art Hunkins wrote:
>>> > >
>>> > > > I've been working with sensekey again, and find that sensekey
>>> > > > cannot    tell me when an ASCII key is released. Indeed all it 
>>> > > > does
>>> > > > is    identify a key*press*.
>>> > > >
>>> > > > I had thought that the kdown parameter could tell me when a key is
>>> > > >    released, but no; a test shows that all parameter activity is 
>>> > > > at
>>> > > > the    keypress, none at the release. (Sensekey shows all data
>>> > > > emanating at    "keypress time".)
>>> > > >
>>> > > > Of course, perhaps this is just the way ASCII keyboards work (I've
>>> > > >    tried two of them on my Windows XP; same "action"). Though I'm
>>> > > > not    sure how keyboard repeat would work without knowledge that 
>>> > > > a
>>> > > > key was    being held down.
>>> > > >
>>> > > > I've also tried multiple delay and repeat options under my
>>> > > > Accessibility settings; the basic fact remains: a message is sent
>>> > > > out when a key goes down, and nothing when it is released. The
>>> > > > ASCII    info *immediately* returns to "zero" as soon as the
>>> > > > keystroke is    registered.
>>> > > >
>>> > > > Am I missing anything here, or is "ASCII key-up" a non-starter?
>>> > > >
>>> > > > Art Hunkins
>>> > > >
>>> > > >
>>> > > > Send bugs reports to the Sourceforge bug tracker
>>> > > > https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> 
>>> > > > Discussions of bugs and features can be posted here
>>> > > > To unsubscribe, send email sympa@lists.bath.ac.uk
>>  with body
>>> > > > "unsubscribe csound"
>>> > > >
>>> > >
>>> > >
>>> > >
>>> > > Send bugs reports to the Sourceforge bug tracker
>>> > > https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> 
>>> > > Discussions of bugs and features can be posted here
>>> > > To unsubscribe, send email sympa@lists.bath.ac.uk
>>  with body
>>> > > "unsubscribe csound"
>>> > >
>>> > >
>>> >
>>> > Send bugs reports to the Sourceforge bug tracker
>>> > https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> 
>>> > Discussions of bugs and features can be posted here
>>> > To unsubscribe, send email sympa@lists.bath.ac.uk
>>  with body
>>> > "unsubscribe csound"
>>> >
>>>
>>> Send bugs reports to the Sourceforge bug tracker
>>>
>> https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> 
>>> Discussions of bugs and features can be posted here
>>> To unsubscribe, send email sympa@lists.bath.ac.uk
>>  with body "unsubscribe
>>> csound"
>>>
>>
>>   KeyOnce.csd
>>
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
> csound"
> 



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"