Csound Csound-dev Csound-tekno Search About

pythonAPI: passing midi

Date2006-03-18 16:26
FromAtte André Jensen
SubjectpythonAPI: passing midi
Hi

I looked at the .py files in examples and it mostly makes sense. But 
supposed I have recieved (or generated) a midi message in python, how do 
I send it to csound?

I understand Iain is doing something like what is in wxController.py:

self.csound.InputMessage("i 1 0 8 %i 70" % self.pitch)

However I'd like to use the dynamic voice allocation facility of csound, 
so I would rather pass on the midi messages...

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-03-18 17:15
FromIstvan Varga
SubjectRe: pythonAPI: passing midi
AttachmentsNone  

Date2006-03-18 18:07
FromAtte André Jensen
SubjectRe: pythonAPI: passing midi
Istvan Varga wrote:

> or send MIDI messages using some sort of MIDI
> loopback device.

Do you mean alsa -> python -> alsa -> csound?

I can create a midi device from pyton that's seen by csound:

The available MIDI in devices are:
    0: Midi Through Port-0 (ALSA)
    1: MCS Out (ALSA) <- Mine

So simply starting csound from within python with "-M 1", is that what 
you mean?

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-03-19 02:47
FromIain Duncan
SubjectRe: pythonAPI: passing midi
> I looked at the .py files in examples and it mostly makes sense. But
> supposed I have recieved (or generated) a midi message in python, how do
> I send it to csound?
> 
> I understand Iain is doing something like what is in wxController.py:
> 
> self.csound.InputMessage("i 1 0 8 %i 70" % self.pitch)
> 
> However I'd like to use the dynamic voice allocation facility of csound,
> so I would rather pass on the midi messages...

If you want to handle midi input from your host, as I do, I personally
suggest C++, but maybe things are better since I last looked. When I
hunted around about six months ago none of python real time midi
libraries looked ready, that may have changed. I found it not too
difficult to get real time midi input working with portmidi and C++.

Iain

Date2006-03-20 03:47
FromIain Duncan
SubjectRe: pythonAPI: passing midi
> Currently, you can only send MIDI messages to, and receive from Csound with
> a C or C++ host, as these require using callback functions for which Python
> and Java wrappers are not implemented yet.
> So, you can either use real time score events with Csound::InputMessage() or
> Csound::ScoreEvent() (note also the software bus interfaces for sending and
> receiving control signals), or send MIDI messages using some sort of MIDI
> loopback device.

Is there much of a performance difference on the csound end between the
two? Seems like input message would require more parsing, but I don't
know the internal well enough to know if that matters.

Thanks
Iain

Date2006-03-20 03:52
FromIain Duncan
SubjectRe: pythonAPI: passing midi
Atte, what kind of voice allocation are you wanting? That is always one
of the problems of real time control, even with hardware. ( droped midi
notes yay! hung midi notes, yay! ) In order to always *know* that we are
within our cpu use goals we need some sort of hard polyphony top out,
but how that is handled is pretty open.

I was thinking I could implement one for an api example using midi
input. If you are a pianist, I guess the most pianistic is:

- only one instance of an active note per pitch
- subsequent notes of a pitch cut off previous ones
- notes release after finger release ( imagine pedalling )
- potentially all playable notes could be releasing at the same time
  ( sweep keyboard with pedal down )

You also said you want to be able to switch sounds of a split correct?

Iain

Atte André Jensen wrote:
> Hi
> 
> I looked at the .py files in examples and it mostly makes sense. But
> supposed I have recieved (or generated) a midi message in python, how do
> I send it to csound?
> 
> I understand Iain is doing something like what is in wxController.py:
> 
> self.csound.InputMessage("i 1 0 8 %i 70" % self.pitch)
> 
> However I'd like to use the dynamic voice allocation facility of csound,
> so I would rather pass on the midi messages...
> 

Date2006-03-22 18:11
FromIstvan Varga
SubjectRe: pythonAPI: passing midi
AttachmentsNone  pymidi.py  pymidi.csd  

Date2006-03-23 08:19
FromAtte André Jensen
SubjectRe: pythonAPI: passing midi
Istvan Varga wrote:

> Some new code has just been added to the CVS sources that makes it possible
> to send MIDI messages to, and receive from Csound using the Python wrappers.
> The attached simple example shows sending MIDI input from Python.

That looks very nice, thanks! I'll look into it asap. I tried to run the 
attached example like this:

[atte@aarhus ace]$ python pymidi.py -o devaudio pymidi.csd
Localisation of messages is disabled, using default language.
time resolution is 0.417 ns
Exception in thread Thread-1:Traceback (most recent call last):
   File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap
     self.run()
   File "/usr/lib/python2.3/threading.py", line 422, in run
     self.__target(*self.__args, **self.__kwargs)
   File "pymidi.py", line 60, in guiThread
     w.mainloop()
   File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 965, in mainloop
     self.tk.mainloop(n)
RuntimeError: Calling Tcl from different appartment

This plays 4 C's in accending octaves, so I guess the midi part of the 
example is working. Should I just forget about the tkinter stuff? I'm 
using wxpython, so unless there's a point that I should understand 
besides tkinter, I might forget about the errors, or...?

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-03-23 09:51
FromIstvan Varga
SubjectRe: pythonAPI: passing midi
AttachmentsNone  

Date2006-03-23 10:04
FromAtte André Jensen
SubjectRe: pythonAPI: passing midi
Istvan Varga wrote:

> Probably yes. The GUI was added only to show using a separate audio
> thread with CsoundPerformanceThread and redirecting the Csound message
> output.

Ok. Thanks again!

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-03-23 18:27
FromIstvan Varga
SubjectRe: pythonAPI: passing midi
AttachmentsNone