Snex: pointers, templates, structures & references
-
Hey,
Does anyone here have a deep understanding of SNEX? ( @Christoph-Hart )
Because I would appreciate some insight.Could you please give me a quick rundown on
- Pointers
- Templates
and how they can be used in SNEX?
I'm not talking about the ones that are already prepared inside a snex node by default.
Rather, I would like to create my own custom templates and pointers inside SNEX.The online documentation rushes over these points and I found that I didn't have enough information to use these features in my own SNEX code.
-
-
: 3
-
Pointers are deliberately ommited from the SNEX feature set because it's too easy to bring the system down with a simple typo.
Instead it heavily makes use of the
&
-reference operator when you want to operate on an object that's defined somewhere else.struct MyData { int value = 90; }; void doSomething(MyData& d) { d.value = 100; }
Templates are basically the same as in C++, but since this is a beast of a concept, it only supports a limited feature set.
Have you checked out the SNEX playground? It's a lightweight project that gives you a code editor and the SNEX compiler and allows you to explore different language features as well as write some tests (most of the unit tests for the SNEX compiler are written with this).
There are a bunch of tests for the template concept here:
https://github.com/christophhart/HISE/tree/develop/tools/snex_playground/test_files/template
-
-
Thanks, that's good to know!
-
@Christoph-Hart
Apologies but I am going to have to ask a rather technical question!Is there any way at all for me to store a reference (&) in an array?
I looked over the docs and ran multiple tests in the SNEX playground that you recommended, but I've had no luck.
What I am trying to do may be beyond SNEX's capabilities.
I am creating a virtual circuit. It is modular, you can declare any component and attach it to another.
I have created classes for each component type, these classes contain dsp .
These have constructors which allow me to declare new component objects easily.But what I need to do now, is create a script which can link these objects together, and then run an audio signal through them. Each object will pass the signal to the next object until it finally reaches the output, having been processed through each of them.
The issue is, I need to store pointers to these objects in an array.
This is necessary so that I can link the objects together and create a modular signal path. Each component object has multiple terminals (functions) inside, and these terminals can be linked to any other terminal inside another object, so it's quite important that I can point to them, to store the instructions of how the circuit all comes together.Is there any solution to this in SNEX? I have tried all the standard C++ methods to achieve this and have failed. The latest method I tried was to fill a SPAN array with references (&) which it did not accept and gave me a casting error.
The alternative is to create a bunch of individual functions and a FAT stack of IF statements to create the modular logic. As long as SNEX is able to compile functions down cleverly, then this should run very efficiently. Does SNEX work that way?
Thanks for your time I appreciate it! : )
-
-