Cabbage Logo
Back to Cabbage Site

(SOLVED) multitrack recorder

Hi. I hope you all are safe.

I am and besides normal work I am spending some time with Cabbage.

The idea (for my last project) is simple - have an multitrack recorder (something like portastudio) as VST plugin and then record using this in Element VST host.

I hacked together working one recorder, but it seems it has some problems with sampling rate - everything recorded with it sound somewhat glitched.

See example:

Source code is here and you need working directory C:/severak/aaa/:

<Cabbage> bounds(0, 0, 0, 0)
form caption("4track") size(400, 300), colour(58, 110, 182), pluginid("4trk")


vslider bounds(40, 4, 50, 150) range(0, 1, 1, 1, 0.001) channel("vol1")
vslider bounds(94, 4, 50, 150) range(0, 1, 1, 1, 0.001) channel("vol2")
vslider bounds(150, 4, 50, 150) range(0, 1, 1, 1, 0.001) channel("vol3")
vslider bounds(204, 4, 50, 150) range(0, 1, 1, 1, 0.001) channel("vol4")
checkbox bounds(46, 158, 30, 30)  channel("ch1") radiogroup("ch")
checkbox bounds(104, 158, 30, 30) channel("ch2") radiogroup("ch")
checkbox bounds(160, 158, 30, 30) channel("ch3") radiogroup("ch")
checkbox bounds(214, 158, 30, 30) channel("ch4") radiogroup("ch")
checkbox bounds(268, 50, 102, 30) channel("ch0") radiogroup("ch") text("MIX")
checkbox bounds(268, 12, 100, 30) text("PLAY/REC") channel("running") colour:1(255, 0, 0, 255) fontcolour:1(0, 255, 0, 255)
filebutton bounds(268, 90, 122, 30) mode("directory") channel("dir") text("DIR", "DIR")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

gkRunning init 0

; this will be a working dir:
; selectable by button DIR
gSdir init "C:/severak/aaa/"

; recorder controls (always on)
instr 1


kch1 chnget "ch1"
kch2 chnget "ch2"
kch3 chnget "ch3"
kch4 chnget "ch4"
kch0 chnget "ch0"

gkRunning chnget "running"

if changed:k(gkRunning)==1 && gkRunning==1 && kch1==1 then
    printks "REC 1 ON\n", 0.5
    event "i",200,0,900,1
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch2==1 then
    printks "REC 2 ON\n", 0.5
    event "i",200,0,900,2
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch3==1 then
    printks "REC 3 ON\n", 0.5
    event "i",200,0,900,3
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch4==1 then
    printks "REC 4 ON\n", 0.5
    event "i",200,0,900,4
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch0==1 then
    printks "MIX ON\n", 0.5
    ; TODO - record MIX
endif


if changed:k(gkRunning)==1 && gkRunning==1 && kch1!=1 then
    printks "PLAY 1 ON\n", 0.5
    event "i",100,0,900,1
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch2!=1 then
    printks "PLAY 2 ON\n", 0.5
    event "i",100,0,900,2
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch3!=1 then
    printks "PLAY 3 ON\n", 0.5
    event "i",100,0,900,3
endif

if changed:k(gkRunning)==1 && gkRunning==1 && kch4!=1 then
    printks "PLAY 4 ON\n", 0.5
    event "i",100,0,900,4
endif

endin


; playback
instr 100

if gkRunning==0 then
    turnoff
endif


ich = p4
Sname sprintf "%sch%d.wav",  gSdir, ich
Schname sprintf "ch%d", ich
printf_i "in=%s\n", 1, Sname

ivalid filevalid Sname
if ivalid==1 then
    
    kVol chnget Schname
    
    aL, aR diskin2 Sname, 1
    outs aL, aR
else
    turnoff
endif

endin

; record
instr 200

if gkRunning==0 then
    turnoff
endif

aL, aR ins

ich = p4
Sname sprintf "%sch%d.wav",  gSdir, ich
printf_i "out=%s\n", 1, Sname

fout Sname, 9, aL, aR
outs aL, aR
clear aL, aR

endin



</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

I’m happy to take a look but I can’t seem to get it to work? The DIR button is not currently doing anything right? How is it supposed to work?

p.s. I saw your comments on HN. Csound splits opinion like no other sound design tool I know :laughing: Some people have a real love or hate relationship with it…

DIR button is currently not implemented and working dir is hardcoded in gSdir variable. Faders currently not doing anything too.

How it’s supposed to work?

  1. you set up your instrument’s output to this plugin input and this plugin input to speakers
  2. you select one of the channels to record on (with those switches under faders)
  3. press PLAY/REC, play something on keyboard (sound input to this plugin), then press this button again to stop recording
  4. file chN.wav in working dir is created
  5. repeat step 2 with another channel while those already recorded are playing
  6. MIX checkbox switches playback to all channels playing

Also I noticed two things - when I changed my fout iformat parameter to 14, it actually produces listeneable sound. But only while recording first track (while no other track is playing). This is no good, because my ultimated goal is to record one track while listening three others.

PS: yop. I noticed that HN thread Csound mailing list and suddenly needed to comment on that. I actually want to learn making VST other ways, but I would like to use some similar modular system to not reinvent DSP blocks itself.

I tried your steps but mix doesn’t produce any recorded audio for me at all? Might you have attached the wrong version by any chance?

It turned out, that it was something weird when debuging/reloading plugin in Cabbage. It turns out that when I stopped whole graph and started it again it works fine.

I actually finished it. It now works as intended and I even recorded one track with it today (lyrics is ending of Roadside Picnic by Strugatsky brothers).

Now workflow is following:

  1. connect 4track between output of synth and input of master out
  2. select working directory with PROJECT button
  3. select one of the tracks (switches under faders)
  4. press PLAY/REC to start recording and again to stop recording
  5. switch to JUST PLAY and press PLAY/REC to listen what you have recorded
  6. record some other tracks as described in steps 3, 4 and 5
  7. switch to FINAL MIX and press PLAY/REC to live mix final product

After doing this, you have five files in your working directory:

  • chX.wav, where X is track number (1-4)
  • mix.wav which is final mix

You can also load those chX.wav to your DAW to do better mixing than with my plugin.

IMPORTANT - when exporting this plugin you need to export it as effect, not synth.

I’m glad you got it sorted. Building tools like this for use in a modular environment like the one you’re using was the main goal of Cabbage. Then I got so busy actually writing the software, I forgot to keep writing music :see_no_evil:

I use my songs as testbed for my plugins.

1 Like