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?

1 Like

ah yes I got it. here:

    a5 oscili  a1 * a2, gisine
    a6 oscili  a3 * a4, gisine

I will try the fix, thanks !

1 Like

Hey Rory !

Thank you it works now. In addition to my error with oscilli, I had the “-d” flag in the CS options, which precisely suppresses all display.

it’s an old test I took up not long ago and I think I was originally trying to make a frequency modulation.

I am going to see how to do that properly with csound.

This is the current state of my app:

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

signaldisplay bounds(8, 156, 378, 134), colour(255, 0, 120) displayType("waveform"), backgroundColour(0, 0, 50), zoom(-1), signalVariable("aout"), channel("display")

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(226, 32, 120, 255)
rslider bounds(8, 6, 68, 65) channel("osc1Gain") range(0, 1, 0, 1, 0.001) text("1 gain") textColour(218, 217, 221, 255) colour(217, 84, 76, 255)
rslider bounds(80, 6, 68, 65) channel("osc2Gain") range(0, 1, 0, 1, 0.001) text("2 gain") textColour(218, 217, 221, 255) colour(217, 84, 76, 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) colour(217, 84, 76, 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) colour(217, 84, 76, 255)
rslider bounds(8, 80, 68, 65) channel("osc1Fine") range(0, 0.1, 0, 1, 0.001) text("1 Fine") textColour(218, 217, 221, 255) colour(176, 23, 226, 255)
rslider bounds(80, 80, 68, 65) channel("osc2Fine") range(0, 0.1, 0, 1, 0.001) text("2 Fine") textColour(218, 217, 221, 255) colour(176, 23, 226, 255)
rslider bounds(152, 80, 68, 65) channel("osc3Fine") range(0, 0.1, 0, 1, 0.001) text("3/2 Fine") textColour(218, 217, 221, 255) colour(176, 23, 226, 255)
rslider bounds(224, 80, 68, 65) channel("osc4Fine") range(0, 0.1, 0, 1, 0.001) text("5/4 Fine") textColour(218, 217, 221, 255) colour(176, 23, 226, 255)
rslider bounds(306, 52, 81, 75) channel("freq") range(50, 200, 100, 0.5, 0.0001) colour(200, 12, 64, 255) outlineColour(111, 173, 23, 255) markerColour(160, 209, 92, 255) text("Main Freq") textColour(226, 138, 213, 255)


</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n --displays -+rtmidi=NULL -M0 -m0 --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"
        
   
    cabbageSet "display", "displayType(\"waveform\")" 

    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 =  a1 * a2
    a6 =  a3 * a4

    kAntiClick	portk konoff, 0.25
    aout = kAntiClick * (a5 + a6)
    
    outs aout, aout
    display aout, .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 have changed a5 and a6. I want to have a ring modulation here. But I am not sure if it works I have the feeling it just mix the 2 signals. I will try with a function table with more harmonics.

Looks right to me, your multiplying two signals, which will modulate rather than mix. :+1: Glad you got the display sorted!

1 Like

ah cool thanks . Sorry I didn’t see notification.

Thank you for your help