HISE Logo Forum
    • Categories
    • Register
    • Login

    onTimer swap between samplers

    Scheduled Pinned Locked Moved General Questions
    16 Posts 4 Posters 442 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.
    • gorangroovesG
      gorangrooves @ustk
      last edited by

      @ustk Thank you. Let me give that a shot :)

      Goran Rista
      https://gorangrooves.com

      Handy Drums and Handy Grooves
      https://library.gorangrooves.com

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

        I wouldn't use a timer for that. You get a precise timing with Engine.getUptime() that you can use in the onNoteOff callback to get the duration of the note:

        // This is only monophonic so for a real use case you might want to 
        // use another data storage type.
        reg start = 0.0;
        
        function onNoteOn()
        {
            start = Engine.getUptime();
        }
        
        function onNoteOff()
        {
            local durationMs = (Engine.getUptime() - start) * 1000.0;
            // do something with the duration
        }
        gorangroovesG 1 Reply Last reply Reply Quote 1
        • gorangroovesG
          gorangrooves @Christoph Hart
          last edited by

          @Christoph-Hart Thank you. That's interesting. I'll play around with it and see if I can make it work :)

          Goran Rista
          https://gorangrooves.com

          Handy Drums and Handy Grooves
          https://library.gorangrooves.com

          1 Reply Last reply Reply Quote 0
          • gorangroovesG
            gorangrooves
            last edited by

            @Christoph-Hart That works well and gives me precise values. Excellent. I'm off to the next steps :) Thank you!

            Goran Rista
            https://gorangrooves.com

            Handy Drums and Handy Grooves
            https://library.gorangrooves.com

            1 Reply Last reply Reply Quote 0
            • gorangroovesG
              gorangrooves
              last edited by

              @Christoph-Hart I was wondering if you could give me a little nudge here. It seems that I am missing something. Everything compiles ok, but the quick fade-out I am trying to achieve is not happening. It seems to be getting ignored. I get no errors. This is what I have:

              onInit
              reg start = 0.0;
              
              const var evtList = [];
              
              evtList.reserve(64000);
              
              function onNoteOn()
              {
              start = Engine.getUptime();
              	
              }
              
              function onNoteOff()
              {
                  local durationMs = (Engine.getUptime() - start) * 1000.0;
                  // do something with the duration
                  
                  if (durationMs < 96)
                  {
                      for(eventId in evtList)
                      {
                          Synth.addVolumeFade(eventId, 50, -100);
                      }
                  // Clear all notes
                      evtList.clear();
                  }  
                 Console.print("open surdo timer is "+durationMs);
              }
              

              Goran Rista
              https://gorangrooves.com

              Handy Drums and Handy Grooves
              https://library.gorangrooves.com

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

                @gorangrooves Is it possible for durationMs to ever be less than 1000 ? Console.print(durationMs);
                Also evtList isn't being populated. And why are you reserving 64000 elements, that seems like a lot?

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

                gorangroovesG 1 Reply Last reply Reply Quote 0
                • gorangroovesG
                  gorangrooves @d.healey
                  last edited by

                  @d-healey Yes, the duration is between 45-95ms when quickly striking the keys.
                  I guess I could lower the even list reserve since it is getting cleared all the time. I did it a while ago on a hi-hat script fearing that it wouldn't be enough, but now I realized that it gets cleared.

                  Why isn't the event list isn't being populated?

                  Goran Rista
                  https://gorangrooves.com

                  Handy Drums and Handy Grooves
                  https://library.gorangrooves.com

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

                    Because you didn't push anything in there :)

                    gorangroovesG 1 Reply Last reply Reply Quote 1
                    • gorangroovesG
                      gorangrooves @Christoph Hart
                      last edited by

                      @Christoph-Hart "That's what she said!" Ha! 😂 Let me see if I can stick that in there.

                      Goran Rista
                      https://gorangrooves.com

                      Handy Drums and Handy Grooves
                      https://library.gorangrooves.com

                      1 Reply Last reply Reply Quote 0
                      • gorangroovesG
                        gorangrooves
                        last edited by

                        Yes, I suck at coding, but I am good at recycling! I reused this nice little bit of your code @Christoph-Hart and made it work :)

                        onNoteOn
                                start = Engine.getUptime();
                        	Message.makeArtificial();
                                evtList.push(Message.getEventId());
                        

                        Thank you kindly, gentlemen!

                        Goran Rista
                        https://gorangrooves.com

                        Handy Drums and Handy Grooves
                        https://library.gorangrooves.com

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

                          @gorangrooves That's not a good way to do it. You're essentially just adding an endless number of event IDs into the array, the more notes played the less efficient your instrument will become. You should use a MIDI list instead.

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

                          gorangroovesG 1 Reply Last reply Reply Quote 0
                          • gorangroovesG
                            gorangrooves @d.healey
                            last edited by

                            @d-healey I have no idea how to go about that. Isn't that array getting emptied every time with

                            evtList.clear();
                            

                            ?

                            Goran Rista
                            https://gorangrooves.com

                            Handy Drums and Handy Grooves
                            https://library.gorangrooves.com

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

                              @gorangrooves Oh yeah so it is, so you're just wasting memory and CPU cycles with your evtList.reserve(64000);:p

                              You should use a midi list.

                              I have no idea how to go about that.

                              Now is a good time to learn. https://docs.hise.audio/scripting/scripting-api/midilist/index.html

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

                              gorangroovesG 1 Reply Last reply Reply Quote 0
                              • gorangroovesG
                                gorangrooves @d.healey
                                last edited by

                                @d-healey Thanks, Dave. I'll try to make some sense of it and see if I can make it work.

                                Goran Rista
                                https://gorangrooves.com

                                Handy Drums and Handy Grooves
                                https://library.gorangrooves.com

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

                                5

                                Online

                                1.7k

                                Users

                                11.8k

                                Topics

                                103.2k

                                Posts