[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Lightning Talk Timer



Hi Noel,

This is what im doing now. I thought i could save a few ms. :)

everything works well except the keyboard routine (where the MIDI keyboard is played via the computer keyboard) which has intermittent stuck notes. Very rare but still intermittent stuck notes. I thought this could be cause the keyboard tracking was lagging due to some reason. Will do a bit more debugging.....

Thank you very much for the response.
Â


On Tue, Apr 15, 2014 at 11:55 PM, Noel Garwick <noel.garwick@xxxxxxxxx> wrote:
Hi Diliup,

I believe that there is a slight gain in performance when using set_allowed so that only certain events are added to the queue. ÂI have never profiled it, but I doubt that it's terribly more efficient. I would just do the usual method of polling for events each loop, tracking the held keys, and handling them appropriately, and see if that meets your requirements. ÂFor your case, you may not really have to track held keys, and could just run a function to turn tones on if a key pressed, and off when it is released:

while True:

  tslf = fpsClock.tick( FPS )

  for event in pygame.events.get():
    if event.type == KEYDOWN:
      if event.key == K_q:
        play_tone( q )
      elif event.key == K_2:
        play_tone( 2 )
      .....
    elif event.type == KEYUP:
      if event.key == K_q:
        stop_tone( q )
      elif event.key == K_2:
        stop_tone( 2 )

  # draw and update buttons here...

  pygame.display.update()

Thank you,
Noel


On Tue, Apr 15, 2014 at 9:25 AM, diliup gabadamudalige <diliupg@xxxxxxxxx> wrote:
not sure if this is correct to do but I have a question re. Pygame.

Is it faster to set the number of keys being scanned rather than scanning the entire keyboard, mouse etc. when getting input in Pygame. I mainly need the mouse, arrow keys, , q,2,w,3,e,r,5,t,6,y,7,u,i9,o,0,p,,[,=,] keys ( to simulate a 1 1/2 octave MIDI keyboard), the space bar and the Esc keys only which are a lot less than the whole lot. Can I Limit to only these keys with Pygame.event.set_allowed()
or
is there a better way to do this?

Please pardon if i asked the question in the wrong place.


On Wed, Mar 19, 2014 at 10:05 PM, Renà Dudfield <renesd@xxxxxxxxx> wrote:
Very cool :)Â Thanks for sharing.



--
Diliup Gabadamudalige


http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************





--
Diliup Gabadamudalige


http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************