Mapper fails on application start

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.

I’ll give another example using one of the example scripts provided with Score’s “Serial” device, specifically for the “DigitalReadSerial” example which has its corresponding Arduino code here: https://docs.arduino.cc/tutorials/uno-rev3/DigitalReadSerial?queryID=58626395742ce0eaa4ea6ca83514e12e

I’ve uploaded my Score project (will last a week) here:

It contains 3 devices: 1) DigitalReadSerial (the serial device with a single child “buttonState”), 2) OSC (an OSC device with a single Boolean child “buttonState”) and 3) Mapper (a mapper device with the child “button” that is bound to DigitalReadSerial/buttonState and writes to OSC/buttonState.

This also has the same problem as in the post above. It works fine after the Mapper device is edited, however does not not function when Score is first opened and the project loaded. ie. it’s necessary to re-edit the Mapper, to get it to work.

I’m testing on an aarch64 raspberry pi with Score 3.1.8.

Cheers