HISE Logo Forum
    • Categories
    • Register
    • Login

    load Samplemap and play note

    Scheduled Pinned Locked Moved General Questions
    25 Posts 2 Posters 1.6k 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

      I've made a little demo project for you. It should explain things a little more clearly than just a snippet.

      The file is actually a .zip but the forum doesn't allow such files. So when you download it just change the extension to .zip and it should open.

      temp.mp3

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

      JayJ 2 Replies Last reply Reply Quote 1
      • JayJ
        Jay @d.healey
        last edited by

        @d-healey Thank you brother I'll read through it and try to learn as much as I can, I appreciate it

        Joansi Villalona

        1 Reply Last reply Reply Quote 1
        • JayJ
          Jay @d.healey
          last edited by

          @d-healey is Good, but is there a way of no having to press the Play Button?, but when selecting any of the option in this case the notes it start automatically?

          Joansi Villalona

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

            @Jay said in load Samplemap and play note:

            no having to press the Play Button?, but when selecting any of the opti

            Yeah of course, just put it in the combo box callback instead.

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

            JayJ 1 Reply Last reply Reply Quote 0
            • JayJ
              Jay @d.healey
              last edited by

              @d-healey said in load Samplemap and play note:

              Yeah of course, just put it in the combo box callback instead.

              Don't know what to change

              Joansi Villalona

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

                @Jay Ok, I'll walk you through it because if I just change it it won't explain why.

                So this is the whole script (except for the one line in the on note callback)

                Content.makeFrontInterface(600, 500);
                
                //Combo box
                const var cmbSound = Content.getComponent("cmbSound");
                
                //Play button
                inline function onbtnPlayControl(component, value)
                {   
                	var sound = cmbSound.getValue()-1; //Get combobox value (-1 to start at 0)
                	
                	value ? Synth.playNote(60+sound, 64) : Engine.allNotesOff();
                };
                
                Content.getComponent("btnPlay").setControlCallback(onbtnPlayControl);
                

                The first line Content.makeFrontInterface(600, 500); Just sets the width and height of the main interface. Nothing special here, HISE adds this for us automatically.

                In this line const var cmbSound = Content.getComponent("cmbSound"); We are getting a reference to the combo box that is on the interface. The combo box has an id of cmbSound and we are saving it in a variable with the same name.

                Next we have the callback function for the play button. This is like when you use a switch statement in the generic on control callback. But this callback is only triggered when the play button btnPlay is pressed.

                var sound = cmbSound.getValue()-1; //Get combobox value (-1 to start at 0) This line gets the current value of the combo box. We use the reference we saved earlier - cmbSound. The first item in a combo box always has an index of 1 but we want it to be 0 so we subtract 1.

                value ? Synth.playNote(60+sound, 64) : Engine.allNotesOff(); This uses the ternary operator ?. It's a way of making a 1 line if/else statement. We can understand it better if we write it out in full.

                if (value)
                {
                    Synth.playNote(60+sound, 64);
                }
                else
                {
                    Engine.allNotesOff();
                }
                

                Let's go through this.

                So firstly we only play a note when the value is 1 - if (value)

                Then we play the note Synth.playNote(60+sound, 64); We use 60 as the note number because the first sample is mapped to middle C which is MIDI note 60. We add to this the current value of cmbSound. We saved this value in the sound variable earlier. So if the first sound is selected then the note that triggers will be 60, if the second sound is selected then the triggered note will be 61, etc.

                In the else clause (it the button value is 0) we just turn off all playing notes. That way we don't have to keep track of individual note IDs. There will only ever be one note playing at a time.


                Ok so to get this to play when selecting from the comboBox instead of by pressing the play button we add a callback function for the combo box. The callback function is auto-generated by HISE if we right click on the control in the widget list and select create custom callback definition then paste into the script editor.

                Now our script will look like this:

                Content.makeFrontInterface(600, 500);
                
                //Play button
                inline function onbtnPlayControl(component, value)
                {   
                	Engine.allNotesOff();	
                };
                
                Content.getComponent("btnPlay").setControlCallback(onbtnPlayControl);
                
                
                inline function oncmbSoundControl(component, value)
                {
                	Synth.playNote(60+value-1, 64);
                };
                
                Content.getComponent("cmbSound").setControlCallback(oncmbSoundControl);
                

                The play button is now a stop button - you'll probably want to rename it and set it to be momentary.

                The note is played in the cmbSound callback. We no longer need to store this control or its value in a separate variable. We can just use the value directly in the Synth.playNote() function. You'll want to disable saveInPreset for the combo box otherwise it will always play when you hit compile.

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

                JayJ 1 Reply Last reply Reply Quote 0
                • JayJ
                  Jay @d.healey
                  last edited by

                  @d-healey got it up to here, but every time I select any of the other notes it play on top of the one already playing, how do I mute the last note playing and start playing the new select it one?

                  Joansi Villalona

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

                    @Jay Oh yeah I didn't think of that. Well you know how to turn the note off, right ;) so just do that before you play a note.

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

                    JayJ 1 Reply Last reply Reply Quote 0
                    • JayJ
                      Jay @d.healey
                      last edited by

                      @d-healey yeah cool, but I would like to be able to do it automatically, I will be trying to do it myself to see if I can pull it off, wish me luck.

                      Thanks man

                      Joansi Villalona

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

                        Just use the same code from the stop button - Engine.allNotesOff();

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

                        JayJ 2 Replies Last reply Reply Quote 1
                        • JayJ
                          Jay @d.healey
                          last edited by

                          @d-healey I'll try when I get home from work

                          Joansi Villalona

                          1 Reply Last reply Reply Quote 0
                          • JayJ
                            Jay @d.healey
                            last edited by

                            @d-healey I couldn't get it to work, maybe I'm going the old route of doing a samplemap per audio file.

                            Also can't get the text to update when calling the preset using this:

                            Content.getComponent("presetLbl").set("text", Engine.getCurrentUserPresetName());
                            

                            Joansi Villalona

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

                              inline function oncmbSoundControl(component, value)
                              {
                                      Engine.allNotesOff();	
                              	Synth.playNote(60+value-1, 64);
                              };
                              

                              Preset browsers are another issue

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

                              JayJ 1 Reply Last reply Reply Quote 0
                              • JayJ
                                Jay @d.healey
                                last edited by

                                @d-healey when I do that, it mutes everything, also some I notice is that after selecting from the combo box, it keeps playing the next audio files in sequence

                                Joansi Villalona

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

                                  @Jay

                                  when I do that, it mutes everything,

                                  What do you mean everything? In the project I sent there should only be one sound at a time.

                                  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

                                  55

                                  Online

                                  1.7k

                                  Users

                                  11.7k

                                  Topics

                                  101.9k

                                  Posts