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

Re: [pygame] Determining note duration from midi input



Something's rotten somewhere...
I'll have to check the midi spec and see, but I think timestamps are
part of it. IIRC, the server sends info to the device telling it to
start timestamping relative to a particular time. If this is correct,
then something may be wrong with the lib or your device. If timestamps
are completely in software it may just be the lib. I am curious what
pygame.midi.init does. Perhaps the casio uses a non-standard
initializarion procedure so the timestamp reset isn't being performed.
not really sure though, I'm away from home on my phone. i'll give you
a proper reply once I can get home and look over various source codes
and maybe we can figure out this casio problem.

On 4/3/10, Neilen Marais <nmarais@xxxxxxxxx> wrote:
> Hi Luke
>
> On Fri, Apr 2, 2010 at 7:00 PM, Luke Paireepinart
> <rabidpoobear@xxxxxxxxx> wrote:
>> 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?
>
> There is pygame.midi.get_count() and pygame.midi.get_device_info()
> that  can help. There is a pretty nice example in
> pygame/examples/midi.py that comes with the source distribution.
>
>> 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})>
>
> Hmm, there definitely seems to be something wrong here. No after
> touch, simple "digital piano" (Casio Privia PX-200). The numbers I get
> don't make sense. Using code that I modified from yours
> (http://pastebin.com/kMTt0kQH ), I generated the following output by
> playing a stacato note (i.e. very short duration), followed by a short
> note followed by a long note. As you can see the timestamps make no
> sense! However, looking at the midi event stream in real time, the
> events are created at the right time. i.e. I press a key - key down
> event. Hold - nothing. Release - key up event.
>
> <Event(29-UserEvent {'status': 144, 'vice_id': 3, 'timestamp': -1,
> 'data1': 60, 'data3': 0, 'data2': 95})>
> Key 60 was pressed.
> <Event(29-UserEvent {'status': 128, 'vice_id': 3, 'timestamp': 0,
> 'data1': 60, 'data3': 0, 'data2': 64})>
> Key 60 was held down for 1.
> <Event(29-UserEvent {'status': 144, 'vice_id': 3, 'timestamp': 0,
> 'data1': 60, 'data3': 0, 'data2': 63})>
> Key 60 was pressed.
> <Event(29-UserEvent {'status': 128, 'vice_id': 3, 'timestamp': 2,
> 'data1': 60, 'data3': 0, 'data2': 64})>
> Key 60 was held down for 2.
> <Event(29-UserEvent {'status': 144, 'vice_id': 3, 'timestamp': 0,
> 'data1': 60, 'data3': 0, 'data2': 67})>
> Key 60 was pressed.
> <Event(29-UserEvent {'status': 128, 'vice_id': 3, 'timestamp': 0,
> 'data1': 60, 'data3': 0, 'data2': 64})>
> Key 60 was held down for 0.
> <Event(29-UserEvent {'status': 144, 'vice_id': 3, 'timestamp': 0,
> 'data1': 60, 'data3': 0, 'data2': 92})>
> Key 60 was pressed.
> <Event(29-UserEvent {'status': 128, 'vice_id': 3, 'timestamp': -1,
> 'data1': 60, 'data3': 0, 'data2': 64})>
> Key 60 was held down for -1.
>
>> 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.
>
> As far as I can tell it's a work-alike that is supposed to be faster
> (http://www.pygame.org/wiki/todo#fastevent%20as%20default%20event%20module
> ). I simply used it because that is what the included pygame example
> code used. More info
> (http://dev.laptop.org/~mcfletch/OLPCGames/pydoc/pygame.fastevent.html
> )
>
>> 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'm using pygame 1.9.1. Conversely, I found that your code that used
> the  normal event did not work. Digging deeper it seems that the
> pygame.midi is buggy in the sense that it uses an event number that is
> bigger than pygame.NUMEVENTS, causing them to be ignored. By changing
> the pygame/midi.py source to use a lower event number, both
> pygame.event and pygame.fastevent works for me.
>
>> What do you think?
>
> Would have been great it it worked for me! Well, it seems like there
> is some problem with my hardware or some other software component
> between pygame and the hardware.  Would you agree? I'm pretty sure the
> basic hardware and drivers work though, since I tested recording with
> rosegarden and it seemed to work quite well!
>
> Thanks
> Neilen
>

-- 
Sent from my mobile device