HISE Logo Forum
    • Categories
    • Register
    • Login

    How do I find and remove objects in an array?

    Scheduled Pinned Locked Moved Scripting
    23 Posts 2 Posters 378 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.
    • d.healeyD
      d.healey
      last edited by

      For the original problem you might be able to make use of some of the fancier array functions like map, filter, find, some, etc. Or just use a good ol' fashioned loop to manually search the array for the object you're interested in.

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

      VirtualVirginV 1 Reply Last reply Reply Quote 0
      • VirtualVirginV
        VirtualVirgin @d.healey
        last edited by

        @d-healey said in How do I find and remove objects in an array?:

        For the original problem you might be able to make use of some of the fancier array functions like map, filter, find, some, etc. Or just use a good ol' fashioned loop to manually search the array for the object you're interested in.

        I am using filter and map in this script, but I am new to them so I may not be using them correctly.

        My trouble at the moment is detecting which notes are selected

        "selectedNotes" is an array that is getting populated properly to tell me which noteCells are selected,
        but then I run this inline function to check and this only works somethimes:

        // check for selected notes
        inline function isSelected(cell)
        {
        	local sRow = selectedNotes.some(obj => obj.row === cell.row);
        	local sCol = selectedNotes.some(obj => obj.col === cell.col);
        	if (sRow && sCol)
        		return true;
        	else
        		return false;
        };
        

        I am trying to use that like "array.contains()", but in this case for specific objects ("cell").
        The "cell" is an object with the coordinates i.e. {"row" : 60, "col" : 4}
        This works when I use click or shift click to select my notes, but not when a drag selection has been made. Not sure why as they both populate the selectedNotes array.

        You can listen to my orchestral mockups here:
        https://www.virtualvirgin.net/

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

          @VirtualVirgin For those functions (some, filter, etc.) the first parameter should be a function.

          8ecde93d-8e0d-4864-9392-6862b29b2606-image.png

          Edit: I just realised you're doing the javascript arrow function thing, we don't have that in HISE.

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

          VirtualVirginV 1 Reply Last reply Reply Quote 0
          • VirtualVirginV
            VirtualVirgin @d.healey
            last edited by

            @d-healey said in How do I find and remove objects in an array?:

            @VirtualVirgin For those functions (some, filter, etc.) the first parameter should be a function.

            8ecde93d-8e0d-4864-9392-6862b29b2606-image.png

            Edit: I just realised you're doing the javascript arrow function thing, we don't have that in HISE.

            No, the arrow function definitely works:

            Screenshot 2025-01-28 at 5.00.15 PM.png

            You can listen to my orchestral mockups here:
            https://www.virtualvirgin.net/

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

              @VirtualVirgin

              Oh that's good to know, thanks!

              Now I can do this kind of thing:

              Engine.showYesNoWindow("A title", "Some text", response => {
              	Console.print(response);
              });
              

              You could replace this

              	if (sRow && sCol)
              		return true;
              	else
              		return false;
              

              With return sRow && sCol

              But this doesn't solve your issue. Can you make a simple snippet that demonstrates the issue?

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

              VirtualVirginV 1 Reply Last reply Reply Quote 0
              • VirtualVirginV
                VirtualVirgin @d.healey
                last edited by VirtualVirgin

                @d-healey
                I found where the problem is taking place:

                            selectedNotes.push
                            (
                	            selectedNotes.filter(function (c) 
                	            {
                	                var cx = c.col * cellWidth;
                	                var cy = height - (c.row + 1) * cellHeight;
                	
                	                return 
                	                (
                	                    cx + cellWidth > x1 &&
                	                    cx < x2 &&
                	                    cy + cellHeight > y1 &&
                	                    cy < y2
                	                );
                	            })
                            );
                

                This selectedNotes.push is pushing an object inside an array to the selectedNotes array, whereas I only need it to push an object to the array.
                So the current result is looking like [[{"row":42, "col":4}]]
                but I need it to just look like [{"row":42, "col":4}]
                I am not sure how I modify that to just use a the object and not have it wrapped in that extra array.

                You can listen to my orchestral mockups here:
                https://www.virtualvirgin.net/

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

                  @VirtualVirgin Add [0] after the parenthesis e090f3a3-5ac8-4143-bc41-ba907ae5f7c9-image.png

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

                  VirtualVirginV 1 Reply Last reply Reply Quote 0
                  • VirtualVirginV
                    VirtualVirgin @d.healey
                    last edited by

                    @d-healey Almost...
                    that turns it into an object, but it only returns one selection to the list instead of all of the noteCells under the selection rectangle area.
                    Without the [0] it returns all of them, but inside an array.

                    You can listen to my orchestral mockups here:
                    https://www.virtualvirgin.net/

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

                      @VirtualVirgin In that case after it returns them, just grab the [0] element from that array.

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

                      VirtualVirginV 1 Reply Last reply Reply Quote 0
                      • VirtualVirginV
                        VirtualVirgin @d.healey
                        last edited by

                        @d-healey Whoops... is there a panic button of some sort for feedback loops? I got stuck in one.

                        You can listen to my orchestral mockups here:
                        https://www.virtualvirgin.net/

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

                          @VirtualVirgin What do you mean?

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

                          VirtualVirginV 1 Reply Last reply Reply Quote 0
                          • VirtualVirginV
                            VirtualVirgin @d.healey
                            last edited by

                            @d-healey I added a for loop after that function and it seems to be stuck in the loop

                            You can listen to my orchestral mockups here:
                            https://www.virtualvirgin.net/

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

                              @VirtualVirgin What does the loop do?

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

                              VirtualVirginV 1 Reply Last reply Reply Quote 0
                              • VirtualVirginV
                                VirtualVirgin @d.healey
                                last edited by

                                @d-healey

                                for (i = 0; i < noteCells; i++)
                                     selectedNotes.push(noteCells[i]);
                                

                                It's not resolving because I meant to use "i < noteCells.length",
                                so I am stuck with a spinning wheel and a sluggish HISE.

                                I'll just force quit it.
                                Just didn't know if there is a button similar to "all notes off" to stop the processing.

                                You can listen to my orchestral mockups here:
                                https://www.virtualvirgin.net/

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

                                  @VirtualVirgin Can you just hit compile again?

                                  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

                                  20

                                  Online

                                  1.7k

                                  Users

                                  11.9k

                                  Topics

                                  103.7k

                                  Posts