crucialfelix / supercolliderjs

The JavaScript client library for SuperCollider
https://crucialfelix.github.io/supercolliderjs/
MIT License
472 stars 41 forks source link

Receiving async notifications from sclang #39

Open jamesopstad opened 6 years ago

jamesopstad commented 6 years ago

Hi,

I'm just getting started with supercolliderjs and I'm not clear on the best way to receive data back from sclang. For example, I would like to boot the server in sclang and receive a response in node when it has booted. This is what I tried:

const sc = require('supercolliderjs')

sc.lang.boot().then(sclang => {
  sclang.on('stdout', msg => {
    if (msg === 'BOOTED') {
      console.log('Server Running')
    }
  })
  sclang.interpret('s.waitForBoot({ "BOOTED".post })')
})

It works sometimes but isn't consistent which makes me think there must be a better approach.

Thanks

crucialfelix commented 6 years ago

Yeah this mixes two different ways of working which gets confusing.

supercolliderjs has promises, and then you are running s.waitForBoot in the language.

two horses

sc.lang.boot().then(sclang => {
  sc.server.boot().then((server) => {
     // now you have both running

  })
})

or

Promise.all([sc.lang.boot(), sc.server.boot()]).then((sclang, server) => {
   // both are running
});

There could be a short cut for that one.

I hope to get some time this summer to write a lot more docs and do a new release. Questions are appreciated

jamesopstad commented 6 years ago

When I run this I get

**stderr : * ERROR: open directory failed 'synthdefs'

I need access to synthdefs created by the class library and haven't worked directly with the server before. How do I get the same functionality as I would by booting the server from sclang?