Csound Csound-dev Csound-tekno Search About

Re: pythonAPI: passing midi

Date2006-03-18 21:37
From"Michael Gogins"
SubjectRe: pythonAPI: passing midi
This example DOES use the dynamic voice allocation facility, which is 
automatic.

Regards,
Mike
----- Original Message ----- 
From: "Atte André Jensen" 
To: 
Sent: Saturday, March 18, 2006 11:26 AM
Subject: [Csnd] pythonAPI: 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
> -- 
> Send bugs reports to this list.
> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
> 

Date2006-03-20 08:04
FromAtte André Jensen
SubjectRe: pythonAPI: passing midi
Michael Gogins wrote:
> This example DOES use the dynamic voice allocation facility, which is 
> automatic.

Ok, my fault.

What I meant was that AFAICS it will take at least some coding to get 
the same behaviour with score events that is automatically there with 
midi events. For instance that "press note A, press note B, release note 
A, release note B" works "as expected" that is like on a piano.

But I very rarely use score events so maybe I should play a bit with it 
and see what happens...

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-03-20 09:55
FromOeyvind Brandtsegg
SubjectRe: pythonAPI: passing midi
The following is my simplified csound code to do polyphonic instrument on/off.
You asked about how to do this from the host (e.g. python),
the example does show how I can treat midi events and score events in a relatively similar way.

The instrument to be played contains an amp envelope that uses e.g. linenr to create a release segment for the envelope. The linenr opcode gently allows both score (defined p3) and realtime (infinite p3).

The midi note number is used to set a fractional instr number, and this give you control over which specific note you want to turn off when you release a midi key.
I would expect a click problem to occur when playing rapid notes on the same key,
but it does not sound like that is happening for me.
If this becoes a problem, you might use an additional fractonal "counter" to separate different instances of the same key on the same instrument.

Also, the example does not differentiate between midi channels (e.g. all midi channels are routed to the same instr. This could easily be coded..

csound code below.
best
Oeyvind
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

instrNum	= 1004		; instrument to play midi notes

kstatus, kchan, kdata1, kdata2 midiin
if kstatus == 144 kgoto noteon
kgoto end

noteon:
knum	= kdata1
kvel	= kdata2
if kvel == 0 kgoto noteoff
; fractional instrument number, poly voice handling id
kinstrNum = instrNum + (kdata1*0.001)	
event "i", kinstrNum, 0, -1, knum, kvel
kgoto end

noteoff:
knum	= kdata1
kvel	= kdata2
; fractional instrument number, poly voice handling id
kinstrNum = instrNum + (kdata1*0.001)	
event "i", -kinstrNum, 0, 0.1, knum, kvel
kgoto end

end:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Date2006-03-20 11:49
FromAtte André Jensen
SubjectRe: pythonAPI: passing midi
Oeyvind Brandtsegg wrote:

> csound code below.

Thanks. That looks interresting, will have a look!

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-03-21 03:45
FromIain Duncan
SubjectRe: pythonAPI: passing midi
> The instrument to be played contains an amp envelope that uses e.g. linenr to create a release segment for the envelope. The linenr opcode gently allows both score (defined p3) and realtime (infinite p3).

That is similar to how I do my instruments as well.

> The midi note number is used to set a fractional instr number, and this give you control over which specific note you want to turn off when you release a midi key.
> I would expect a click problem to occur when playing rapid notes on the same key,
> but it does not sound like that is happening for me.
> If this becoes a problem, you might use an additional fractonal "counter" to separate different instances of the same key on the same instrument.

The way I solve is a bit hackish but works very well for pianistic and
legato sounds. By having one voice per potential note of polyphony, you
can have an amp envelope instrument always on for each voice. A release
triggers the release phase of the envelope. The amp envelope keeps track
of what is happening and if it is getting clobbered by a subsequent note
( the desired behaviour ) instead of just starting a new note, it's amp
envelope can very quickly go to zero and then back on. I use this
technique to make monosynths, but it could easily be adapted for piano
like sounds. You would have the overhead of 88  amp envelopes constantly
running, but if this is meant to be an ideal situation for one player, I
don't think that would be a big deal. It would mean that your cpu load
would not spike no matter what you did on the piano, so perhaps that
would be good.

I think I may muck about with that scheme and pormidi to make an api
example for realtime pianistic playing, it would be an interesting
example in a number of ways and probably useful.

Iain