Csound api and CompileOrc()

I’m developing a plugin for Bidule using their sdk that basically is integrating an instance of Csound api, and will be able to compile any valid orc code that is entered into a text box in the gui.

What’s the standard practice to recompiling orc code using the cpp api, when an instance of Csound is already running?

I have set up the initial orc (and sco) code in the init() method in the plugin, that works fine, but when I recompile some (valid) orc code that replaces the same instr 1, I get some nasty, loud glitchy output and the whole instance basically crashes and eventually brings down Bidule.

Is there a special order to doing this within C++?

I’m not using compilestr or any of the Csound opcodes for this - only within C++

This is the general idea:

// gets called when a button is pressed.
CsoundTest::recompileOrc() {
 
    if (_recompileTrig == 1) {
        // csound->Reset(); <- does this need to be called at all?
        _csCompileResult = csound->CompileOrc(templateOrc.c_str());

        if (_csCompileResult == 0) {
            csound->ReadScore("i1 0 4 220");  // <- restarts a new instance of instr 1
        }
        _recompileTrig = 0;
    }
}

thanks!

I’ve found the cleanest way to do this is to destroy Csound and create a new instance of it.

csound = nullptr;
csound = std::make_unique<Csound> ();

It’s not pretty, but do the job. I had issues with some resources not being freed when calling csound->Reset(), which would in turn lead to other issues.

Ah right, brute force! cool will try that.

One thing I did think was, when I recompiled, the orc code was including

"sr=48000\n\
    ksmps=64\n\
    nchnls=2\n\
    0dbfs=1\n\
    chn_k \"phsRate\", 1\n\
    chn_k \"pitch\", 1\n\
    chn_k \"amp\", 1\n\";

each time, rather than just the instr code.

Could that muddle things up?

Thanks