What's new

Saving Numbers & Strings into a single file

Hi,

I'm working on a multi-script and I'm trying to figure out how to save different script variables (numbers) and strings (text) into a single NKA file.

I don't want the user to save two external NKA's (one for variables and one for strings)...

Is this at all possible?

Thanks!!!
HD
 

P.N.

Senior Member
You can't mix strings, integers or real numbers in the same array...
Integers and real numbers you mght get way with conversions and use a single array (either with integers or real numbers), depending on your goals, but strings are another matter.
 

P.N.

Senior Member
Well, if you only needed to save a string variable, you could save_array_str() and use the string as the name of your integer array.
After, you may use a file selector to browse the integers arrays that were saved with the string name... but... i don't know if this helps your specific scenario.
 

Lindon

VST/AU Developer
The way we used to do this was with number substitution. Strings(each character) represented as numbers 0 to 26 and remapped using a string array containing the alphabet.

We actually used more than 26 slots so we could have spaces , hyphens etc.
 

P.N.

Senior Member
The way we used to do this was with number substitution. Strings(each character) represented as numbers 0 to 26 and remapped using a string array containing the alphabet.

We actually used more than 26 slots so we could have spaces , hyphens etc.
Can't do anything for text_edits, but it might be useful to the OP. :)
 
OP
dfhagai

dfhagai

HD
The way we used to do this was with number substitution. Strings(each character) represented as numbers 0 to 26 and remapped using a string array containing the alphabet.

We actually used more than 26 slots so we could have spaces , hyphens etc.
Any tip on how to achieve that would be much appreciated :)
 

P.N.

Senior Member
Hey, dfhagai.

I can show you how to make integers match strings, but this is actually not as useful as it seems in practice because the opposite is not possible with text_edit controls.
Your reason for doing this is saving a single file, for which the user can then save a filename and the preset in the same file, correct?

Saving an array in which the file name is the name of the preset, and the preset is made up of integers comprising the values for that array is the way to go in this scenario with save_array_str().

If you were to have a integer to string segment built into the integer preset file (and using it as a multidimensional array), the user wouldn't have a way to input the preset name into that file.
We have no way of retrieving characters from a text edit control.

The only solution for this would be including a virtual keyboard into your main script so that the user could in fact type in a preset name.
 

Lindon

VST/AU Developer
Well as P.N says the number->text substitution isnt any use to you if you want to have users re-name presets, and that be saved in some array, then string-arrays are your friend - in fact I started doing this before string arrays were savable things, so anyway here's a quick run thru:

Code:
declare !alphabet[38]
    !alphabet[0] := "A"
    !alphabet[1] := "B"
    !alphabet[2] := "C"
    !alphabet[3] := "D"
    !alphabet[4] := "E"
    !alphabet[5] := "F"
    !alphabet[6] := "G"
    !alphabet[7] := "H"
    !alphabet[8] := "I"
    !alphabet[9] := "J"
    !alphabet[10] := "K"
    !alphabet[11] := "L"
    !alphabet[12] := "M"
    !alphabet[13] := "N"
    !alphabet[14] := "O"
    !alphabet[15] := "P"
    !alphabet[16] := "Q"
    !alphabet[17] := "R"
    !alphabet[18] := "S"
    !alphabet[19] := "T"
    !alphabet[20] := "U"
    !alphabet[21] := "V"
    !alphabet[22] := "W"
    !alphabet[23] := "X"
    !alphabet[24] := "Y"
    !alphabet[25] := "Z"
    !alphabet[26] := "1"
    !alphabet[27] := "2"
    !alphabet[28] := "3"
    !alphabet[29] := "4"
    !alphabet[30] := "5"
    !alphabet[31] := "6"
    !alphabet[32] := "7"
    !alphabet[33] := "8"
    !alphabet[34] := "9"
    !alphabet[35] := "0"
    !alphabet[36] := " "
    !alphabet[37] := "_"
-- so we've declared a a mapping of numbers to characters; now all we need do is create a fixed number (lets say 12) slots in our numeric array to hold the name.

Code:
    %preset_array[0] := 7
    %preset_array[1] := 4
    %preset_array[2] := 11
    %preset_array[3] := 11
    %preset_array[4] := 14
    %preset_array[5] := 36
    %preset_array[6] := 22
    %preset_array[7] := 14
    %preset_array[8] := 17
    %preset_array[9] := 11
    %preset_array[10] := 3
    %preset_array[11] := 36
Now all you do is save and load this numeric array as normal and then run a small function over it to get your string back:
Code:
    declare @temp_name
    declare const MAX_NAME_LENGTH := 12
    for idx := 0 to (MAX_NAME_LENGTH -1)
        @temp_name := @temp_name + !alphabet[%preset_array[idx]]
    end for
@temp_name now contains "HELLO WORLD "
 
Last edited:
OP
dfhagai

dfhagai

HD
Thanks P.N & Lindon! much appreciated.

I've built a 8 channel multi-script mixer (volume & pan).
It has 8 ui_text_edits under each channel so that the user could freely label each track.

I now understand that it is simply impossible to create a single preset that will save the volume, pan position and track names into a single file...very limiting...

The only solution for this would be including a virtual keyboard into your main script so that the user could in fact type in a preset name.
Might just do that, or give the user a stock list of general names to choose from (strings, brass, winds, synths, guitars etc...).

Thanks again!
 

P.N.

Senior Member
in fact I started doing this before string arrays were savable things
That's what i was thinking when i saw your post.


Might just do that, or give the user a stock list of general names to choose from (strings, brass, winds, synths, guitars etc...).
Yeah, i mean, you could do the save_arr_str() thing instead...

But, just for proof of concept and curiosity, here's something similar to what Lindon posted.
This one uses an array based on the Windows 1252 protocol but modified in order to make it more user friendly. (null character is represented by 0, space by 1 and so on).

It's has live virtual keybiard input, but only of the main alphabet. (didn't feel like adding more...)
Adding more characters to this would be extremelly easy though, since it already has the arrays ready to go.

You can see the corresponding numbers for each character, which could be something fun to play around with.
Still, i wouldn't recommend implementing this in a real instrument.
Just have fun with it. :)

PS: The code's a little rough around the edges.

Untitled-1.jpg

Cheers.
 

Attachments

Top Bottom