HISE Logo Forum
    • Categories
    • Register
    • Login

    User defined Component properties via JSON

    Scheduled Pinned Locked Moved Scripting
    9 Posts 4 Posters 213 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.
    • G
      Giuseppe
      last edited by

      Hello,
      I have added a user defined Component property (an integer to be used as an index for a series of toggling buttons) via the Components JSON.
      I was wondering if this can be considered good practice? I find it very handy as said property is predefined for a series of buttons in an array, so once one is clicked the integer returns which one was.

      Regards,
      Giuseppe

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

        @Giuseppe I'm not sure what you mean, please post a snippet demonstrating it.

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

        ustkU G 2 Replies Last reply Reply Quote 0
        • ustkU
          ustk @d.healey
          last edited by ustk

          @d-healey, I think @Giuseppe is adding properties manually to component's JSON (probably by pressing J key)
          This works nicely when you read it from script, and seems secure enough. Though I haven't tested with exported plugin, which should be the first thing to check...

          Can't help pressing F5 in the forum...

          1 Reply Last reply Reply Quote 0
          • G
            Giuseppe @d.healey
            last edited by

            @d-healey Yes, as @ustk said I'm manually opening the JSON of the component and just adding another line with an integer index, which ranges from 0 to number of components for each component. It keeps track of which component triggered a callback that is associated to all of said components.

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

              @Giuseppe That's not considered good practice. You could store all your components in an array and use the array index, there are other methods of organising your controls also depending on the specifics of the project.

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

              G 1 Reply Last reply Reply Quote 0
              • G
                Giuseppe @d.healey
                last edited by

                @d-healey Thanks David. I was watching your Scripting Best Practices videos about toggling buttons, and I see you use the "continue" command to keep track of which button triggered the callback. As far as I understand it, that gives the string name of the triggering component, but how could I store an index associated to said component? Maybe using an object?

                LindonL d.healeyD 2 Replies Last reply Reply Quote 0
                • LindonL
                  Lindon @Giuseppe
                  last edited by Lindon

                  @Giuseppe create an array of all the components of a given "type" (your choice), now us array.indexOf(component) to tell you which component is being activated...

                  e.g. lets say we have 5 buttons...called Button1 to Button5:

                  const myComponentArray = [];
                  const NUM_COMPONENTS = 5;
                  
                  for(i=0,i<NUM_COMPONENTS ; i++)
                  {
                       myComponentArray[i] = Content.getComponent("Button" + (i+1));
                      myComponentArray[i].setControlCallback("mycallback");
                  }
                  
                  
                  inline function mycallback(component, value)
                  {
                  	local pos = myComponentArray.indexOf(component);
                         Console.print("Pressed button:" + (pos+1);
                  };
                  
                  
                  
                  
                  

                  HISE Development for hire.
                  www.channelrobot.com

                  G 1 Reply Last reply Reply Quote 0
                  • G
                    Giuseppe @Lindon
                    last edited by

                    @Lindon right, thanks Lindon. I missed the indexOf command, much appreciated !

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

                      @Giuseppe said in User defined Component properties via JSON:

                      "continue" command to keep track of which button triggered the callback

                      continue is used in loops to skip the current cycle.

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

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

                      21

                      Online

                      1.7k

                      Users

                      11.8k

                      Topics

                      102.8k

                      Posts