Jacko Opcodes

These opcodes enable the use of Jack ports from within Csound orchestras and instruments. Ports can receive or send audio or MIDI data, and send note data.

The Jacko opcodes do not replace the Jack driver and Jack command-line options for Csound, nor do the Jacko opcodes work with them (hence the name "Jacko" instead of "Jack"). The Jacko opcodes are an independent facility that offers greater flexibility in signal routing.

It is Jack that calls csoundPerformKsmps.The k-rate speed is not dictated by Csound, it is dictated by the Jack DAEMON configuration: --period. Csound has to agree to that.

In addition, the Jacko opcodes can work with the Jack system in "freewheeling" mode, which enables the use of Jack-enabled external synthesizers, such as Aeolus or Pianoteq, to render Csound pieces either faster or, even more importantly, slower than real time. This is extremely useful for rendering complex pieces without dropouts using instruments, such as Aeolus, that may not be available except through Jack (see example below). A second example shows midi connections to external synthesizers and a midi connection from an external keyboard.

The Jacko opcodes include: JackoInit, for initializing the current instance of Csound as a Jack client. JackoInfo, for printing information about the Jack daemon, its clients, their ports, and their connections. JackoFreewheel, for turning Jack's freewheeling mode on or off. JackoAudioInConnect, for creating a connection from an external Jack audio output port to a Jack port in Csound. JackoAudioOutConnect, for creating a connection from a Jack port in Csound to an external Jack audio input port. JackoMidiInConnect, for creating a connection from an external Jack MIDI port. MIDI events from Jack are received by Csound's regular MIDI opcodes and MIDI interop system. JackoMidiOutConnect, for creating a connection from a Jack port in Csound to an external Jack MIDI input port. JackoOn, for turning Jack ports in Csound on or off. JackoAudioIn, for receiving audio from a Jack input port in Csound, which in turn has received the audio from its connected external port. JackoAudioOut, for sending audio to a Jack output port in Csound, which in turn will send the audio on to its connected external port. JackoMidiOut, for sending MIDI channel messages to a Jack output port in Csound, which in turn will send the MIDI on to its connected external port. JackoNoteOut, for sending a note (with duration) to a Jack output port in Csound, which in turn will send the note on to its connected external port. JackoTransport, for controlling the Jack transport.

A typical scenario for the use of the Jacko opcodes would be something like this.


Here is an example of the Jacko opcodes. It uses the file jacko.csd.

Example 7. Example of the Jacko opcodes.

csound -m255 -M0 -+rtmidi=null -RWf --midi-key=4 --midi-velocity=5 -o jacko_test.wav

;;;; NOTE: this csd must be run after starting "aeolus -t".

sr    	   = 48000
	   ; The control rate must be BOTH a power of 2 (for Jack)
	   ; AND go evenly into sr. This is about the only one that works!
ksmps 	   = 128
nchnls 	   = 2
0dbfs 	   = 1

	   JackoInit		"default", "csound"

	   ; To use ALSA midi ports, use "jackd -Xseq"
	   ; and use "jack_lsp -A -c" or aliases from JackInfo,
	   ; probably together with information from the sequencer,
	   ; to figure out the damn port names.

	   ; JackoMidiInConnect   "alsa_pcm:in-131-0-Master", "midiin"
	   JackoAudioInConnect 	"aeolus:out.L", "leftin"
	   JackoAudioInConnect 	"aeolus:out.R", "rightin"
	   JackoMidiOutConnect 	"midiout", "aeolus:Midi/in"

           ; Note that Jack enables audio to be output to a regular
 	   ; Csound soundfile and, at the same time, to a sound 
	   ; card in real time to the system client via Jack. 

       	   JackoAudioOutConnect "leftout", "system:playback_1"
	   JackoAudioOutConnect "rightout", "system:playback_2"

	   ; Turning freewheeling on seems automatically 
           ; to turn system playback off. This is good!

	   JackoFreewheel	1

	   alwayson		"jackin"

	   instr 1
ichannel   =			p1 - 1
itime 	   = 			p2
iduration  = 			p3
ikey 	   = 			p4
ivelocity  = 			p5
	   JackoNoteOut 	"midiout", ichannel, ikey, ivelocity
	   print 		itime, iduration, ichannel, ikey, ivelocity

	   instr jackin
	   JackoTransport	3, 1.0
aleft 	   JackoAudioIn		"leftin"
aright 	   JackoAudioIn 	"rightin"

	   ; Aeolus uses MIDI controller 98 to control stops. 
           ; Only 1 data value byte is used, not the 2 data 
	   ; bytes often used  with NRPNs. 
           ; The format for control mode is 01mm0ggg:
	   ; mm 10 to set stops, 0, ggg group (or Division, 0 based).
	   ; The format for stop selection is 000bbbbb:   
	   ; bbbbb for button number (0 based).

	   ; Mode to enable stops for Divison I: b1100010 (98 
           ; [this controller VALUE is a pure coincidence]).

	   JackoMidiOut          "midiout", 176, 0, 98, 98 

	   ; Stops: Principal 8 (0), Principal 4 (1) , Flote 8 (8) , Flote 2 (10)

	   JackoMidiOut          "midiout", 176, 0, 98, 0
	   JackoMidiOut          "midiout", 176, 0, 98, 1
	   JackoMidiOut          "midiout", 176, 0, 98, 8
	   JackoMidiOut          "midiout", 176, 0, 98, 10

	   ; Sends audio coming in from Aeolus out
	   ; not only to the Jack system out (sound card),
	   ; but also to the output soundfile.
           ; Note that in freewheeling mode, "leftout"
           ; and "rightout" simply go silent.

 	   JackoAudioOut 	"leftout", aleft
	   JackoAudioOut 	"rightout", aright
	   outs  		aright, aleft

f 0 30
i 1 1 30 60 60
i 1 2 30 64 60
i 1 3 30 71 60
e 2

Here is a second example of the Jacko opcodes. It uses the file jacko_extSynths.csd.

Example 8. Another example of the Jacko opcodes.

-o dac -+rtmidi=null -Ma; 

sr     = 48000
ksmps  = 128
nchnls = 2
0dbfs  = 1

; by Menno Knevel - 2023

JackoInit   "default", "csound6"						; Csound as a Jack client
JackoMidiInConnect "UM-3:midi/playback_2", "midiinEDIROL" 	                ; create 1 Midi in port 
JackoMidiOutConnect "midioutMAUDIO", "M-Audio-Delta-1010:midi/capture_1"	; create 1 Midi output port
JackoMidiOutConnect "midioutEDIROL", "UM-3:midi/capture_1"			; create 2nd Midi output port

instr 1	; get notes from score AND from the EDIROL Midi port "midiinEDIROL"

midinoteoncps p4, p5				            ;Gets a MIDI note number as a cycles-per-second frequency
ikey = p4
ivel = p5/127
kenv madsr 0.05, 0.8, 0.8, 0.5		
aout pluck kenv*ivel, ikey, ikey*.2, 2, 1	
outs aout, aout

instr 2	; send notes to the M-Audio Midi port (external synth #1)	
irandom     random      50, 100
JackoNoteOut "midioutMAUDIO", 1-1, irandom, 100		    ; channel range = 0-15

instr 3 ; send notes to Edirol Midi port (external synth #2)	
irandom     random      30, 80
JackoNoteOut "midioutEDIROL", 1-1, irandom, 100

f 0 20 ; run for 20 seconds, allows playing instr 1 on keyboard
f 2 0 4096 10 1	

i1 1 3 100 100    ; score notes for instr 1
i1 10 3 1200 100

i2 1 .1
i2 2 1
i2 4 2

i3 11 .1
i3 12 1
i3 14 2


By: Michael Gogins 2010