HISE Logo Forum
    • Categories
    • Register
    • Login

    Coloured Keys not quite behaving...

    Scheduled Pinned Locked Moved Newbie League
    8 Posts 3 Posters 56 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.
    • J
      JamesC
      last edited by

      Evening everyone hope you are all well. So code incoming, I've got a dropdown box to change loaded sample maps - they've got quite a varying range depending on the selected map and was colour coding the keys for the user so its clear what you've got to work with.

      The issue is that it seems a bit inaccurate and to be honest I'm not sure why some are very close 1 or 2 notes missed low and high others are missing 16-20 notes left uncoloured completely, as always I suspect there is something I've missed!

      /// Dropdown Sample Maps
      Content.getComponent("cmbsamplemap").setControlCallback(oncmbsamplemapControl);
      
      const var sampleMaps = Sampler.getSampleMapList();
      
      const var cmbsamplemap = Content.getComponent("cmbsamplemap");
      
      
      cmbsamplemap.set("items", sampleMaps.join("\n"));
      
      inline function oncmbsamplemapControl(component, value)
      {
      	Sampler1.asSampler().loadSampleMap(sampleMaps[value-1]);
      	
      for (i = 0; i < 127; i++)
      
       if (Sampler1.asSampler().isNoteNumberMapped(i))
          Engine.setKeyColour(i, Colours.withAlpha(Colours.green, 0.3));
          else
         Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0));
      };```
      d.healeyD LindonL 2 Replies Last reply Reply Quote 0
      • d.healeyD
        d.healey @JamesC
        last edited by d.healey

        @JamesC The sample map loading is asynchronous so your colour setting code is running before the map is fully loaded. You need to use a loading callback to handle this.

        Free HISE Bootcamp Full Course for beginners.
        YouTube Channel - Public HISE tutorials
        My Patreon - HISE tutorials

        1 Reply Last reply Reply Quote 0
        • LindonL
          Lindon @JamesC
          last edited by Lindon

          @JamesC said in Coloured Keys not quite behaving...:

          if (Sampler1.asSampler().isNoteNumberMapped(i))
          Engine.setKeyColour(i, Colours.withAlpha(Colours.green, 0.3));
          else
          Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0));
          };

          Im not sure this will work without the braces, try this:

              if(Sampler1.asSampler().isNoteNumberMapped(i))
              {
                  Engine.setKeyColour(i, Colours.withAlpha(Colours.green, 0.3));
              }else{
                 Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0));
              };
          };
          

          if nothing else it makes it more readable...but whilst we are here....

              if(Sampler1.asSampler().isNoteNumberMapped(i))
          

          so you are looping round all possible notes (0 ->127) and every time you are asking HISE to load the Sampler1.asSampler()

          Its more efficient and better to do this:

          /// Dropdown Sample Maps
          Content.getComponent("cmbsamplemap").setControlCallback(oncmbsamplemapControl);
          
          const var sampleMaps = Sampler.getSampleMapList(); //<-- shouldnt this be Sampler1 ??
          
          const var cmbsamplemap = Content.getComponent("cmbsamplemap");
          const var Sampler1AsASampler = Sampler1.asSampler(); //<--assuming you've got a reference to Sampler1 earlier...
          
          cmbsamplemap.set("items", sampleMaps.join("\n"));
          
          inline function oncmbsamplemapControl(component, value)
          {
          	Sampler1AsASampler.loadSampleMap(sampleMaps[value-1]);
          
          //so put all this code in the OnLoad callback	
          for (i = 0; i < 127; i++)
          {
              if (Sampler1AsASampler.isNoteNumberMapped(i))
              {
                  Engine.setKeyColour(i, Colours.withAlpha(Colours.green, 0.3));
              }else{
                 Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0));
              }; 
          };
          // to here...
          };
          

          HISE Development for hire.
          www.channelrobot.com

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

            You will need this:

            https://docs.hise.dev/scripting/scripting-api/scriptpanel/index.html#setloadingcallback

            HISE Development for hire.
            www.channelrobot.com

            J 1 Reply Last reply Reply Quote 0
            • J
              JamesC @Lindon
              last edited by

              @Lindon thanks both for the help, I'm not sure I'm understanding the example given in the documentation

              What element is this case are we setting the loading call back for in the exmaple I see its the panel in this case is it the sampler? (I'm also fairly sure my layout of brackets etc is completely out on this also!:

              //so put all this code in the OnLoad callback
              
              sampler.setLoadingCallback(function(isPreloading)
              {	
              for (i = 0; i < 127; i++)
              {
                  if (Sampler1AsASampler.isNoteNumberMapped(i))
                  {
                      Engine.setKeyColour(i, Colours.withAlpha(Colours.green, 0.3));
                  }else{
                     Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0));
                  }; 
              };
              // to here...
              
              d.healeyD 2 Replies Last reply Reply Quote 0
              • d.healeyD
                d.healey @JamesC
                last edited by

                @JamesC You need to use a panel, the callback is triggered by the sample map being loaded. From within the callback you can call your key colouring function.

                Free HISE Bootcamp Full Course for beginners.
                YouTube Channel - Public HISE tutorials
                My Patreon - HISE tutorials

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

                  @JamesC Apparently I made a video about it

                  https://www.youtube.com/watch?v=H1OCC-EDl14

                  Free HISE Bootcamp Full Course for beginners.
                  YouTube Channel - Public HISE tutorials
                  My Patreon - HISE tutorials

                  1 Reply Last reply Reply Quote 0
                  • J
                    JamesC @d.healey
                    last edited by

                    @d-healey awesome will stick it on my watch list and regroup tomorrow!

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

                    12

                    Online

                    2.0k

                    Users

                    12.8k

                    Topics

                    111.4k

                    Posts