Welcome to %s forums

BrainModular Users Forum

Login Register

script question--populating listbox in script from file

I need help on a Patch
Post Reply
woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 02 Dec 2008, 02:07

I'd like to create a script that would allow me to read a textfile containing a tabbed list like so:

7 volume
8 decay
10 pan
37 filter cutoff

etc.

assign the names to slots in a listbox. Have a fader input whose value is output as a MIDIcc with a number corresponding to the selected control name.

It all seems pretty doable, but I'm unsure of a few things:

When I populate a listbox with strings, is that set of strings only read when I attach the listBox? Otherwise, maybe I should have a fader which updates a textfield instead.... I wish there was the notion of a textFader, but maybe I can create that, just by dynamically updating the caption of the fader based on its output value.... ugly recursive wiring, but it might work.

I'm excited, because I'll have many of these controls, and I can have them all read from the same file, and can therefore update them all at once.

Things I don't know:

how to read or refer to a 'tab'. or double-quotes--what are the escapes for these? End--of-line is addressed in the textfile example.
Is there a way to get the directory of the usine installation? The read-from-text example uses a static file on the root of the c drive....

Thanks as always! My setup is slowly coming together, and I'm having fun.

cheers,
-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 02 Dec 2008, 08:33

Haven't got much time right now, but at least I can give you the ASCII numbers for (horizontal) tabs and double quotes (assuming that is what you mean by escapes). Tab is 9 and double quote is 34.

I'd like to add that you seem to have some very good ideas for streamlining your workspaces!
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 02 Dec 2008, 19:12

I realize now,it doesn't look like I need to escape the quotes. If I read from a file and save the result as a string, I can just use that, and I don't need the quotes (I assume....) I'm going to go ahead and set an output string, rather than using a listbox.

I'm still not sure what the command 'read in characters until you get a tab' would look like.

while char <> 9 do

??

Surely, that won't work..... Alternatively, I could read all the lines into a stringlist, and then break up each line into a record containing a string and an int. But still not sure how to recognize that tab character.

Also, I can find no reference to the TStringList object in the help. Not sure how it works, although maybe I have all I need in the 'read from file' example script.

thanks!
-e
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 02 Dec 2008, 20:39

Okay, 't' doesn't create a tab, it just creates the characters, and 9 and t without quotes give errors.

Can't figure out how to make a tab....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 02 Dec 2008, 20:47

okay, I found this on the web, in a discussion of PASCAL:
<quote>
There is no way to put non-graphic symbols into strings. In fact, non-graphic characters are unpersons in a stronger sense, since they are not mentioned in any part of the standard language. Concepts like newlines, tabs, and so on are handled on each system in an 'ad hoc' manner, usually by knowing something about the character set (e.g., ASCII newline has decimal value 10).
</quote>

I'm not sure how to get or set the ascii character via number.

Otherwise it seems like I'll need to hear from senso.....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 02:21

Okay, I got this working, with "$" for a delimiter, and it's a simple find/replace on the textfile, so no big deal... Tabs would be more transparent.

I'm having the issue that I'd like to get the directory path and file name from an external connection, but it seems that that will mean putting the filereading code in the main method--if I put it in the init method, the output can't have been cabled yet, and therefore I must re-read the file data with every event loop. Is there a way to check whether the filename input has changed?

Or another graceful way to do this? I really want the file directory to be an external input for portability. Unless the script has a way to find out the usine directory.....

Any help appreciated as always!

-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 03 Dec 2008, 09:50

I don't know if/how you can get to external variables from within scripts, but if there's a way I guess defining a environment variable (like PATH or HOME etc) would do the trick. You could also try to have some sort of .ini file. I think both can be done within the init proceduire.

A trick that I often use when I have a lot of relatively static input parameters, is to connect all the faders or whatever to a HasChanged module and connect that to a corresponding input in the script. Then the script only has to check one value for most of the iterations. You can also connect a OnActivation to the script to make sure that the values are read after activation of the patch. Another thing you can do if the values won't change after the first initialization, is to use a boolean:
IF (first) THEN BEGIN
first := FALSE;
GetValue(....

Hope this helps somewhat.
Bjørn S

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 03 Dec 2008, 10:41

Just remembered another trick I've used for reducing the number of times the input parameters are read, suitable for parameters that can change a lot, but the "timing" can be a bit sloppy: Create a counter that increments with 1 for each execution block, and code something like this:

IF ((counter MOD interval) = 0) THEN ...

If the input parameters are defined as an array of parameters you can also spread the execution using a counter:

GetValue(inputArr[(counter MOD interval)]
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 18:39

Wow, bsork, this is all AWESOME info. Thanks!!!!!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 18:45

what is the clock rate for using modules, btw?

I seem to recall seeing that somewhere in the manual.... I'll go look.
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 18:53

Okay, bsork, I've implemented BOTH these strategies, loading the ccs from disc on the first iteration, and checking some inputs only every 16(for now) cycles. EXCELLENT! But one more question:

how can I get an internal variable to have it's state remembered independently for each preset? Do I have to expose an input to get a value saved with a preset? What all does usine look at when it creates a preset?

Thanks!
-e
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 03 Dec 2008, 23:02

I suppose you be "clock rate" mean how often the patches are calculated? If you haven't found it yet, it's in the "Data & Flow Types" chapter in the manual:
This is the most complex section of this manual. Usine is “Intuitive” and you don’t need to understand all the concepts at the beginning. Of course, it will be necessary if you want to become an expert user.

The most important thing with Usine is to understand that the input sound is sliced and processed by blocks of samples. The best block size is calculated automatically, and is normally, something like 64,128. (see Setup Asio p18).

At 44100Hz sample rate, with a 64 samples block size, patches will be recalculated each 64÷44100 = 1.45ms or approximately 690 time per second!
If you want to store different variable values per preset, it has to be done outside of the script. AFAIK, anyway... I'm not sure of exactly how much is stored by the Preset Manager (or the Conductor), but I can't remember experiencing anything else but script stuff not being stored (unless when using the Conductor/Preset Isolate option, of course). I guess the value of input parameters are stored like anything else though, but I haven't tried it as I always connect something to them.

You could use a trick similar to the HasChanged one above with values that are only changing with the presets. If you get any problems reading the new value, you can try with a WaiOneCycle after the HasChanged.
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 23:53

okay, question: if I need an array of values to be saved, how could I cable that up?

My problem is that I'd like to save the position of encoders with the preset, since they have no actual 'position'.... I guess I can figure out how to do this with cabling.

thanks!
-e
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Dec 2008, 08:36

If you mean arrays connected to scripts, you should put a StopEventFlow or PassEventFlow (whatever is most fitting) between the script and the array module so that the initialization/compiling of the script won't empty the array. In fact, that's the case for any data, arrays and single values.
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 04 Dec 2008, 18:58

is that only on the output of the script?? Or for the input too??
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Dec 2008, 23:10

Only the outputs, as the script is controlling what and when the input data is read anyway.

I've created quite a few patches where the data is stored in arrays, but manipulated and populated by a script; one of them is the Midi Mapper in the distro. Take a look at that one or some of the other big/complex patches of mine found in the add-ons.
Bjørn S

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests