Starting a new thread as there are number of bits of discussion on this so this will hopefully track all my progress as I get through - eventually being able to read xml directly into the custom module to use.
I've installed from the console into the custom module directory using npm install xml2js and that has created the required directories as per the guidance from @jean-emmanuelhere
This is the extract from my custom module that lads ok without it.
//xml to json test
const xml2json = requireNative('xml2json');
var xmlStr = "<root><person><name>violin</name></person></root>";
var json = JSON.parse(xml2json.toJson(xmlStr))
console.log('xmlinput string - xmlStr' + xmlStr)
console.log('json' + json)
I thought at least I might get a bit through this before asking for some help but I've already hit a bump in the road as I'm getting this error on the console
This is not specific to open stage control but rather a common issue when working with electron (the binary that ships node with open-stage-control) and what's called native modules (C++ modules that need to be compiled to work). You have two solutions:
// convert XML to JSON using xml-js
var convert = nativeRequire('xml-js');
//accessing this small xml locally here
var localxml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>THIS IS XML IN CUSTOM MODULE</title>' +
' <todo>Maybe a violin</todo>' +
' <todo>Play con sordino</todo>' +
'</note>';
//now accessing an xml in a file structure
const fs = nativeRequire('fs');
const path = nativeRequire("path");
var xmlFromFile = fs.readFileSync(path.resolve(__dirname, "../BlankMap.expressionmap"));
//var xmlFromFile = fs.readFileSync('user.xml')
var options = { compact: true, spaces: 0};
var result1 = convert.xml2js(localxml, options);
var result2 = convert.xml2json(localxml, options);
var result3 = convert.xml2js(xmlFromFile, { compact: true, spaces: 0 });
var result4 = convert.xml2json(xmlFromFile, { compact: false, spaces: 0 });
console.log('-----------------------------------------------------------');
console.log('Result 1 - OBJECT IN CUSTOM MODULE' + result1,);
console.log('-----------------------------------------------------------');
console.log(' ');
console.log('-----------------------------------------------------------');
console.log('Result 2 - JSON FROM XML IN CUSTOM MODULE' + result2);
console.log('-----------------------------------------------------------');
console.log(' ');
console.log('-----------------------------------------------------------');
console.log('Result 3 - OBJECT FROM XML FILE IN FILE STRUCTURE' + result3,);
console.log('-----------------------------------------------------------');
console.log(' ');
console.log('-----------------------------------------------------------');
console.log('Result 4 - JSON FROM XML FILE IN FILE STRUCTURE' + result4);
console.log('-----------------------------------------------------------');
open your generated json in the browser (i use chrome)
hit F12 to open the chrome dev tools
hit the network tab and then preview
this shows you the structure of your json file. when you found your needed entry, you can right click and copy the path to that entry like we had here. as in cubase expression maps it's always the same structure we can use this one:
The idea is to loop thorough the js or json and collect all the instrument map definitions and create a new object, then loop through all the expression maps in the directory to create a full set of objects. I can then use these objects in place of the text strings in my custom module.
This is tonight’s challenge but I’m away from my machine currently…
You don’t need to map it to the track directly. You need to tell OSC what articulations to put in the buttons.
You extract a track Identifier to get the custom module to choose which map to use them custom module maps the buttons. I’d you put something In the track name in cubase that identifies which map you have assigned in cubase then you can extract that in OSC from the sysex that it’s sent.
For example - Cubase track name might be
Violins 1 map005
You send the name to OSC from cubase - get the cm to pull the map005 from the track name and then pull the articulations from the xml for map005 and send it to the buttons.
this works all as expected. i think i just did it the complicated way. i coded it for every track with the if statement. works fine but just never ends with copy pasting editing and all that stuff.
i guess i have to think the other way around with coding. i always start with the smallest and keep copy pasting it.
things are getting clearer now