using PyCall on an event stream

79 views
Skip to first unread message

Forrest Curo

unread,
Nov 29, 2015, 1:35:54 AM11/29/15
to julia...@googlegroups.com
I get the following:
"
julia> using PyCall

julia> @pyimport mido

julia> inp = mido.open_input("Q25 MIDI 1")
PyObject <open input 'Q25 MIDI 1' (PortMidi/ALSA)>

julia> for msg in inp
       print(msg)
       end
PyObject <message note_on channel=0 note=59 velocity=91 time=0>
-------------
What follows this last prompt: The for loop is quoting a python program which prints out midi messages as received...

Whatever Julia is doing with this... leads to printing out the previous midi message. That is, the last line here appears when I lift my finger off the key. (The note-off will appear when I play the next note.)

Why isn't this working? -- and what function might work better to get inp's current value, not the next-to-last?

Steven G. Johnson

unread,
Nov 29, 2015, 8:15:40 AM11/29/15
to julia-users
Is this in the Julia REPL?

Forrest Curo

unread,
Nov 29, 2015, 5:44:23 PM11/29/15
to julia...@googlegroups.com
Okay, I wrote the following python script as mymid.py :

"
import mido
import time
def mcatch(msg):
    print (msg)
       
inp = mido.open_input('Q25 MIDI 1', callback=mcatch)
while(True):
    time.sleep(100)
"

and copied it to /usr/lib/python2.7
-----------
This now works:

julia> using PyCall

julia> @pyimport mymid
note_on channel=0 note=59 velocity=87 time=0
note_off channel=0 note=59 velocity=64 time=0
...

Forrest Curo

unread,
Dec 1, 2015, 4:05:57 PM12/1/15
to julia-users


On Sunday, November 29, 2015 at 5:15:40 AM UTC-8, Steven G. Johnson wrote:
Is this in the Julia REPL?

Yes.

I've since found a better approach which I'm going to post as a new topic!
Reply all
Reply to author
Forward
0 new messages