Cabbage Logo
Back to Cabbage Site

How to use display?

Hello,

I am trying to work with csound display opcode and the display widget. I have this file:

<Cabbage> bounds(0, 0, 0, 0)
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1"), colour(140, 160, 170, 130)

checkbox bounds(308, 22, 80, 17), text("On/Off"), channel("onoff"), , fontColour:0(0, 0, 0, 255), fontColour:1(0, 0, 0, 255), colour:1(255, 255, 0, 255)
rslider bounds(8, 6, 68, 65) channel("osc1Gain") range(0, 1, 0, 1, 0.001) text("1 gain") textColour(218, 217, 221, 255)
rslider bounds(80, 6, 68, 65) channel("osc2Gain") range(0, 1, 0, 1, 0.001) text("2 gain") textColour(218, 217, 221, 255)
rslider bounds(152, 6, 68, 65) channel("osc3Gain") range(0, 1, 0, 1, 0.001) text("3/2 gain") textColour(218, 217, 221, 255)
rslider bounds(224, 6, 68, 65) channel("osc4Gain") range(0, 1, 0, 1, 0.001) text("5/4 gain") textColour(218, 217, 221, 255)
rslider bounds(8, 80, 68, 65) channel("osc1Fine") range(0, 1, 0, 1, 0.001) text("1 Fine") textColour(218, 217, 221, 255)
rslider bounds(80, 80, 68, 65) channel("osc2Fine") range(0, 1, 0, 1, 0.001) text("2 Fine") textColour(218, 217, 221, 255)
rslider bounds(152, 80, 68, 65) channel("osc3Fine") range(0, 1, 0, 1, 0.001) text("3/2 Fine") textColour(218, 217, 221, 255)
rslider bounds(224, 80, 68, 65) channel("osc4Fine") range(0, 1, 0, 1, 0.001) text("5/4 Fine") textColour(218, 217, 221, 255)
rslider bounds(306, 52, 81, 75) channel("freq") range(50, 1000, 100, 1, 0.001) colour(238, 123, 155, 255) outlineColour(111, 173, 23, 255) markerColour(160, 209, 92, 255) text("Main Freq") textColour(226, 138, 213, 255)

signaldisplay bounds(8, 156, 378, 134) colour("white") displayType("waveform"), backgroundColour(0, 100, 0), signalVariable("a5", "a6"), channel("display")

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n --displays -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


gisine	ftgen	0, 0, 4096, 10, 1
instr    1
    koscgain1 chnget    "osc1Gain"
    koscgain2 chnget    "osc2Gain"
    koscgain3 chnget    "osc3Gain"
    koscgain4 chnget    "osc4Gain"
    koscfine1 chnget    "osc1Fine"
    koscfine2 chnget    "osc2Fine"
    koscfine3 chnget    "osc3Fine"
    koscfine4 chnget    "osc4Fine"
    kfreq     chnget    "freq"
    konoff    chnget    "onoff"
        
    

    a1 oscili  koscgain1, kfreq * (1 + koscfine1), gisine
    a2 oscili  koscgain2, kfreq * (1 + koscfine2) * 2 , gisine
    a3 oscili  koscgain3, kfreq * (1 + koscfine3) * (3 / 2), gisine
    a4 oscili  koscgain4, kfreq * (1 + koscfine4) * (5 / 4), gisine
    a5 oscili  a1 * a2, gisine
    a6 oscili  a3 * a4, gisine

    kAntiClick	portk konoff, 0.25
    aout = kAntiClick * (a5 + a6)
    
    outs aout, aout
    display aout, 1, 1, 1
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
; f1 0 16384 10 1 0
i 1 0 [60*60*24*7]    ;instrument that reads in widget data
</CsScore>
</CsoundSynthesizer>

I would like see the waveform produced in a4 and a5. Sadly the display show nothing. I am sure I missed something. Maybe because the sound is continuous and I need something to trigger the “display”. How can I achieve what I want ?

This took a while to work out. The problem is with your Csound code. You’re passing a function table handle as the frequency. Here is an updated version, although it’s only displaying aout.

<Cabbage> 
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1"), colour(140, 160, 170, 130)

signaldisplay bounds(8, 156, 378, 134), colour("white") displayType("waveform"), backgroundColour(147, 210, 0), zoom(-1), signalVariable("aout"), channel("display")

checkbox bounds(308, 22, 80, 17), text("On/Off"), channel("onoff"), value(1), fontColour:0(0, 0, 0, 255), fontColour:1(0, 0, 0, 255), colour:1(255, 255, 0, 255)
rslider bounds(8, 6, 68, 65) channel("osc1Gain") range(0, 1, 0.5, 1, 0.001) text("1 gain") textColour(218, 217, 221, 255)
rslider bounds(80, 6, 68, 65) channel("osc2Gain") range(0, 1, 0.7, 1, 0.001) text("2 gain") textColour(218, 217, 221, 255)
rslider bounds(152, 6, 68, 65) channel("osc3Gain") range(0, 1, 0.5, 1, 0.001) text("3/2 gain") textColour(218, 217, 221, 255)
rslider bounds(224, 6, 68, 65) channel("osc4Gain") range(0, 1, 0, 1, 0.001) text("5/4 gain") textColour(218, 217, 221, 255)
rslider bounds(8, 80, 68, 65) channel("osc1Fine") range(0, 1, 0, 1, 0.001) text("1 Fine") textColour(218, 217, 221, 255)
rslider bounds(80, 80, 68, 65) channel("osc2Fine") range(0, 1, 0.5, 1, 0.001) text("2 Fine") textColour(218, 217, 221, 255)
rslider bounds(152, 80, 68, 65) channel("osc3Fine") range(0, 1, 0, 1, 0.001) text("3/2 Fine") textColour(218, 217, 221, 255)
rslider bounds(224, 80, 68, 65) channel("osc4Fine") range(0, 1, 0, 1, 0.001) text("5/4 Fine") textColour(218, 217, 221, 255)
rslider bounds(306, 52, 81, 75) channel("freq") range(50, 1000, 100, 1, 0.001) colour(238, 123, 155, 255) outlineColour(111, 173, 23, 255) markerColour(160, 209, 92, 255) text("Main Freq") textColour(226, 138, 213, 255)

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n --displays 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr    1
    koscgain1 chnget    "osc1Gain"
    koscgain2 chnget    "osc2Gain"
    koscgain3 chnget    "osc3Gain"
    koscgain4 chnget    "osc4Gain"
    koscfine1 chnget    "osc1Fine"
    koscfine2 chnget    "osc2Fine"
    koscfine3 chnget    "osc3Fine"
    koscfine4 chnget    "osc4Fine"
    kfreq     chnget    "freq"
    konoff    chnget    "onoff"
        
    cabbageSet "display", "displayType(\"waveform\")"

    a1 oscili  koscgain1, kfreq * (1 + koscfine1), -1
    a2 oscili  koscgain2, kfreq * (1 + koscfine2) * 2, -1
    a3 oscili  koscgain3, kfreq * (1 + koscfine3) * (3 / 2), -1
    a4 oscili  koscgain4, kfreq * (1 + koscfine4) * (5 / 4), -1
    a5 oscili  a1 * a2, 1
    a6 oscili  a3 * a4, 1

    kAntiClick	portk konoff, 0.25
    aout = kAntiClick * (a5 + a6)
    
    
    display aout, .1, 1
    outs aout, aout
    
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
; f1 0 16384 10 1 0
i 1 1 [60*60*24*7]    ;instrument that reads in widget data
</CsScore>
</CsoundSynthesizer>

what does “-1” for fn param in oscili exactly do ? In fact I would like to use function table in the future. Is it impossible with display ?

according to documentation frequency is the second parameter no ?

ares oscili xamp, xcps[, ifn, iphs]

https://csound.com/docs/manual/oscili.html

-1 means use a default function table. But you can leave it out. Frequency is the second argument, but if I’m not mistaken you were passing gisine for the second parameter?