Forum

    • Register
    • Login
    • Search
    • Categories

    onTimer swap between samplers

    General Questions
    4
    16
    106
    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.
    • gorangrooves
      gorangrooves last edited by

      Hey guys,
      I am trying to switch between two notes that trigger simultaneously, depending on how quickly the note-off happens. Here is my logic.

      Sampler A (plays regular notes as long as the note is held, simple envelope release time set up 1166ms)
      On note on: start timer
      On note off: stop timer
      If timer is less than 50ms, set simple envelope release to 100ms

      Sampler B (plays one-shots, has a fade in)
      On note on: start timer and set the volume output to -100
      On note off: stop timer
      If timer is less than 50ms, set the volume output to 100 (full)

      So, what this should result in (in theory) is that if you quickly press the note on/off, the Sampler A will play the sample's attack portion and quickly fade out, while the Sampler B will crossfade and play the decay of the muted note.
      If you press the key and hold the note, then only Sampler A will sound and the sampler B will be ignored.

      For starters, I am just trying to get and print the timer value when pressing the key, but I am not having much success. Here is what I have in my Midi Processor:

      onInit
      var t = Synth.getTimerInterval();
      
      onNoteOn
      function onNoteOn()
      {	
      	startTimer;
      }
      
      onNoteOff
      function onNoteOff()
      {
          stopTimer;
          Console.print("open surdo timer is "+t);
      }
      

      No matter how I trigger the note, the console print always says 0.

      Any help is much appreciated. Thank you!

      Goran Rista
      https://gorangrooves.com

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

      ustk 1 Reply Last reply Reply Quote 0
      • ustk
        ustk @gorangrooves last edited by ustk

        @gorangrooves
        You have to create a timer first with Engine.createTimerObject()
        Then the calls are myTimer.startTimer(int ms) & myTimer.stopTimer()

        I can't help pressing F5 in the forum...

        gorangrooves 1 Reply Last reply Reply Quote 0
        • gorangrooves
          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 Hart
            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
            }
            gorangrooves 1 Reply Last reply Reply Quote 1
            • gorangrooves
              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
              • gorangrooves
                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
                • gorangrooves
                  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.healey 1 Reply Last reply Reply Quote 0
                  • d.healey
                    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

                    gorangrooves 1 Reply Last reply Reply Quote 0
                    • gorangrooves
                      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 Hart
                        Christoph Hart last edited by

                        Because you didn't push anything in there 🙂

                        gorangrooves 1 Reply Last reply Reply Quote 1
                        • gorangrooves
                          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
                          • gorangrooves
                            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.healey 1 Reply Last reply Reply Quote 0
                            • d.healey
                              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

                              gorangrooves 1 Reply Last reply Reply Quote 0
                              • gorangrooves
                                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.healey 1 Reply Last reply Reply Quote 0
                                • d.healey
                                  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);😛

                                  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

                                  gorangrooves 1 Reply Last reply Reply Quote 0
                                  • gorangrooves
                                    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

                                    10
                                    Online

                                    1.2k
                                    Users

                                    7.0k
                                    Topics

                                    64.7k
                                    Posts