yes
no
It should really be done better (i.e.: with bidirectional event-based sending) but, lacking that, here is something that works now:
sketch.js:
let boxes = Array();
const numBoxes = 3;
function ignoreInput(e)
{
e.preventDefault();
}
function sendInput()
{
let n;
for(n = 0; n < boxes.length; ++n)
if(this == boxes[n])
break;
if(n < boxes.length)
{
let obj = {};
let value = parseInt(this.value());
if(!isNaN(value))
{
obj["box" + n] = value;
Bela.control.send(obj);
}
}
}
function setup() {
for(let n = 0; n < numBoxes; ++n)
{
boxes.push(createInput());
boxes[n].position(10, n * 30);
boxes[n].size(100);
boxes[n].input(sendInput, n);
}
createCanvas(windowWidth, windowHeight);
}
function draw ()
{
clear(); // clear any text
if(Bela.data.buffers.length < 1) {
// haven't received enough data yet
return;
}
for(let n = 0; n < numBoxes; ++n)
{
// receive on buffer 0
let label = 'box'+n+': '+Bela.data.buffers[0][n];
text(label, 120, 15 + n * 30);
}
}
Pd:
aka:
#N canvas 88 22 900 571 10;
#X obj 28 189 loadbang;
#X obj 79 530 s bela_guiOut;
#X text 91 509 send to the Bela GUI;
#X obj 126 267 f;
#X obj 191 283 + 1, f 5;
#X obj 171 383 + 10;
#X obj 268 215 r bela_guiControl;
#X obj 44 118 s bela_setGui;
#X obj 44 72 loadbang;
#X msg 44 95 new control box0 \, new control box1 \, new control box2;
#X obj 266 275 route box0 box1 box2;
#X floatatom 124 374 5 0 0 0 - - - 0;
#X floatatom 199 362 5 0 0 0 - - - 0;
#X msg 77 403 0;
#X obj 81 480 pack f f f f;
#X text 9 447 send on buffer 0;
#X floatatom 262 365 5 0 0 0 - - - 0;
#X obj 28 211 metro 1000;
#X text 101 75 Create the receivers;
#X obj 26 242 t b b;
#X text 271 246 Receive from the GUI;
#X connect 0 0 17 0;
#X connect 3 0 11 0;
#X connect 4 0 3 1;
#X connect 5 0 14 2;
#X connect 6 0 10 0;
#X connect 8 0 9 0;
#X connect 9 0 7 0;
#X connect 10 0 11 0;
#X connect 10 1 12 0;
#X connect 10 2 16 0;
#X connect 11 0 4 0;
#X connect 11 0 14 1;
#X connect 11 0 5 0;
#X connect 12 0 5 1;
#X connect 13 0 14 0;
#X connect 14 0 1 0;
#X connect 16 0 14 3;
#X connect 17 0 19 0;
#X connect 19 0 13 0;
#X connect 19 1 3 0;
GUI:
you can type into a box while the text next to it shows the latest value sent from Pd.