HISE Logo Forum
    • Categories
    • Register
    • Login

    Snex: pointers, templates, structures & references

    Scheduled Pinned Locked Moved Solved ScriptNode
    5 Posts 2 Posters 236 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • griffinboyG
      griffinboy
      last edited by griffinboy

      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.

      griffinboyG 1 Reply Last reply Reply Quote 0
      • griffinboyG griffinboy marked this topic as a question on
      • griffinboyG
        griffinboy @griffinboy
        last edited by

        @griffinboy

        : 3

        Christoph HartC 1 Reply Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @griffinboy
          last edited by

          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:

          Link Preview Image
          HISE/tools/snex_playground/test_files/template at develop · christophhart/HISE

          The open source framework for sample based instruments - HISE/tools/snex_playground/test_files/template at develop · christophhart/HISE

          favicon

          GitHub (github.com)

          griffinboyG 2 Replies Last reply Reply Quote 1
          • griffinboyG griffinboy has marked this topic as solved on
          • griffinboyG
            griffinboy @Christoph Hart
            last edited by

            @Christoph-Hart

            Thanks, that's good to know!

            1 Reply Last reply Reply Quote 0
            • griffinboyG
              griffinboy @Christoph Hart
              last edited by griffinboy

              @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! : )

              1 Reply Last reply Reply Quote 0
              • griffinboyG griffinboy has marked this topic as unsolved on
              • griffinboyG griffinboy has marked this topic as solved on
              • First post
                Last post

              34

              Online

              1.7k

              Users

              11.9k

              Topics

              103.5k

              Posts