# Texteditor to initialise Arrays

**URL:** <https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008>\
**Category:** Cabbage Stew\
**Created:** [13 December 2023 19:11 UTC](https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008 "2023-12-13T19:11:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ph\_ne](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@ph\_ne](https://forum.cabbageaudio.com/u/ph_ne)\
**Post date:** [13 December 2023 19:11 UTC](https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008/1 "2023-12-13T19:11:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [13 December 2023 19:46 UTC](https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008/2 "2023-12-13T19:46:21Z")

</div>

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](https://csound.com/docs/manual/compilestr.html) 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](https://csound.com/docs/manual/SigioTop.html#SigioFileIO).

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

---

<div class="post-metadata">

**Author:** ![ph\_ne](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@ph\_ne](https://forum.cabbageaudio.com/u/ph_ne)\
**Post date:** [14 December 2023 07:34 UTC](https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008/3 "2023-12-14T07:34:25Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 December 2023 09:40 UTC](https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008/4 "2023-12-14T09:40:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 December 2023 13:52 UTC](https://forum.cabbageaudio.com/t/texteditor-to-initialise-arrays/4008/5 "2023-12-14T13:52:27Z")

</div>

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.
