Cabbage Logo
Back to Cabbage Site

Texteditor to initialise Arrays

Hello everybody!

I need some help with an actual project.

I want to write a VST with which i can load some arrays and update the running VST.

More precise:
Outside of Csound i want to create my arrays as a file, which i used to load to Csound via a #include statement.
With the VST via the texteditor widget i want to realise now what i did before via #include.
Is it possible to load these files into a running csound instr? Or do i have to create multiple instr for different taks? For example one is receiving the String from the texteditor, antoher one is compiling the string?

How should i takle this?

One big difference here is that the way you used to do it was done at compile time. At run-time you will need to take care your instruments are loaded first. How you go about compiling the files is up to you. You can compile Csound code at run-time using compilestr or some such opcode. Note you can also load the files from disk straight into Csound without the need of a texteditor using one of the file input/output opcodes.

I guess I’m curious as to why you want to load them to the texteditor first?

I guess i wanted to use the texteditor, because i thought i need some of the features of it. But maybe a filebutton would also work?

I didn’t use compilestr yet and i don’t know what syntax must be inside of a file for this.
Also i’m wondering how i need to initialize the arrays in before, because of errors that are related to the instrument handling these arrays.

I don’t get it completely right now how i would handle this, so i do a small sketch:

instr 1 
 when the value of a filebutton is changed then compilestr (?) it
  in the file there is this: 
       instr 2
          when there is already an instance of instr 2 turn it off
          gkArray1...
          gkArray2...
          gkArray3...
       endin
endin

instr 3
  this instrument is working the arrays
endin

Hmm, I thought this would work. I’m going to ask around and see if this is expected behaviour or not.

So the issue is that those arrays aren’t known when instrument 3 is compiled. So you either

  1. Declare the global arrays in your main .csd file, and then populate them in the instrument you compile with compilestr
    gkArray1[] init 4
    gkArray2[] init 4
    gkArray3[] init 4

    instr 1 
        iRes compilestr  {{
            instr 2
                gkArray1[0] = 99
                gkArray1[1] = 99
                gkArray1[2] = 99
                gkArray1[3] = 99
            endin
            schedule(2, 0, 1)
        }}
    endin

    instr 3
      printarray gkArray1, metro(1)
    endin
  1. Hold off compiling any instruments that need access to the arrays until after you have compiled instr 2
    iRes1 compilestr  {{
        instr 2
            gkArray1[] init 4
        endin
        schedule(2, 0, 1)
    }}
    
    iRes2 compilestr {{
        instr 3
            printarray gkArray1, metro(1)
        endin
        schedule(3, 1, 1)
    }}
endin

I guess option 1 is probably the simplest as you’re going to need to know the global variables names anyway.