HISE Logo Forum
    • Categories
    • Register
    • Login

    How should I implement a common method in multiple namespaces

    Scheduled Pinned Locked Moved Scripting
    3 Posts 2 Posters 277 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.
    • R
      RCJacH
      last edited by

      Let's say I have A B C three articulations, and each with a namespace implementing a RR count (using namespace because it's local to a script).

      I want to use the getNextRR() method in the corresponding namespace based on Message.getChannel(), because each is implemented differently. How should I approach this?

      The problem is that we can't add namespaces themselves to a list, only methods from namespaces.

      I can think of three ways to make this work, but each with drawbacks.

      1. The simplest way is to use a switch condition, it works fine but lots of code for each method, plus switch in Javascript is not performance friendly.

      2. Keep only the RR count in namespace, and implement another set of objects with corresponding methods calling Namespace.RR. Methods from objects work, but this method is convoluted and I'm not sure how it performs.

      3. Implement an object within each namespace itself, then use an const var array for calling based on index, mainly because array[index] is faster than switch in Javascript.
        So for each namespace we add a reg methods = {"method1": method1, "method2": method2...}, then in the main script const var articulations = [A.methods, B.methods...], and you call by using articulations[index]"method1".
        However this doesn't work all the time lol. It compiles, but calling methods this way doesn't trigger Console.print() in them, and returns the wrong value when the method tries to retrieve values from a global array.

      So what should I do about this?

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @RCJacH
        last edited by

        @rcjach make a separate script to handle rrs and another one to handle articulations. You don't need a namespace per articulation, namespace aren't classes.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        R 1 Reply Last reply Reply Quote 0
        • R
          RCJacH @d.healey
          last edited by

          @d-healey okay thanks for the reminder.
          I refactored the script like you said and used a switch condition :face_with_tears_of_joy:

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          51

          Online

          1.7k

          Users

          11.7k

          Topics

          101.8k

          Posts