Page 1 of 1

DirectEvent strange error

Posted: Thu Jul 24, 2008 5:52 am
by Roger
Hello!

Just bought my Modul8, and was very happy with the scripting until I tried DirectEvent. It always shows an error that apparently shouldn't be there.

I shortened my script to just this, so I can show the error:

Code: Select all

print 'param=', param
message = param['message']
param1 = param['param1']
param2 = param['param2']
print 'message=', message, 'param1=', param1, 'param2=', param2


When I restart the module, the error window shows up complaining about line 2:

Code: Select all

Runtime error in "VaiVendo script" (DirectEvent) at line 2:
KeyError: 'message'


But the outuput on the console seems OK, the message variable is set:

Code: Select all

param= {'timestamp': 22866874564392.0, 'channel': 1, 'param1': 19, 'message': 'CONTROL_CHANGE', 'rawEvent': 176, 'param2': 127}
message= CONTROL_CHANGE param1= 19 param2= 127


If i try to get param1 first, it will complain about param1 and not about the others. The 1st param I try to get always give me this error.
What is wrong?
Is it a bug?

BTW, i'm using Modul8 2.5.6

Thanks...

Re: DirectEvent strange error

Posted: Tue Jul 29, 2008 11:39 am
by david
Hello Roger,

Roger wrote:Hello!

Just bought my Modul8, and was very happy with the scripting until I tried DirectEvent. It always shows an error that apparently shouldn't be there.

I shortened my script to just this, so I can show the error:

Code: Select all

print 'param=', param
message = param['message']


Code: Select all

Runtime error in "VaiVendo script" (DirectEvent) at line 2:
KeyError: 'message'

What is wrong?
Is it a bug?


param is a Python dictionnary, but its content depends on the type of the received DirectEvent. So when you are receiving KEYDOWN/KEYUP messages, the dictionnary is not containing the 'message' value.

So you could use something like this for parsing Midi direct event :

Code: Select all

if type == 'MIDI':
   print ' param=', param
   message = param['message']
   param1 = param['param1']
   param2 = param['param2']
   print 'message=', message, 'param1=', param1, 'param2=', param2


David