Hi, and sorry I’m back so soon! While my mapper, from Thibaud’s suggestion last post, works, it fails when Score is reinitialised. To fix it, I need to edit the Mapper and refresh the namespace. My guess is that the serial device it’s reading from is passing it some value it doesn’t like. At one point I was had bound the mapper to a float type and the value in the bound child was “nan” (NaN, I assume) on restart. Tried lots of things including checks with isNan() but nothing would fix it.
Trying presently to bind Bool types only. Here is the Mapper script I’m testing:
import Ossia 1.0 as Ossia
Ossia.Mapper
{
function createTree() {
return [
{
name: "red",
bind: "Arduino:/red",
type: Ossia.Type.Bool,
write: function(v) {
if(v.value) {
return [ { address: "score:/reinit", value : 1 }, { address: "score:/play", value : v.value } ];
}
}
},
{
name: "green",
bind: "Arduino:/green",
type: Ossia.Type.Bool,
write: function(v) {
if(v.value) {
return [ { address: "score:/reinit", value : 1 }, { address: "score:/play", value : v.value } ];
}
}
}
];
}
}
And this is the serial script:
import Ossia 1.0 as Ossia
//import Score 1.0 as Score
Ossia.Serial
{
property var lastmsg: "0,0,0,0"
function openListening(address) {}
function closeListening(address) {}
function onMessage(message) { // evaluated each time a message is received
//console.log(message);
var redVal, greenVal, blueVal;
if(message != lastmsg) {
const msgAr = message.split(" ");
//console.log(message);
lastmsg = message;
redVal = msgAr[1];
greenVal = msgAr[2];
blueVal = msgAr[3];
if(redVal == "1") {
redVal = true;
} else {
redVal = false;
}
if(greenVal == "1") {
greenVal = true;
} else {
greenVal = false;
}
if(blueVal == "1") {
blueVal = true;
} else {
blueVal = false;
}
return [{address: "/volume", value: msgAr[0] / 1023}, {address: "/red", value: redVal}, {address: "/green", value: greenVal}, {address: "/blue", value: blueVal}];
}
}
function createTree() {
return [
{
name: "volume",
//bind: "Pi:/Vol",
type: Ossia.Type.Float,
min: 0,
max: 1023,
access: Ossia.Access.Get,
bounding: Ossia.Bounding.Clip,
repetition_filter: Ossia.Repetitions.Filtered
},
{
name: "red",
type: Ossia.Type.Bool,
access: Ossia.Access.Get,
repetition_filter: Ossia.Repetitions.Filtered
},
{
name: "green",
type: Ossia.Type.Bool,
access: Ossia.Access.Get,
repetition_filter: Ossia.Repetitions.Filtered
},
{
name: "blue",
type: Ossia.Type.Bool,
access: Ossia.Access.Get,
repetition_filter: Ossia.Repetitions.Filtered
}
];
}
}
Any suggestions, please?
Thanks
Edit: Checking the messages received from the serial port from the beginning, after initialising Score, all the values seem valid.