My csound plugins

All your LV2 and LADSPA goodness and more.

Moderators: MattKingUSA, khz

Post Reply
frostfall
Established Member
Posts: 14
Joined: Tue Oct 10, 2017 9:10 am

My csound plugins

Post by frostfall »

Hello!

I wish to present you with my effort to create plugins that are useful to me and to other (may be!). I used csound to create the plugins and cslapsda to make the plugin usable. Csound is a programming language dedicated to create music / instrument or real time effect.

The first plugin here is something called MidiCC Rack (well I was in lack of inspiration when I named it). The purpose of this plugin is to take one midi event in and out multiple midi events on other channels. I did it because when I put all my guitar plugins in Carla, I found that it was not very easy to switch from Clean to Saturate sound. I had to :
- switch off the overdrive
- Change the channel of the amp
- Put on the chorus
- etc, etc..

I wanted all of this to be done with only one click on a button. Carla helps a lot here because you can set up channel and midi cc to control plugins with external sources. The plugin is not usable by you directly, you have to change the source code in order to make your own idea, but I fully commented the source below to make it easy. Here it is :
<csLADSPA>
Name=MidiCC Rack
Maker=Sylvain Dubois
UniqueID=100678
Copyright=None
</csLADSPA>

<CsoundSynthesizer>
<CsOptions>
; CSound will connect to the midi channel when the plugin startup
; We have to specifiy the midi in plugin and midi out.
; if I want midi in on device 1 I have to specify -M1
; it's the same for midi out with the -Q option
; rtmidi=portmidi means we do not want to display a virtual keyboard, only to route midi events.
-odac -M1 -Q0 -+rtmidi=portmidi
</CsOptions>
<CsInstruments>

; This script is based on the one provided in http://www.csounds.com/manual/html/midiin.html. Here we create an audio channel with 0 channel (don't want audio on this one)
sr = 44100
ksmps = 10
nchnls = 0

; Example by schwaahed 2006

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

; We retrieve the midi events in those data.
kstatus, kchan, kdata1, kdata2 midiin

; the different midi events are below : play a note, change a controller etc...I personnally focus on controller events (176)
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
; Here is the core of the system : kdata2=0 means the button is off. Otherwise we put the saturation on again.
if (kdata2 == 0) then
; We send midi events accordingly. midiout 176 means we send a controller midi event. 10 is the channel. 4 is the Midi CC and 0 the value we put on the effect
; Change clean channel marshall
midiout 176, 10, 4, 0
; Activate chorus
midiout 176, 10, 7, 100
else
; change crunch channel marshall
midiout 176, 10, 4, 127
; Desactivate chorus
midiout 176, 10, 7, 0
endif
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

</CsInstruments>
<CsScore>
i130 0 3600
e
</CsScore>
</CsoundSynthesizer>
How to use this when the code is written??
Save the code below to a file.csd in your computer.
In your linux do apt-get install csound csladspa
after this you have to do this command : export LADSPA_PATH=/usr/lib/ladspa/
You have to do this every time you want to start a software that use the ladspa csound.
So I personnally made a bash startup for carla :
#!/bin/bash
export LADSPA_PATH=/usr/lib/ladspa/
carla
Next step is to put the plugin in the /usr/lib/ladspa folder. What I've done is to make a symbolic link in the folder :

sudo ln -s /<yourfolder>/midirack.csd /usr/lib/ladspa/

Next if you use carla you have to refresh the list of your plugins. The plugin is now usable! When you choose it, it will not display anything though. You can see that it started well in the Logs tab of Carla (very helpful to debug the plugin and see the results of the printks command).

In order to control the midi In, I used VMPK. This is a small Virtual Midi keyboard but it has cool functionality like adding custom knob and button (named switch).
You can add a button in the "Edit menu" then something like "More controllers", "add". Select a switch with value min 0 and 127 max. You have a fully usable button! In my script above I connected the midi in to VMPK (-M1), then the output to Midi Through Port 0 (-Q0).
You have to do "a2jmidid -e" in order to see the midi input and output in Carla. Then I plugged Midi Through Port 0 output to all the plugins that I needed to control.

Last useful tip concerning carla. Every plugins have a Dry/Wet and Volume knob. By changing the Dry/Wet knob you can Bypass a plugin. By putting the Volume to 0 or 100 (default) you can disable / enable a plugin. A full specification of Carla events can be found here : https://github.com/falkTX/Carla/issues/363

This a long post for this plugin and there's a lot of technical info (sorry!). I just hope that this script can be useful to someone else like it was for me :) (BTW if there's other way to do this, I'm glad to here it, but I find it to be very convenient to write 3->4 lines of code to do this ^^). If you have any question, be my guest!
User avatar
davephillips
Established Member
Posts: 592
Joined: Sat Aug 15, 2015 1:05 pm
Has thanked: 35 times
Been thanked: 23 times

Re: My csound plugins

Post by davephillips »

Greetings !

I am impressed, that's a great example for the csLadspa opcode. Alas, I haven't touched a LADSPA plugin for ages, but your script just might push me that way again. Anyway, nice work, and I hope you post a notice about it to the Csound list too.

Best regards,

Dave Phillips
ssj71
Established Member
Posts: 1294
Joined: Tue Sep 25, 2012 6:36 pm
Has thanked: 1 time

Re: My csound plugins

Post by ssj71 »

cool thanks!

Have you thought about trying to use cabbage (http://cabbageaudio.com/)? I've seen some fancy plugins come from that.
_ssj71

music: https://soundcloud.com/ssj71
My plugins are Infamous! http://ssj71.github.io/infamousPlugins
I just want to get back to making music!
frostfall
Established Member
Posts: 14
Joined: Tue Oct 10, 2017 9:10 am

Re: My csound plugins

Post by frostfall »

ssj71 wrote:cool thanks!

Have you thought about trying to use cabbage (http://cabbageaudio.com/)? I've seen some fancy plugins come from that.
Thanks for the advice. When I was searching for the best way to do my plugin, I came through cabbage, it's really interesting if you need a GUI. Here it was only simply routing midi events, so I thought it would be too much for this.

I may use it for other things in the future though ^^
Post Reply