HISE Logo Forum
    • Categories
    • Register
    • Login

    Summing the elements of an array?

    Scheduled Pinned Locked Moved General Questions
    9 Posts 4 Posters 372 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.
    • CyberGenC
      CyberGen
      last edited by CyberGen

      Hi,

      I am trying to sum all the elements of an array in real time?
      We don't know how many elements there is going to be in the array at any given time. For example; an array containing the note numbers of all the keys that are being held down. The objective is to always know the sum value of the note numbers in the array.

      I'm using a simple but inefficient way, (see example below). It sorta works, but It's hardly an efficient way to do it. And it imposes limits.

      I believe there is an efficient way to script it with a loop, but I was not able to put it together.

      little help please?:folded_hands_medium-light_skin_tone:

      A = [0];
      sumA = A[0] + A[1] + A[2] + andSoForth to include all elements in the array.
      
      
      d.healeyD ulrikU 2 Replies Last reply Reply Quote 0
      • d.healeyD
        d.healey @CyberGen
        last edited by

        @RastaChess Use a loop. But why do you want to do this?

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

        CyberGenC A 2 Replies Last reply Reply Quote 0
        • ulrikU
          ulrik @CyberGen
          last edited by

          @RastaChess

          const array = [1, 23, 4, 65, 78];
          reg sumA = 0;
          
          for (n in array)
          	sumA += n;
          
          Console.print(sumA);
          
          //    or
          
          for (i = 0; i < array.length; i++)
                sumA += array[i];
          
          

          Hise Develop branch
          MacOs 15.3.1, Xcode 16.2
          http://musikboden.se

          CyberGenC 1 Reply Last reply Reply Quote 0
          • CyberGenC
            CyberGen @ulrik
            last edited by CyberGen

            @ulrik Thank you very much. I used your first example. It works great!

            Now I can delete, 40 sums from my script. 😊

            1 Reply Last reply Reply Quote 0
            • CyberGenC
              CyberGen @d.healey
              last edited by

              @d-healey I'm attempting to write a legato_glide script for a monosynth. I know, don't laugh... It's actually about 98% working. But it's all based on arrays and its very convoluted. I does the job pretty well though. I just have one or two wrinkles to iron out.

              I 'm summing the elements of an array to calculate the accumulated value of the intervals derived from the oldRoot to newRoot interval movements during a legato run. 🙂

              Your tutorials have helped me learn a lot, thank you for those.

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

                @RastaChess It sounds unnecessary, but I don't know without seeing the code.

                Here's a glide script I wrote - https://github.com/davidhealey/HiseUtilityScripts/blob/master/modules/PortGlide.js

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

                CyberGenC 1 Reply Last reply Reply Quote 0
                • CyberGenC
                  CyberGen @d.healey
                  last edited by

                  @d-healey I supposed it could be. It's an important part of this iteration of the script though.

                  I downloaded your script months ago for research. Thank you for making that available. However, I needed mine to work in a slightly different manner, I couldn't find a better alternative, so I decided to write my own.

                  I went with arrays, so far so good.

                  1 Reply Last reply Reply Quote 1
                  • A
                    aaronventure @d.healey
                    last edited by

                    @d-healey Moving average would be one thing. Is there a better way to do value smoothing in HISE?

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

                      @aaronventure Not something I've looked into, usually anytime I need smoothing I'm using a modulator that handles it.

                      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

                      43

                      Online

                      1.7k

                      Users

                      11.7k

                      Topics

                      101.9k

                      Posts