[Csnd] Csound WASM - problems to show csound channel values in html

hi all -

i am working on some examples for javascript csound GUI (in particular in Csound for Android).

i have some issues to show a csound control channel continuously in the html GUI.

this is my csound instrument:
   kTest = randomh:k(0,100,1,3)
   chnset(kTest,"bla")

i tried this as html body:

<script>
function displayChn() {
   document.getElementById("display").innerHTML = csound.getControlChannel("bla");
}
</script>
<button onclick='displayChn()'>Get Value!</button>
<p id="display"></p>

when i click on the button, i get this output:
  [object Promise]

i tried this code instead which is adapted from steven's and hlodver's tutorial (Tutorial 2 - Interacting with Csound | WebAudio Csound):

<script>
   const blaReader = () => {
     csound.getControlChannel('bla').then(v => {
       document.getElementById("display").innerHTML = v;
     })
     setTimeout(blaReader, 1000 / 10)
   }
   blaReader();
</script>
<p id="display"></p>

unfortunately, i do not get an output here at all.

thanks for any hints or examples -
  joachim

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

Hi Joaquim. HTML/js are not my strong suit so excuse the crude formatting & display.

This works fine for me in Csound for Android ver 39, so I’m not sure why you might be experiencing issues:

-odac

sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

instr 1
kTest = randomh:k(0,100,1,3)
chnset(kTest,“bla”)
endin

i1 0 z Get Value!

See attached as well.

Best,
Scott

html_test.csd (499 Bytes)

hi scott -

thanks for you feedback! i am looking for a CONTINUOUS output of a csound control channel in an html element. but in your code, i need to click on the button, right?

last night i found a solution in javascript's setInterval method:

i have to figure out how to use this properly but i guess this is what can be used to show control signals say ten times a second in the user interface.

cheers -
  joachim

Ok, now I get it, sorry for the confusion. Yes, setInterval works fine and is quite straightforward.

setInterval(displayChn, 100)

function displayChn() {
document.getElementById(“display”).innerHTML =
csound.getControlChannel(“bla”);
}

Handy! Thanks for the tip, nice alternative to the console print method.

Best,
Scott