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

Re: [pygame] Re: Determining note duration from midi input





On Fri, Apr 2, 2010 at 7:05 AM, Neilen <nmarais@xxxxxxxxx> wrote:
Hi Luke

On Apr 2, 11:21 am, Luke Paireepinart <rabidpoob...@xxxxxxxxx> wrote:
> On Fri, Apr 2, 2010 at 3:46 AM, Neilen <nmar...@xxxxxxxxx> wrote:
> > Hi,
>
>
> > Can you create a minimal version of your code and post it to pastebin or
> something?
> I've never used pygame.midi before but I've used midi for a lot of things,
> so I might be able to help.

Thanks!

Code is here: http://pastebin.com/MfB1GgmP

Please excuse the hard coded device numbers, just some rough
experimental code. It is essentially a reduced version of the pygame
examples/midi.py input case. The loop basically checks the pygame
event queue, handles any events and then polls the midi device. Any
midi events found are pushed onto the pygame queue. I (as an
experiment) added the absolute timestamp (variable mt). Would have
been better to include that in the event data for "real" code of
course.


No problem.
I just changed 'casio_i' until it started reading midi data from my keyboard.  my ID was 1.  how did you figure out your ID's? trial and error?

I'm not sure if your keyboard has aftertouch, but you basically had the right idea.   I'm not sure why you think timestamp is wrong.  Do you get keyup's when you release the key?  your keyboard may force sending keyups before the key is actually released.

Here's some event data from my keyboard (playing 2 notes of different lengths):
<Event(34-Unknown {'status': 144, 'vice_id': 1, 'timestamp': 2105, 'data1': 72, 'data3': 0, 'data2': 66})>
<Event(34-Unknown {'status': 128, 'vice_id': 1, 'timestamp': 2390, 'data1': 72, 'data3': 0, 'data2': 64})>
<Event(34-Unknown {'status': 144, 'vice_id': 1, 'timestamp': 4633, 'data1': 69, 'data3': 0, 'data2': 66})>
<Event(34-Unknown {'status': 128, 'vice_id': 1, 'timestamp': 9216, 'data1': 69, 'data3': 0, 'data2': 64})>


Also I dont' think you're registering the events properly because I'm unable to actually use the event like a normal event.

....
Yeah, could you specify which version of pygame you're using?
I'm not sure what 'fastevent' is, I can't find it in the docs.  I'm suspecting it's broken in my pygame version because the events you were registering I wasn't able to access their data meembers.I could check if e.type was pygame.midi.MIDIIN but I couldn't do e.status or e.data1.

Here's the modified code...  notice I changed your post method.
http://pastebin.com/bxUdu2F3

And here's the output:
F:\Media\Music>python miditest.py
Key 67 was pressed.
Key 67 was held down for 1824.
Key 69 was pressed.
Key 69 was held down for 34.
Key 71 was pressed.
Key 71 was held down for 86.
Key 72 was pressed.
Key 72 was held down for 71.


What do you think?

-Luke