HISE Logo Forum
    • Categories
    • Register
    • Login

    How To Link Keyboard Keys to Buttons

    Scheduled Pinned Locked Moved Scripting
    5 Posts 2 Posters 65 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.
    • W
      weezycarter
      last edited by

      Hello I currently am trying to make a drum machine style plugin.

      I have 16 buttons I assigned as pads with a custom pad Image I imported.

      When I click the pads it triggers the samples in my sampler which is great. The pads light up and everything. However, when I hit the keys on the keyboard, the pads are not linked to the keys. I want the pads to light up as well and be triggered when I hit the keys on the keyboard not just when I click with a mouse, here is the code of my interface so far that I put in the editor to achieve this,

      Content.makeFrontInterface(900, 600);
      
      // ===== Config =====
      const var NUM_PADS  = 16;
      const var BASE_NOTE = 60; // Your C3 maps to MIDI 60
      
      // ===== State =====
      reg eventIds = [];
      const var btnTrigger = [];
      reg suppressBtnCallback = false;
      
      // ===== Helper =====
      inline function setPadLit(index, on)
      {
          if (index < 0 || index >= NUM_PADS || !btnTrigger[index]) return;
      
          suppressBtnCallback = true;                 // don't re-trigger UI callback
          btnTrigger[index].setValue(on ? 1 : 0);     // visually light/unlight
          suppressBtnCallback = false;
      }
      
      // ===== UI Callback =====
      inline function onBtnTriggerControl(component, value)
      {
          if (suppressBtnCallback) return;            // ignore programmatic changes
      
          local index = btnTrigger.indexOf(component);
          if (index == -1) return;
      
          if (value)
              eventIds[index] = Synth.playNote(BASE_NOTE + index, 64);
          else if (eventIds[index] != 0)
              Synth.noteOffByEventId(eventIds[index]);
      }
      
      // ===== Wire up the 16 buttons =====
      var i;
      for (i = 0; i < NUM_PADS; i++)
      {
          btnTrigger[i] = Content.getComponent("Button" + i); // Capital B
          if (btnTrigger[i])
              btnTrigger[i].setControlCallback(onBtnTriggerControl);
      }
      
      // ===== MIDI → UI mirroring =====
      function onNoteOn()
      {
          local idx = Message.getNoteNumber() - BASE_NOTE; // 60 -> index 0
          setPadLit(idx, true);
      }
      
      function onNoteOff()
      {
          local idx = Message.getNoteNumber() - BASE_NOTE;
          setPadLit(idx, false);
      }
      
      

      to my knowledge, and for the past 6 hours of failing at coding with chat gpt, the interface doesn't recognize midi? how can I go about linking the buttons to the keys?

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

        @weezycarter said in How To Link Keyboard Keys to Buttons:

        I have 16 buttons I assigned as pads with a custom pad Image I imported.

        Use a panel instead of buttons.

        @weezycarter said in How To Link Keyboard Keys to Buttons:

        reg eventIds = [];

        Should probably be a const, and perhaps a midi list instead of an array

        @weezycarter said in How To Link Keyboard Keys to Buttons:

        the past 6 hours of failing at coding with chat gpt,

        Better to spend 6 hours reading the docs

        @weezycarter said in How To Link Keyboard Keys to Buttons:

        function onNoteOn()
        {
        local idx = Message.getNoteNumber() - BASE_NOTE; // 60 -> index 0
        setPadLit(idx, true);
        }

        Is this inside your on init callback?

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

        W 1 Reply Last reply Reply Quote 0
        • W
          weezycarter @d.healey
          last edited by

          @d-healey This code is inside my interface on the oninit tab

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

            @weezycarter The HISE script editor provides a drop down to switch between the major callbacks.

            f051aac5-c458-44fc-85bf-b740c20c7736-image.png

            You need to put your onNoteOn and onNoteOff code within the correct callbacks, rather than in the onInit callback.

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

            W 1 Reply Last reply Reply Quote 0
            • W
              weezycarter @d.healey
              last edited by

              @d-healey THANK YOU! IT WORKS PERFECT!

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

              30

              Online

              2.0k

              Users

              12.8k

              Topics

              111.0k

              Posts