BelaPlatform / Bela

Bela: core code, IDE and lots of fun!
Other
494 stars 139 forks source link

Support for simultaneous MIDI controllers with Csound on Bela. The portaudio -Ma command line flag #636

Open csounder opened 4 years ago

csounder commented 4 years ago

In Csound, under portaudio, one can use multiple MIDI controllers at the same time. A number of my students are wanting to do that with their Csound instruments running on the Bela, but for some reason, we can only use a single MIDI device at a time. Can you please support multiple simultaneous MIDI controllers on the Bela or tell us how? Is there an alsa command line flag for this?

giuliomoro commented 4 years ago

I just peeked at the code in question, and it would take a bit of refactoring. I am not sure why they decided to use Bela's Midi instead of the existing portmidi backend. Maybe it would be worth going down that route instead, to minimise the coding effort (I'd be happy to add portmidi to the board, if needed). I will ask on csound/csound about that.

Also, could you post some example code where several MIDI devices are used at once? Is Csound able to distinguish from which device a new MIDI message came in? Or do they all "look the same"?

giuliomoro commented 4 years ago

https://github.com/csound/csound/issues/1350

csounder commented 4 years ago

Support for portmidi on the board might be good - hopefully there would not be any additional latency or CPU load issues associated with it.

If you ask Victor, Steven, Eduardo, Tarmo, Rory or other in the Csound Developer List for information on how portmidi MIDI is handled more specifically, and if individual devices can be referred to separately, they would know.

-dB

Dr. Richard Boulanger

On Sat, Jul 4, 2020 at 12:12 PM giuliomoro notifications@github.com wrote:

I just peeked at the code in question https://github.com/csound/csound/blob/develop/Bela/BelaCsound.cpp, and it would take a bit of refactoring. I am not sure why they decided to use Bela's Midi instead of the existing portmidi backend. Maybe it would be worth going down that route instead, to minimise the coding effort (I'd be happy to add portmidi to the board, if needed). I will ask on csound/csound about that.

Also, could you post some example code where several MIDI devices are used at once? Is Csound able to distinguish from which device a new MIDI message came in? Or do they all "look the same"?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BelaPlatform/Bela/issues/636#issuecomment-653784283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALWYFRDFXLRHB2XSZ4CUYDRZ5IHPANCNFSM4OQISYQA .

csounder commented 4 years ago

Here is the command line I would use (in CsoundQt and in the terminal)

-+rtaudio=pa_cb -odac -+rtmidi=portmidi -Ma --env:CSNOSTOP=yes

this uses both portaudio in callback mode and portmidi in read all devices mode.

I HAVE INCLUDED two .csd files for you to try (and you might want to consider including as examples - the MIDI monitor.csd is pretty useful)

Not sure that the --env: command line argument is necessary, and you might not be using portaudio on the Bela

When running either of these, the console would report:

/usr/local/bin/csound -+rtaudio=pa_cb -odac -+rtmidi=portmidi -Ma --env:CSNOSTOP=yes /Users/rboulanger/Downloads/01fmCMI.csd (or MIDI-Monitor.csd)

0dBFS level = 32768.0 --Csound version 6.14 (double samples) Jun 27 2020 [commit: 58d6e6459e9a7330e0ff747958a15125d15ffa7f] libsndfile-1.0.28 UnifiedCSD: /Users/rboulanger/Downloads/01fmCMI.csd

STARTING FILE Creating options Creating orchestra closing tag Creating score rtaudio: PortAudio module enabled ... using callback interface rtmidi: PortMIDI module enabled sorting score ... ... done midi channel 1 using instr 1 midi channel 2 using instr 1 midi channel 3 using instr 1 midi channel 4 using instr 1 midi channel 5 using instr 1 midi channel 6 using instr 1 midi channel 7 using instr 1 midi channel 8 using instr 1 midi channel 9 using instr 1 midi channel 10 using instr 1 midi channel 11 using instr 1 midi channel 12 using instr 1 midi channel 13 using instr 1 midi channel 14 using instr 1 midi channel 15 using instr 1 midi channel 16 using instr 1 midi channel 17 using instr 1 midi channel 18 using instr 1 midi channel 19 using instr 1 midi channel 20 using instr 1 midi channel 21 using instr 1 midi channel 22 using instr 1 midi channel 23 using instr 1 midi channel 24 using instr 1 midi channel 25 using instr 1 midi channel 26 using instr 1 midi channel 27 using instr 1 midi channel 28 using instr 1 midi channel 29 using instr 1 midi channel 30 using instr 1 midi channel 31 using instr 1 midi channel 32 using instr 1 midi channel 33 using instr 1 midi channel 34 using instr 1 midi channel 35 using instr 1 midi channel 36 using instr 1 midi channel 37 using instr 1 midi channel 38 using instr 1 midi channel 39 using instr 1 midi channel 40 using instr 1 midi channel 41 using instr 1 midi channel 42 using instr 1 midi channel 43 using instr 1 midi channel 44 using instr 1 midi channel 45 using instr 1 midi channel 46 using instr 1 midi channel 47 using instr 1 midi channel 48 using instr 1 midi channel 49 using instr 1 midi channel 50 using instr 1 midi channel 51 using instr 1 midi channel 52 using instr 1 midi channel 53 using instr 1 midi channel 54 using instr 1 midi channel 55 using instr 1 midi channel 56 using instr 1 midi channel 57 using instr 1 midi channel 58 using instr 1 midi channel 59 using instr 1 midi channel 60 using instr 1 midi channel 61 using instr 1 midi channel 62 using instr 1 midi channel 63 using instr 1 midi channel 64 using instr 1

displays suppressed 0dBFS level = 1.0 chnl 1 using instr 1

0: IAC Driver HairLessMIDI2Serial-1 (portmidi) 1: IAC Driver HairLessMIDI2Serial-2 (portmidi) 2: IAC Driver IBVA1 (portmidi) 3: Duet USB (portmidi) 4: Bela (portmidi) 5: Launchkey Mini MK3 MIDI Port (portmidi) 6: Launchkey Mini MK3 DAW Port (portmidi) 7: nanoKONTROL SLIDER/KNOB (portmidi) 8: Vienna Instruments MIDI (portmidi)

PortMIDI: Activated input device 0: 'IAC Driver HairLessMIDI2Serial-1' (CoreMIDI) PortMIDI: Activated input device 1: 'IAC Driver HairLessMIDI2Serial-2' (CoreMIDI) PortMIDI: Activated input device 2: 'IAC Driver IBVA1' (CoreMIDI) PortMIDI: Activated input device 3: 'Duet USB' (CoreMIDI) PortMIDI: Activated input device 4: 'Bela' (CoreMIDI) PortMIDI: Activated input device 5: 'Launchkey Mini MK3 MIDI Port' (CoreMIDI) PortMIDI: Activated input device 6: 'Launchkey Mini MK3 DAW Port' (CoreMIDI) PortMIDI: Activated input device 7: 'nanoKONTROL SLIDER/KNOB' (CoreMIDI) PortMIDI: Activated input device 8: 'Vienna Instruments MIDI' (CoreMIDI)

orch now loaded audio buffered in 1024 sample-frame blocks

PortAudio V19-devel (built Feb 12 2010 09:42:54) 0: dac0 (Telestream [Core Audio]) 1: dac1 (DisplayPort [Core Audio]) 2: dac2 (Duet USB [Core Audio]) 3: dac3 (MacBook Pro Speakers [Core Audio]) 4: dac4 (Soundflower (2ch) [Core Audio]) 5: dac5 (Soundflower (64ch) [Core Audio]) 6: dac6 (ZoomAudioD [Core Audio])

PortAudio: selected output device 'Duet USB' writing 2048 sample blks of 64-bit floats to dac SECTION 1:

====. HERE ARE TWO MIDI Instruments for TESTING ======

; MIDI-Monitor.csd - by schwaahed 2006

-dm0 -+rtaudio=pa_cb -odac -+rtmidi=portmidi -Ma --env:CSNOSTOP=yes massign 0, 130 ; make sure that all channels pgmassign 0, 130 ; and programs are assigned to test instr instr 130 knotelength init 0 knoteontime init 0 kstatus, kchan, kdata1, kdata2 midiin if (kstatus == 128) then knoteofftime times knotelength = knoteofftime - knoteontime printks "kstatus= %d, kchan = %d, \\tnote# = %d, velocity = %d \\tNote OFF\\t%f %f\\n", 0, kstatus, kchan, kdata1,kdata2, knoteofftime, knotelength elseif (kstatus == 144) then knoteontime times printks "kstatus= %d, kchan = %d, \\tnote# = %d, velocity = %d \\tNote ON\\t%f\\n", 0, kstatus, kchan, kdata1, kdata2, knoteontime elseif (kstatus == 160) then printks "kstatus= %d, kchan = %d, \\tkdata1 = %d, kdata2 = %d \\tPolyphonic Aftertouch\\n", 0, kstatus, kchan, kdata1, kdata2 elseif (kstatus == 176) then printks "kstatus= %d, kchan = %d, \\t CC = %d, value = %d \\tControl Change\\n", 0, kstatus, kchan, kdata1, kdata2 elseif (kstatus == 192) then printks "kstatus= %d, kchan = %d, \\tkdata1 = %d, kdata2 = %d \\tProgram Change\\n", 0, kstatus, kchan, kdata1, kdata2 elseif (kstatus == 208) then printks "kstatus= %d, kchan = %d, \\tkdata1 = %d, kdata2 = %d \\tChannel Aftertouch\\n", 0, kstatus, kchan, kdata1, kdata2 elseif (kstatus == 224) then printks "kstatus= %d, kchan = %d, \\t ( data1 , kdata2 ) = ( %d, %d )\\tPitch Bend\\n", 0, kstatus, kchan, kdata1, kdata2 endif endin i130 0 60 e

===============

; MIDI-CC1-6-FM.csd

-dm0 -+rtaudio=pa_cb -odac -+rtmidi=portmidi -Ma --env:CSNOSTOP=yes sr=44100 ksmps = 32 nchnls = 2 0dbfs = 1 massign 1, 1 ; assign MIDI Channel 1 to control Instrument 1 ; initialize Controllers 1-6 on MIDI Channel 1 ctrlinit 1, 1,100, 2,12, 3,13, 4,6, 5,1, 6,44 instr 1 icps cpsmidi iamp ampmidi .5 kgain midic7 1, 0, 1 ; CC1 = volume kgain port kgain,.1 ; smooth CC1 to reduce zipper noise kcar midic7 2, 1, 10 ; CC2 = carrier ratio kmod midic7 3, .1, 10 ; CC3 = modulator ratio kindx midic7 4, 1, 20 ; CC4 = modulation index kindx port kindx, .01 ; smooth CC4 to reduce zipper noise iatk midic7 5, .0001, 1 ; CC5 = attack time irel midic7 6, .01, 2 ; CC6 = release time asig foscil iamp, icps, int(kcar), int(kmod), kindx, 1 kmgate madsr iatk, .001, .37, irel outs asig*kmgate*kgain, asig*kmgate*kgain endin f0 6000 f1 0 8192 10 1 e

=======

Dr. Richard Boulanger

On Sat, Jul 4, 2020 at 1:13 PM Dr. Richard Boulanger rboulanger@berklee.edu wrote:

Support for portmidi on the board might be good - hopefully there would not be any additional latency or CPU load issues associated with it.

  • typically, when I run multiple MIDI devices on my Mac using CsoundQt and portmidi, I just specify the command line argument -+rtmidi=portmidi -Ma

If you ask Victor, Steven, Eduardo, Tarmo, Rory or other in the Csound Developer List for information on how portmidi MIDI is handled more specifically, and if individual devices can be referred to separately, they would know.

  • the sense that I have is that portmidi -Ma MIDI is simply merged from any and all connected MIDI hardware and virtual controllers, and so if one controller is sending on MIDI channel 1 and the other controller is sending on MIDI channel 1 that instrument 1 (which defaults to receiving messages on MIDI channel 1) responds to both controllers. That is my experience and what I was trying to do on the Bela after testing it using CsoundQt on the Mac.

-dB

Dr. Richard Boulanger

On Sat, Jul 4, 2020 at 12:12 PM giuliomoro notifications@github.com wrote:

I just peeked at the code in question https://github.com/csound/csound/blob/develop/Bela/BelaCsound.cpp, and it would take a bit of refactoring. I am not sure why they decided to use Bela's Midi instead of the existing portmidi backend. Maybe it would be worth going down that route instead, to minimise the coding effort (I'd be happy to add portmidi to the board, if needed). I will ask on csound/csound about that.

Also, could you post some example code where several MIDI devices are used at once? Is Csound able to distinguish from which device a new MIDI message came in? Or do they all "look the same"?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BelaPlatform/Bela/issues/636#issuecomment-653784283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALWYFRDFXLRHB2XSZ4CUYDRZ5IHPANCNFSM4OQISYQA .