[Csnd] csound.js ReadScore method

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd] csound.js ReadScore method

Jean Basile Sosa
Hello,

Could you help me to understand the csound.js ReadScore method please ?

I would like to declare something like that, of course relative to an orchestra complied via the csound.CompileOrc method :

In html:

    <textarea class="code" id="score" hidden>
<!-- for example these three score lines -->
i 1.02 0 246.942 0.0155 0.014 1 246.942 0 0.9789 1.1687 0 0 1.019 1.0115 1.0104
i 1.01 11.75 471.25 0.0155 0.0171 1 293.665 0 0.6736 8.2028 0 0 1.2734 1.7197 1.7101
i 1.03 28.5 289.531 0.0181 0.0149 20 123.471 0 1 0.462 0 0 1.5137 2.279 3.0554
e
    </textarea>

In javascript:

  function moduleDidLoad() {
      csound.Play();
      csound.CompileOrc(document.getElementById('instruments').value);
      document.getElementById("score").innerHTML = "SCORE";
      attachListeners();
    }

    function attachListeners() {
      document.getElementById("score").addEventListener("click", score);
    }

    function score() {
      csound.ReadScore(document.getElementById('score').value);
    }

When I "click" on the score button, nothing happens because I guess the score lines are not relatived to any orchestra?
Could you tell me how can I fire the csound.js ReadScore method to send some score lines to an instrument within the web please?

Best,

Jean Basile

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Victor Lazzarini-2
That should work. Maybe open the JS console and see if Csound is running Ok, you see the Csound messages there.

You can even try invoking csound.ReadScore() on the console REPL to see if it runs from there.

Prof. Victor Lazzarini
Maynooth University
Ireland

> On Nov 24, 2020, at 6:22 PM, Jean Basile Sosa <[hidden email]> wrote:
>
> *Warning*
>
> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>
> Hello,
>
> Could you help me to understand the csound.js ReadScore method please ?
>
> I would like to declare something like that, of course relative to an orchestra complied via the csound.CompileOrc method :
>
> In html:
>
>    <textarea class="code" id="score" hidden>
> <!-- for example these three score lines -->
> i 1.02 0 246.942 0.0155 0.014 1 246.942 0 0.9789 1.1687 0 0 1.019 1.0115 1.0104
> i 1.01 11.75 471.25 0.0155 0.0171 1 293.665 0 0.6736 8.2028 0 0 1.2734 1.7197 1.7101
> i 1.03 28.5 289.531 0.0181 0.0149 20 123.471 0 1 0.462 0 0 1.5137 2.279 3.0554
> e
>    </textarea>
>
> In javascript:
>
>  function moduleDidLoad() {
>      csound.Play();
>      csound.CompileOrc(document.getElementById('instruments').value);
>      document.getElementById("score").innerHTML = "SCORE";
>      attachListeners();
>    }
>
>    function attachListeners() {
>      document.getElementById("score").addEventListener("click", score);
>    }
>
>    function score() {
>      csound.ReadScore(document.getElementById('score').value);
>    }
>
> When I "click" on the score button, nothing happens because I guess the score lines are not relatived to any orchestra?
> Could you tell me how can I fire the csound.js ReadScore method to send some score lines to an instrument within the web please?
>
> Best,
>
> Jean Basile
>
> Csound mailing list
> [hidden email]
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&amp;data=04%7C01%7CVictor.Lazzarini%40mu.ie%7C92ef21e629a04929ab3708d890a5e6c4%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C0%7C637418389504647960%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=cZhMarhi%2FYN0V6GXZ1DnYifcrXv%2BuORyuMwhEI4iAdo%3D&amp;reserved=0
> Send bugs reports to
>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&amp;data=04%7C01%7CVictor.Lazzarini%40mu.ie%7C92ef21e629a04929ab3708d890a5e6c4%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C0%7C637418389504647960%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=tZ7ZZ5WXzSapFlky8t%2BoAsdHmPPSFi2u9%2BfPT2QqaIQ%3D&amp;reserved=0
> Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Jean Basile Sosa
In reply to this post by Jean Basile Sosa
Indeed It should work, but not...

I don't understand, sorry Victor.

For me Csound on web is working as you could see here (just click play):
http://csound.jeanbasilesosa.com/

But if I click on the score button, no result.

I would like to click on the score button and then call a
   function score() {
      csound.ReadScore(document.getElementById('score').value);
    }

And then for exemple "i 1.02 0 246.942 0.0155 0.014 1 246.942 0 0.9789 1.1687 0 0 1.019 1.0115 1.0104" should be send and csound should be play,

But in my exemple nothing happens :(

Maybe do you have an other advice?

Merci,

Jean Basile

 





Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Steven Yi
I think the problem is that you have a button with the id of score:

    <button class="btn score" id="score" >SCORE</button>

So that is what is being grabbed by your code in score() does not have
the contents you expect. Try renaming that button's id and I think it
will work for you.

On Tue, Nov 24, 2020 at 5:38 PM Jean Basile Sosa
<[hidden email]> wrote:

>
> Indeed It should work, but not...
>
> I don't understand, sorry Victor.
>
> For me Csound on web is working as you could see here (just click play):
> http://csound.jeanbasilesosa.com/
>
> But if I click on the score button, no result.
>
> I would like to click on the score button and then call a
>    function score() {
>       csound.ReadScore(document.getElementById('score').value);
>     }
>
> And then for exemple "i 1.02 0 246.942 0.0155 0.014 1 246.942 0 0.9789 1.1687 0 0 1.019 1.0115 1.0104" should be send and csound should be play,
>
> But in my exemple nothing happens :(
>
> Maybe do you have an other advice?
>
> Merci,
>
> Jean Basile
>
>
>
>
>
>
>
> Csound mailing list
> [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Jean Basile Sosa
In reply to this post by Jean Basile Sosa
I thank you very much Steven,

Indeed it was a major part of my problem, more I forget to call in order three other functions...

Here a result on web, just click on score if you want to listen a beginning of music: http://csound.jeanbasilesosa.com/

html:
    <textarea id="steven" hidden>
i1.02 0 246.942 0.0155 0.014 1 246.942 0 0.9789 1.1687 0 0 0 0 1 0 1 1 0 1.019 1.0115 1.0104

i1.01 11.75 471.25 0.0155 0.0171 1 293.665 0 0.6736 8.2028 0 0 0 0 1 0 1 1 0 1.2734 1.7197 1.7101

i1.03 28.5 289.531 0.0181 0.0149 20 123.471 0 1 0.462 0 0 0 0 1 0 1 1 0.5175 1.5137 2.279 3.0554
    </textarea>

js:
    function score() {
      setElement();
      ctrl();
      csound.ReadScore(document.getElementById("steven").value);
      Play();
    }

Many thanks again Steven,

See you,

Jean Basile

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Steven Yi
Glad that's worked out, looking forward to seeing this when it is complete! :)

On Tue, Nov 24, 2020 at 6:45 PM Jean Basile Sosa
<[hidden email]> wrote:

>
> I thank you very much Steven,
>
> Indeed it was a major part of my problem, more I forget to call in order three other functions...
>
> Here a result on web, just click on score if you want to listen a beginning of music: http://csound.jeanbasilesosa.com/
>
> html:
>     <textarea id="steven" hidden>
> i1.02 0 246.942 0.0155 0.014 1 246.942 0 0.9789 1.1687 0 0 0 0 1 0 1 1 0 1.019 1.0115 1.0104
>
> i1.01 11.75 471.25 0.0155 0.0171 1 293.665 0 0.6736 8.2028 0 0 0 0 1 0 1 1 0 1.2734 1.7197 1.7101
>
> i1.03 28.5 289.531 0.0181 0.0149 20 123.471 0 1 0.462 0 0 0 0 1 0 1 1 0.5175 1.5137 2.279 3.0554
>     </textarea>
>
> js:
>     function score() {
>       setElement();
>       ctrl();
>       csound.ReadScore(document.getElementById("steven").value);
>       Play();
>     }
>
> Many thanks again Steven,
>
> See you,
>
> Jean Basile
>
> Csound mailing list
> [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Jean Basile Sosa
In reply to this post by Jean Basile Sosa
It's the very first beginning but I hope to share this project when it will be completed...

The next step is to send values in time of each i score event to the web UI, but after having take a look of all csound.js methods I wonder how I can do this.

Maybe would you suggest me something?

Thanks again,

Jean Basile

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Steven Yi
Sorry for a late reply!

One option to sync up Csound with visual is to use channels. It is not
perhaps the most elegant and that we may want to add a host event
opcode in the future, but for now you can see how this might work here
in this p5.js sketch:

https://editor.p5js.org/kunstmusik/sketches/K0t1doE6J

You should see the visual change with the amplitude envelope. You
might try various strategies for channel values and signaling to the
host.

For others, what do you think about something like this:

[csound code]

instr x
  host_event "eventName", 0,1,2,3,4,5
endin

[host code]
// JS
csound.addHostEventListener(evt => {
  console.log(`event ${evt.name} with args ${evt.args}`);
});

// C
typdef void (hostEventCallback*) (CSOUND*, CS_VARIABLE**);

void myHostEventCallback(CSOUND* csound, CS_VARIABLE** args) {
  // CS_VARIABLE would allow query of CS_TYPE, would need additional
API for querying data structures
}
csoundAddHostEventListener(csound, &myHostEventCallback);


On Wed, Nov 25, 2020 at 10:43 AM Jean Basile Sosa
<[hidden email]> wrote:

>
> It's the very first beginning but I hope to share this project when it will be completed...
>
> The next step is to send values in time of each i score event to the web UI, but after having take a look of all csound.js methods I wonder how I can do this.
>
> Maybe would you suggest me something?
>
> Thanks again,
>
> Jean Basile
>
> Csound mailing list
> [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Andy.Fillebrown
You can override the host console function and use the Csound print opcodes to send strings to it. Send JSON from Csound to host to simplify parsing and filtering.


On Fri, Dec 18, 2020 at 11:35 AM Steven Yi <[hidden email]> wrote:
Sorry for a late reply!

One option to sync up Csound with visual is to use channels. It is not
perhaps the most elegant and that we may want to add a host event
opcode in the future, but for now you can see how this might work here
in this p5.js sketch:

https://editor.p5js.org/kunstmusik/sketches/K0t1doE6J

You should see the visual change with the amplitude envelope. You
might try various strategies for channel values and signaling to the
host.

For others, what do you think about something like this:

[csound code]

instr x
  host_event "eventName", 0,1,2,3,4,5
endin

[host code]
// JS
csound.addHostEventListener(evt => {
  console.log(`event ${evt.name} with args ${evt.args}`);
});

// C
typdef void (hostEventCallback*) (CSOUND*, CS_VARIABLE**);

void myHostEventCallback(CSOUND* csound, CS_VARIABLE** args) {
  // CS_VARIABLE would allow query of CS_TYPE, would need additional
API for querying data structures
}
csoundAddHostEventListener(csound, &myHostEventCallback);


On Wed, Nov 25, 2020 at 10:43 AM Jean Basile Sosa
<[hidden email]> wrote:
>
> It's the very first beginning but I hope to share this project when it will be completed...
>
> The next step is to send values in time of each i score event to the web UI, but after having take a look of all csound.js methods I wonder how I can do this.
>
> Maybe would you suggest me something?
>
> Thanks again,
>
> Jean Basile
>
> Csound mailing list
> [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] [EXTERNAL] [Csnd] csound.js ReadScore method

Jean Basile Sosa
In reply to this post by Jean Basile Sosa
Thanks Steven and Andy,

I found a temporary inelegant solution using the host console.

It works in local but when I test it online p2 is set with a delay and do not correspond to the score instructions : for example if I trigger the score function three seconds after the "Csound ready" message, the value of p2 equals 3 while in the score line p2 equals 0.
Certainly mistakes or approximations in my code...

html:

<textarea id="scoreTest" hidden>        
i1.02 0 20 0.0155 0.014 1 246.942 0 0.9789 0.1687 0 0 0 0 1 0 1 1 0 1.019 1.0115 1.0104
i1.01 5.75 14.25 0.0155 0.0171 1 293.665 0 0.6736 4.2028 0 0 0 0 1 0 1 1 0 1.2734 1.7197 1.7101
i1.03 14.25 5.75 0.0181 0.0149 20 123.471 0 1 0.462 0 0 0 0 1 0 1 1 0.5175 1.5137 2.279 3.0554
</textarea>

<textarea id="display" hidden></textarea> <!-- textarea zone to output just filtering messages -->

csound:

instr 1

; instrument code, etc.

; sprintf and puts to show scorelines in console, the "scoreStatement" for filtering messages later
Stest sprintf "%s %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", "scoreStatement", "i", p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22
puts Stest,1

endin

Javascript:

    var count = 0;
    var scoreOn = false;

    function handleMessage(message) {
      var element = document.getElementById('console');
      element.value += message;

      var searchFilter = "scoreStatement"; filter only i instructions messages
      if (scoreOn == true) {
      message.includes(searchFilter) == true;
      var parse = document.getElementById('display');
      parse.value = message;
      parseInstructions();
      }

      element.scrollTop = 99999; // focus on bottom
      count += 1;
      if (count == 1000) {
        element.value = ' ';
        count = 0;
      }
    }

  function parseInstructions(){
      var receiveStatement = document.getElementById('display').value;
      var scoreDatas = receiveStatement.split(" ").slice(2);  convert the filtered messages in array

      /*the rest of the code parse and send values of scoreDatas to each html item using for loop on the array and document.getElementById().value*/
 }

    function score() {
      scoreOn = true;
      init();
      ctrl();
      csound.ReadScore(document.getElementById("scoreTest").value);
      if (started == false) {
        CsoundObj.CSOUND_AUDIO_CONTEXT.resume();
        started = true;
      }
    }

For test online, just click on score button: http://csound.jeanbasilesosa.com/

Maybe have you an idea about my p2 problem when I trigger the score function?

Mery christmas,

Jean Basile

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here