Rationale: I just ported one of my Nebulae customer instruments to work with docB’s excellent VCV Rack Csound module. It occurred to me that the Rack module could be a great way to prototype/debug Nebulae code, because it’s difficult to do this in the Nebulae environment. The Rack modules uses channels cor controls/inputs vs Nebulae which uses globals. It wou;d be cool to be able to write the same (or more similar) code for both environments.
I think you can use csoundCompileOrc to create globals (or add instruments, gens) on the fly.
But other instruments that use those globals should be created later otherwise you will have a runtime error.
Those API functions are not used to set Csound global variables, they are used to set C variables/memory in the Csound object. Csound code does not have access to them.
As Giovanni said, the only way to set global variables is via compilation, or through Csound
events (using pfields to instruments), or try chnexport
In the instrument, I simply refer to these global variables. All variables are prefixed with type and instrument name to avoid name collisions.
In the host software (HTML5) there is a kind of generic thing that depends on the global variable, the control channel, and the HTML input element all having exactly the same name:
('input').on('input', async function(event) {
var slider_value = parseFloat(event.target.value);
if (csound) {
csound.SetControlChannel([event.target.id](http://event.target.id), slider_value);
}
var output_selector = '#' + [event.target.id](http://event.target.id) + '_output';
(output_selector).val(slider_value);
});
I haven’t tried sending control signals from Csound to the host software.