ui
ui copied to clipboard
Sockets changing Nexus
Hello and good day! I am posting this issue because I am instantiating a received socket to change the GUI value and I'm getting problems. Almost all the time I receive a socket that wants to change a slider or a knob from other person (like as I'm changing mine, I change all others) the software freezes. But if I instantiate it to just control tonejs audio there is no problem, only when I want to change the nexus uis I am doing it like this (values is an array of vars for each widget) socket.on('uiSocketSynthVolume', function(data) { if (isStreaming == true) { if (data.y == "synthVolume") { //polySynth.volume.value = data.x; values[0] = data.x; if (UI.synthvolume.value != values[0]) { UI.synthvolume.value = values[0]; } } else { console.log(""); } } }); And a socket.on all the other users to when they change it Best, Luis
Hi Luis, this is freezing because it creates an infinite loop or socket emissions.any time you set the value of a dial, the 'change' function is called. So the sequence of events in your situation is:
You change a dial It emits the value through a websocket All other dials are set to that new value All those other dials emit their value through the websocket All dials are again set to that value Etc
Their needs to be a built-in solution to this kind of loop. I believe there is already. I'll look at the code and get back to you.
Thank you for quick answer, as always. I hope we can fix this. Best, Luis
Luis, can you give me a complete list of the types of interface components you are using in this setup? You mentioned sliders and knobs -- anything else?
Basically, I don't see an easy general solution, and this was unfortunately an oversight of the version 2 API I created. I think it will take some extra development to resolve, which I can't do at the moment. But if you let me know the types of interfaces you are using, I can send you patch functions which will get the job done for your project at the moment.
Thank you very much for the quick answer Taylor. Well at the moment I am using only sliders and knobs yes! I have buttons but are not actually from NexusUI and I am not broadcasting them Let me know if I can help, Luis.
In both cases (slider and dial) you can use the following code to set the value without causing the slider/dial to trigger its 'change' function.
dial1._value.update(v);
dial1.render();
However, since this causes the dial/slider to update without triggering its 'change' function, that means it will also not execute any web audio code you have in its 'change' function. So you will need to manually duplicate your web audio code here in the socket listener. It's not great -- again, this is a temp fix to keep your project rolling.
dial1._value.update(v);
dial1.render();
// web audio code goes here
polySynth.volume.value = v
I will keep thinking about a more elegant solution for this.
Thank you again taylorbf, always accurate. I didn't answer before due to personal impossibilities I just tested this, seems to work perfectly. Didn't test with sockets both ways and 50 people at the same time but the architecture seems to solve the problem. Best, Luis