HISE Logo Forum
    • Categories
    • Register
    • Login

    How to get event ids for artificial events?

    Scheduled Pinned Locked Moved Scripting
    28 Posts 3 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 @benosterhouse
      last edited by d.healey

      @benosterhouse

      The next question would be why I'm wanting to keep track of the play position of every event.

      Go on :)

      On a piano wouldn't a repeated note cancel out the previous note, since it's striking the same string?

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

      1 Reply Last reply Reply Quote 0
      • B
        benosterhouse
        last edited by

        Basically, I'm seeing if I can port a library to vst using hise.
        It has string swells in it, which are tempo synced. I see that hise doesn't really have timestretching yet, but I was realizing there's another way around it:
        If you play the beginning of the swell, then crossfade into the middle of the swell, you can adjust the length of the swell, so it'd fit into any project tempo (the phasing isn't too bad. I have some ideas to get around that).

        If you're fading together different parts of the swell, the tail end of it needs to be started with an artificial event.
        If you have multiple stiched-together swells (which use artificial events), and they're happening on the same key at the same time, you need a way to note-off all the artificial events when you lift the pedal.

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

          @benosterhouse I get it, I'll play around with it a little tomorrow and see if I can come up with a way of managing the sustain/note off thing manually.

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

          1 Reply Last reply Reply Quote 0
          • B
            benosterhouse
            last edited by benosterhouse

            Ok cool!
            On a sampled piano, if you play a repeated note with the pedal down you want to keep the previous sample going.

            1 Reply Last reply Reply Quote 0
            • B
              benosterhouse
              last edited by

              Ok, that way I was trying to iterate through things before was too complicated and didn't actually work.

              I just added another dimension to the array so I could record more than one event id per key!
              Waaay simpler.

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

                How many events do you want to record per key? I'm still thinking that with acoustic instruments in general each repeated note will kill old notes, causing them to decay.

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

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

                  That's not completely true. For example if you press down the sustain pedal, play a loud note on the piano, then play a soft note on the same key shortly after it, you would hear that the new note is fading down the old note which sounds really bad.

                  That's why in the sampler options you have the "Kill second note" retrigger behaviour which allows you to have at least two notes of the same key ringing at once. This weakens that effect a little bit, but it's still noticeable.

                  d.healeyD 1 Reply Last reply Reply Quote 1
                  • d.healeyD
                    d.healey @Christoph Hart
                    last edited by

                    @Christoph-Hart Very good point!

                    1505a50a-4d81-4d14-9e10-b24425d75489-image.png

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

                    1 Reply Last reply Reply Quote 0
                    • B
                      benosterhouse
                      last edited by benosterhouse

                      This should record as many event ids per key as needed --I didn't set a max number.

                      Here's what I got!

                      function onNoteOn()
                      {     
                          Message.ignoreEvent(true);
                          
                          note = Message.getNoteNumber();
                          if (keyDown.getValue(note) == 1)
                              keyVoiceCount[note]++;
                              
                          g_group_allows[G_START] = 1;
                          eventIds[note][keyVoiceCount[note]] = Synth.playNote(note, 64);
                          eventTimeStamp[note][keyVoiceCount[note]] = Engine.getUptime();
                          keyDown.setValue(note, 1);
                      }
                      
                      function onNoteOff()
                      {   
                          if (pedal == 0) 
                          {
                              keyDown.setValue(Message.getNoteNumber(), 0);
                              note = Message.getNoteNumber();
                              for (v = 0; v <= keyVoiceCount[note]; v++)
                              {
                                  Synth.noteOffByEventId(eventIds[note][v]);
                                  if (delayedEventIds[note][v])
                                  {
                                      Synth.noteOffByEventId(delayedEventIds[note][v]);
                                      delayedEventIds[note][v] = 0;
                                  };
                                  eventTimeStamp[note][v] = 0;
                              };
                              keyVoiceCount[note] = 0;
                          };
                      }
                       
                      function onTimer()
                      {
                          for (n = 0; n < 128; n++)
                          {
                              for (v = 0; v <= keyVoiceCount[n]; v++)
                              {
                                  if (eventTimeStamp[n][v]) 
                                  {
                                      playPos = (Engine.getUptime() - eventTimeStamp[n][v]) * 1000;
                                      playPos = Engine.getQuarterBeatsForMilliSeconds(playPos);
                                      if (playPos > 4 && !delayedEventIds[n][v])
                                      {
                                          g_group_allows[G_START] = 1;
                                          delayedEventIds[n][v] = Synth.playNote(n, 64);
                                      };
                                  };
                              };  
                          };
                      }
                       
                      function onController()
                      {
                          if (Message.getControllerNumber() == 64) 
                          {
                              if (Message.getControllerValue() > 5) 
                              {
                                  pedal = 1;
                                  //Console.print("pedal down");
                              } else {
                                  pedal = 0;
                                  for (n = 0; n < 128; n++)
                                  {
                                      if (Synth.isKeyDown(n) == 0 && keyDown.getValue(n) == 1)
                                      {
                                          keyDown.setValue(n, 0);
                                          for (v = 0; v <= keyVoiceCount[n]; v++)
                                          {   
                                              Synth.noteOffByEventId(eventIds[n][v]);
                                              eventIds[n][v] = 0;
                                              Synth.noteOffByEventId(delayedEventIds[n][v]);
                                              delayedEventIds[n][v] = 0;
                                              eventTimeStamp[n][v] = 0;
                                          };
                                          keyVoiceCount[n] = 0;
                                      };
                                  };
                              };
                          };
                      }
                       
                      

                      So basically now you can have multiple parallel sequences of artificial events on the same key, which are note off'd correctly by the pedal.

                      Before, I did this by using Synth.addNote() to schedule the sequence of artificial events, but I was running into some problems there.

                      This is with Retrigger set to "Do nothing"

                      Man, this was a lot of work! Maybe I should have just done the "Kill Duplicate" option and just NOT allowed overlapping swells on the same key haha :face_with_tongue:

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

                        @benosterhouse

                        Maybe I should have just done the "Kill Duplicate" option and just NOT allowed overlapping swells on the same key haha

                        Looks like you're having fun though :)

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

                        1 Reply Last reply Reply Quote 0
                        • B
                          benosterhouse
                          last edited by

                          Yep, I'm learning a lot :)

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

                            Yep, I'm learning a lot

                            Make sure you use the reserve function for all those arrays to avoid allocating items in the MIDI callbacks:

                            Link Preview Image
                            HISE | Docs

                            favicon

                            (docs.hise.audio)

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

                              @Christoph-Hart Would an array of MIDI lists be more efficient?

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

                              1 Reply Last reply Reply Quote 0
                              • B
                                benosterhouse
                                last edited by benosterhouse

                                For a multi-dimensional array, would reserve make sense used this way?

                                delayedEventIds.reserve(128); // note slots
                                delayedEventIds[n].reserve(16); // reserve 16 voices per note slot
                                delayedEventIds[n][v] = Synth.playNote(n, 64);
                                
                                1 Reply Last reply Reply Quote 0
                                • Christoph HartC
                                  Christoph Hart
                                  last edited by

                                  Yes. You might need to initialise the element at delayedEventIds[n]
                                  as array before calling reserve, but then it should work.

                                  @d-healey the efficiency of the MIDI list gets interesting as soon as it helps you avoid writing for loops, so

                                  • searching for an item
                                  • clearing all items

                                  It will speed up things a bit.

                                  The nested for loop in this example will most likely be the bottleneck, so I would start optimizing there on a higher level though...

                                  1 Reply Last reply Reply Quote 0
                                  • B
                                    benosterhouse
                                    last edited by

                                    Cool, yep it gets initialized in the onInit

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

                                    28

                                    Online

                                    1.7k

                                    Users

                                    11.9k

                                    Topics

                                    103.3k

                                    Posts