HISE Logo Forum
    • Categories
    • Register
    • Login

    Like a drumpad

    Scheduled Pinned Locked Moved Scripting
    18 Posts 5 Posters 2.8k 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.
    • chrisC
      chris
      last edited by chris

      Hi

      i would like to add to an image (pad) a simple sound from the sampler (note number 60)
      and to an other image the note 61.
      how can i do that?

      Thanks.

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by Christoph Hart

        This should get you going.

        
        // Store the event id of the generated note for the note on.
        // For a 4x4 Drumpad, use an array.
        reg b1EventId = -1;
        
        // Use a filmstrip to skin this button
        const var Button1 = Content.getComponent("Button1");
        
        // Make it momentary so that if you release the mouse, it will send a note off message
        Button1.set("isMomentary", true);
        
        // Make it non-persistent so that it won't get saved in presets and called on initialisation
        Button1.set("saveInPreset", false);
        
        function onNoteOn()
        {
            // This makes the button go down if you play a MIDI note
            if(Message.getNoteNumber() == 60)
                Button1.setValue(true);
        }
        function onNoteOff()
        {
            if(Message.getNoteNumber() == 60)
                Button1.setValue(false);
        }
        function onController()
        {
        	
        }
        function onTimer()
        {
        	
        }
        function onControl(number, value)
        {
            // Button press
            if(value)
        	// Play a C4 and store the event id for the note off
                b1EventId = Synth.playNote(60, 127);
            else
                // Use the event id to kill the note when you release the button
                Synth.noteOffByEventId(b1EventId);
        	
        }
        
        1 Reply Last reply Reply Quote 0
        • staiffS
          staiff
          last edited by

          "// For a 4x4 Drumpad, use an array."

          i think my problem is here.
          tried with 2 Pads. Midi works but click on button give the same note (and sound) for the twice buttons...

          Excuse me i'm French.

          1 Reply Last reply Reply Quote 0
          • staiffS
            staiff
            last edited by

            try to setup the array, but i can't. i lost all of my hairs, putting out one by one ...going crazy ...

            read all about array in this site (and elsewhere) but nothing works...

            Excuse me i'm French.

            1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart
              last edited by

              1. Have you changed the note number from 60 to the other note?
              2. Have you changed the onControl callback to an actual switch statement (I skipped it in this simple example, but if you don't do it with more than one control then the onControl callback gets fired multiple times.
              1 Reply Last reply Reply Quote 0
              • staiffS
                staiff
                last edited by

                • yes: changed the note number for the 2 pads (because my notes was 48 &52 for testing)
                • no i just duplicate the OnControl Values.
                  the switch statement like in the multipages ? (http://forum.hise.audio/topic/499/multiple-page/17)

                Excuse me i'm French.

                1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart
                  last edited by

                  Yes, the onControl callback is fired for every control and you have to branch it to implement each specific behaviour either using a switch statement or a large if...else structure (which is far more inefficient though).

                  1 Reply Last reply Reply Quote 0
                  • staiffS
                    staiff
                    last edited by staiff

                    ok, in OnControl i did:

                    	{
                    		case Button1:
                    		{
                    // Button press
                        if(value)
                    	// Play a C4 and store the event id for the note off
                            b1EventId = Synth.playNote(48, 127);
                        else
                            // Use the event id to kill the note when you release the button
                            Synth.noteOffByEventId(b1EventId);
                            break;
                    		}
                    		case Button2:
                    		{
                    // Button press
                        if(value)
                    	// Play a C4 and store the event id for the note off
                            b1EventId = Synth.playNote(52, 127);
                        else
                            // Use the event id to kill the note when you release the button
                            Synth.noteOffByEventId(b1EventId);
                            break;
                    		}
                    	}
                    

                    it works !

                    but i kept just your: reg b1EventId = -1; in OnInit (without array)

                    you wrote that we must create array ... (?)

                    Excuse me i'm French.

                    1 Reply Last reply Reply Quote 0
                    • staiffS
                      staiff
                      last edited by staiff

                      ok,
                      for Chris (and other users) i did a simple project with 3 buttons. Notes are 48,50 and 52 (C1, D1 and E1)
                      you must change it in the OnNoteOn, OnnoteOff and OnControl to your desired note ;)

                      HiseSnippet 1638.3oc4Y0raabCDdks2zJknflhbnG5AhfBTY.GE8icRPMBhrjsSERThpkqQukPuKWIVsKo.IW4nDDf7H0GgdrON4Mnc3xUZWIqJa4jZm1t9h3PNy7MejbFR51BtCQJ4BqLW+vQCHVYtgcmQLUuF8vTlUycsxj0dWQXvw7WaUez.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w7t7SSWUt5oqsJ8uG5p5mAzUkOuoq2o2ICmCd5CZesy2AscLUpSMPNqITR6ECHwsSNJd44bTbq3R8I+B5EJopnD8A0WcR4e.QpnCpey3CpalMsnt5akEmJw50StE06aWazjF0H0Ng5p5ouzy6g18Hzt8T5VeqUjmWBmTIkSP+ZJmf9D5jpobRsgobh0hcxouWCb6JtanOVM8UtzWYMtCH+8T2sQe+EljpFk9JsKw8vJM26gM2I+yIbukcacMj4i2UlCdgUN+Si23a0l2dOOOhiJArqYu+ubQuB6ECJ21.ku1tiB1WGPYc6fCF.EviexhwstTexB3Pq9braG5aRMreuV8PftDSK82pE4pcfynylxWw.+.x.BVAy9I57p90N3fmH3gClUqO73n0JGJvNvUz5ltiWvH.sqRGiMDbozCBmHaIS2U6PQWMWkH4.HCsPNsL3zVvTOiAY00aBy.hLntEdPzS0L66q7Emu7pf5swfUSMx5ztoLsVxzahSMzIg0gXv1odMm47VHW6J3oZ9zmh3iOi1pmO3dFulT1wXrCUOUsGaHrM.jXRisKwCG5qlHMMHawY7A83Lpyzq4TBZ2tDQZnO23YGkBVxmH410NvbZgDQeWsmQYDrXpsRKGUT97SEKZ55arMvEoSif9uQgnU+eegnEQc2LtLDB7tP8Y977MripGfzE5tpf5A7PET.qEFR..GFzFpzzApt5PRWuYEcMLS6R51Z.0gvbKM948i6r7jhSPmkG2okyXSAwV7u2Eqv.lHLckinyW4Ck87SujVB0v0PBptYIilTCzUjVSybfrN3gDSFFCd9aKT2h5zlCjIrORmzwd6KmfN.6H3uzw7dE5P+Kij.HfE8+WIqcKcaTYqn6FZlrBf5duzwQuq5tvz070nxRqQ0kViMWZM1Zo039KsFOXo03gKPC8gL1ITwCL4Xsr9K.wd6JR```

                      Excuse me i'm French.

                      lixiaolongL 1 Reply Last reply Reply Quote 0
                      • Christoph HartC
                        Christoph Hart
                        last edited by

                        Thanks staiff. I've updated your example to include a few fixes and best practices:

                        • used the array method for storing the event IDs (your script will behave weird when pressing more than one note / button at once).
                        • using the switch statement in the note callbacks for improved efficiency. Try to use switch as much as possible especially in the high performance callbacks.
                        • removed some comments that were duplicated for no reason.
                        HiseSnippet 1750.3oc4Y81aSbCF+RaOTSfhFS7h8BdgEZSKUTJ4Os.ipIRaZKJZDHpoTMIDBbuyWhWuXGY6zRXBI9RruG6iv9Hw2fsGe9tDeooo8.Ff1NIPwO1+7yO+6w2ie70VBtGQJ4BmbWd+g8IN4tha6gLU25cwTlSiscxk2cawfdGxesyVC6ikRhuStby+Hc24xufSzy6e3V3PLyiL1jiyAbpG4wzdT0Xqup1uPCC2E6S1m1yZzqUqgGmUmGxG.TYd2RN8wdGg6PdBVOr4bcNlRNQ5jqja0JqJNp7guYyUm34Vg0Wc0ffz1c7FHDDl5..tSN2b+M7jycGephKZqvJBLmKrE2eX6t7SXFWe.UROLjnaT1oMvIi4c4g95Eu1pS8tzP+VIpmzAl6Vi0x4MZ40caR8oirOVS+lnNPiQXKs4laVzq74SuRSid4rn2BF5cM21dBZe03dzb6xtMXJhH.CQSaZYFqyb+wht04vHXpU6gOhrq.ZLBQw6VpzJn0KUZ4MVpvREtycPsgUBAo5RPjiALHpOhGD0tCgQDvRzGw3JBJfKhLG0fyVcoBvNBoBcLVXf1vWh9Yzyuc4UPl+8hDe7LIAgQAzvdREPRjhijGQYvzQknCGnTbl8rsUjkxvjkrP5PT0485yYPih2Lt+apWCvr2DVkHpB0i2C5FKFhjbXpwvZI.MjO.IHgDrzrH6wGHIqnG9IvFcjjv7ApYVSAAndfNC6pWpPrOVUR.GRkMSl6atBRIFPlv0LN618IBIUpo6X+Cdgy9QEHkfQ7wfTBq59BBLqRDFbsGNLDrxYPGTEEGRkXEUKGoHfFaCVqHf.CBvgRhIB9gquUNG8sRj9F+6YoCoFxYyzI8e0yw+Us7e0y2+Umk+CFv7zxJHzOAB0OkUb4B+9REPvCHe6qkI86JxnsHFAC0gi7g2oS1D0ODODD4lM1tQz1ECZ4ITkW2hMMaazqC87+DHeLQTb4kMCJ1S5GO89v0t+C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iKU.AdWn9JONeE2ny.P5hQ9RQ083CTPQFMwPB.ntdWnZf1PEPdD6ZBlSWmgocojB0aSX9kR9J+wcVNo.BcmkS5zwKYpf0V7uit8Vt4IL8oHQ0.GBklDZukVB0YooDbRGbSAcPsm9zoEzJGXqMb4ASFFCeNyhoZR8ZwAwDdORmzwciOOK5dXOA+kdlOXjdouXjEfArn+LK4capaiJ6DcudSvpGbt2K87zuUcaHbMcDUxLhpYFwZYFw5YFwcyLh6kYD2eFHzEYr4.EumIGqiy+.7xebm.
                        
                        lixiaolongL 1 Reply Last reply Reply Quote 0
                        • chrisC
                          chris
                          last edited by

                          Thanks Christoph, Staiff working well now!

                          1 Reply Last reply Reply Quote 0
                          • lixiaolongL
                            lixiaolong @staiff
                            last edited by

                            @staiff Hello, the garbled code shown here, can you please write a regular code? Because I also encountered the same problem, I refer to your code, button 1 and button 2 can trigger different sound samples, but button 3, button 4, button 5, trigger the same sound sample, how can Each button triggers a different sound sample?
                            Also, why do I add my own image to the button to display only half of the image? How can I display the full image?

                            1 Reply Last reply Reply Quote 0
                            • lixiaolongL
                              lixiaolong @Christoph Hart
                              last edited by

                              @Christoph-Hart Hello, the garbled code shown here, can you please write a regular code? Because I also encountered the same problem, I refer to your code, button 1 and button 2 can trigger different sound samples, but button 3, button 4, button 5, trigger the same sound sample, how can Each button triggers a different sound sample?
                              Also, why do I add my own image to the button to display only half of the image? How can I display the full image?

                              DalartD 1 Reply Last reply Reply Quote 0
                              • DalartD
                                Dalart @lixiaolong
                                last edited by

                                @lixiaolong Everything seems to work fine for me using the hise snippet provided above.

                                lixiaolongL 1 Reply Last reply Reply Quote 1
                                • lixiaolongL
                                  lixiaolong @Dalart
                                  last edited by

                                  @Dalart Hello, thank you very much! Are you willing to share the code with me for reference? Only button 1 and button 2 can trigger different sound samples, and the sound samples of button 1 or button 2 are triggered from button 3.

                                  DalartD 1 Reply Last reply Reply Quote 0
                                  • DalartD
                                    Dalart @lixiaolong
                                    last edited by

                                    @lixiaolong Here ya go, I used @Christoph-Hart 's HISE snippet above and just added a few samples to it so you can see it working correctly. Hope this helps, just paying it forward for the help I've gotten from this forum :)

                                    Download to zipped project:
                                    https://we.tl/t-ETkKHotFBJ

                                    lixiaolongL 2 Replies Last reply Reply Quote 0
                                    • lixiaolongL
                                      lixiaolong @Dalart
                                      last edited by

                                      @Dalart Thank you so much! You are amazing!😃 :thumbs_up: :thumbs_up:

                                      1 Reply Last reply Reply Quote 0
                                      • lixiaolongL
                                        lixiaolong @Dalart
                                        last edited by

                                        This post is deleted!
                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post

                                        52

                                        Online

                                        1.7k

                                        Users

                                        11.7k

                                        Topics

                                        101.8k

                                        Posts