HISE Logo Forum
    • Categories
    • Register
    • Login

    Checking elements of an array in the "if" operator

    Scheduled Pinned Locked Moved General Questions
    19 Posts 2 Posters 602 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 @bendurso
      last edited by

      @bendurso

      Well you're just checking if (value) which is the same as saying if the value is 1 do whatever is in the curly braces. But I don't think this is what you want and I don't even see where value is coming from.

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

      bendursoB 1 Reply Last reply Reply Quote 0
      • bendursoB
        bendurso @d.healey
        last edited by

        @d-healey Oh, yes, my code was weird.

        Something like this maybe should check if PadSampleMaps contains currentSampleMapId1 or 2? It doesn't work :(

        inline function updateKeyboardPanelVisibility()
        {
        	if (PadSampleMaps.contains(currentSampleMapId1) || PadSampleMaps.contains(currentSampleMap2))
        	{	
        		pnlKeyboard1.showControl(true);
        	}
        	else
        	{
        		pnlKeyboard1.showControl(false);
        	}
        
        }
        
        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @bendurso
          last edited by

          @bendurso What is the exact value of currentSampleMapId1?

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

          bendursoB 1 Reply Last reply Reply Quote 0
          • bendursoB
            bendurso @d.healey
            last edited by

            @d-healey Is the ID of the SampleMap. The console print is showing it correctly.

            const var currentSampleMapId1 = Sampler1.getCurrentSampleMapId();
            
            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @bendurso
              last edited by

              @bendurso Yeah but is it "Pad 1" or "Pad 1.xml" or something different?

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

              bendursoB 1 Reply Last reply Reply Quote 0
              • bendursoB
                bendurso @d.healey
                last edited by

                @d-healey Oh, it's just "Pad 1".

                I just noticed that when I hit "compile" the panel shows or hides as it should. But it doesn't happen when I change the samplemap. I think placing "updateKeyboardPanelVisibility()" inside the samplemap selectors doesn't work because they can't check each other's state.

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

                  @bendurso Yeah you'll need to trigger the function from a callback or a broadcaster otherwise it won't know when to change.

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

                  bendursoB 2 Replies Last reply Reply Quote 1
                  • bendursoB
                    bendurso @d.healey
                    last edited by

                    @d-healey Oh thanks, that's new for me. I'll investigate how to implement it :)

                    1 Reply Last reply Reply Quote 0
                    • bendursoB
                      bendurso @d.healey
                      last edited by

                      @d-healey I have simplified the code to only check the SampleMap of one sampler. I also changed the constant variables to local variables within the inline function updateKeyboardPanelVisibility(). After making these changes, I called the function "updateKeyboardPanelVisibility()" on the sample selector, and it started working. However, I noticed that the panels only update after changing the sample map twice. I mean, when one panel is active and the other has to be activated, the change only takes effect after two switches. Any insights into why this might be happening?

                      const var pnlKeyboard1 = Content.getComponent("pnlKeyboard1");
                      const var pnlKeyboard2 = Content.getComponent("pnlKeyboard2");
                      
                      inline function updateKeyboardPanelVisibility()
                      {
                      	local currentSampleMapId1 = Sampler1.getCurrentSampleMapId();
                      	local PadSampleMaps = ["Pad 1", "Pad 2", "Pad 3", "Pad 4"];
                      
                      	if (PadSampleMaps.contains(currentSampleMapId1))
                      	{	
                      		pnlKeyboard1.showControl(true);
                      		pnlKeyboard2.showControl(false);
                      	}	
                      	else
                      	{
                      		pnlKeyboard1.showControl(false);
                      		pnlKeyboard2.showControl(true);
                      	}
                      	
                      	
                      }
                      
                      inline function onpnlSampleSelector1Control(component, value)
                      {
                      
                      	if (value)
                          {
                              local array = component.get("popupMenuItems").split("\n");
                              local t = array[value - 1];
                              local t2 = t.substring(t.indexOf(":") + 2, t.length);
                              lblSampler1.set("text", t2);   
                              Sampler1.loadSampleMap(t2);
                              updateKeyboardPanelVisibility();
                             	               		                             
                          }
                          
                      };
                      
                      d.healeyD 1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @bendurso
                        last edited by

                        @bendurso I'm not sure it's a good idea to call your variable array as that is a type, but perhaps it won't hurt...

                        When you load a sample map it doesn't happen instantaneously, but your call to updateKeyboardPanelVisibility() does happen straight after your loadSampleMap call. But at that point the sample map ID will still be for the old one, because the new one hasn't finished loading. You need to handle this in the preload callback.

                        I showed how to do this last month in my auto colouring the keyboard video on Patreon.

                        By the way, why are you hiding/showing keyboards?

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

                        bendursoB 1 Reply Last reply Reply Quote 1
                        • bendursoB
                          bendurso @d.healey
                          last edited by

                          @d-healey The auto colorouing keyboard should be a perfect solution hehe. I placed two colored panels above the real (floating tile) keyboard to show the range of each selected sample map in a different color. (I have two samplers, so I'll duplicate this function)

                          Ohh, I just tried and it worked! Thank you so much!

                          pnlSampleSelector1.setLoadingCallback(function(isPreloading)
                          {
                          	updateKeyboardPanelVisibility();
                          
                          });
                          
                          d.healeyD 1 Reply Last reply Reply Quote 0
                          • d.healeyD
                            d.healey @bendurso
                            last edited by

                            @bendurso

                            to show the range of each selected sample map in a different color.

                            Why not just colour the keys?

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

                            bendursoB 1 Reply Last reply Reply Quote 0
                            • bendursoB
                              bendurso @d.healey
                              last edited by

                              @d-healey Is it possible to color each sampler with a different color? Like this:
                              Screen Shot 2023-08-02 at 15.03.37.png

                              I should have started there hehe.

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

                                @bendurso Go watch my video, that's exactly what I show how to do :p

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

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

                                25

                                Online

                                1.8k

                                Users

                                12.0k

                                Topics

                                104.5k

                                Posts