HISE Logo Forum
    • Categories
    • Register
    • Login

    Pushing Messages onto an Array?

    Scheduled Pinned Locked Moved Solved Scripting
    30 Posts 5 Posters 1.1k 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 @clevername27
      last edited by d.healey

      @clevername27 The MIDI list isn't for that purpose. It's not like an event list in a DAW.

      Christoph explains it in this post - https://forum.hise.audio/topic/79/scripting-best-practices

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

      clevername27C 1 Reply Last reply Reply Quote 1
      • clevername27C
        clevername27 @d.healey
        last edited by clevername27

        @d-healey Thank you for the reference - I guess I'm still not seeing how this object would be useful here. Off the cuff, this object has a performance advantage because it allocates all 128 slots at once, allowing pointer mathematics to access individual slots (instead of pulling them individually off the heap or from the stack). In @Christoph-Hart 's example for an array of notes, he simply uses a regular array (i.e., traditional linked list).

        404 Not Found

        favicon

        (docs.hise.audio)

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

          There is another container class called unordered stack which can hold the full event data but I think it‘s also limited to 256 slots.

          clevername27C 1 Reply Last reply Reply Quote 0
          • clevername27C
            clevername27 @Christoph Hart
            last edited by clevername27

            @Christoph-Hart Thank you - I'm also realizing you explicitly wrote in the documentation that the performance advantage of the MIDI List is not gained from pre-allocating the memory, so I'm not correct there.

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

              With a bit more context of your use case I might help you out. Your initial approach is not recommended, the array will allocate in the audio thread (and the AudioThreadGuard should complain).

              clevername27C 1 Reply Last reply Reply Quote 0
              • clevername27C
                clevername27 @Christoph Hart
                last edited by clevername27

                @Christoph-Hart Thank you, kindly. I'm looking to:

                1. Capture all incoming MIDI notes in real-time.

                2. Offline, I will adjust the Note-On and Note-Off timestamps.

                3. Finally, pipe the resulting note list into a MIDI Player, and play it back in time with the host DAW.

                Cheers, mate. I would post and comment my code for the community.

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

                  Before you reinvent the wheel, you are aware that the MIDI player has a record function that does exactly this? You can even supply it a post processing function that will give you an array of all new events that you then can process (eg. for quantization).

                  I'm using this in a current product I'm working on, so I would consider it stable but under documented - like everything in HISE that comes fresh out of the oven :)

                  These MIDIPlayer functions are useful in this case:

                  • setUseTimestampInTicks() - calling this in onInit is highly recommended as it will use ticks instead of samples as unit which makes sample rate agnostic operations much more simple (960 ticks = 1 quarter).
                  • record() / stop(): obvious...
                  • setRecordEventCallback() - supply it with a function that modifies the array of MessageHolders before it gets written into the MIDI sequence
                  • setSyncToMasterClock() hooks the MIDI player to be controlled by the master clock (and then use the TransportHandler for DAW syncing).
                  NatanN clevername27C 2 Replies Last reply Reply Quote 1
                  • NatanN
                    Natan @Christoph Hart
                    last edited by

                    @Christoph-Hart
                    Legend, Could you please Do an example for these?
                    setUseTimestampInTicks()
                    MidiPlayer.setSyncToMasterClock

                    clevername27C 1 Reply Last reply Reply Quote 0
                    • clevername27C
                      clevername27 @Natan
                      last edited by clevername27

                      @Natan EDIT: What I've written below is approximate, not actual code. You'll need to create MIDI player in your Module Tree.

                      const TH = Engine.createTransportHandler();
                      TH.setEnableGrid(true, 4);
                      TH.setSyncMode(TH.PreferExternal);
                      TH.setOnGridChange(true, GridChange);
                      const var yourMidiPlayer = Synth.getMidiPlayer("myMidiPlayer");
                      yourMidiPlayer.setUseTimestampInTicks();
                      yourMidiPlayer.setSyncToMasterClock(true);
                      

                      You'll need to either create a new sequence or load one.

                      NatanN 1 Reply Last reply Reply Quote 1
                      • clevername27C
                        clevername27 @Christoph Hart
                        last edited by

                        @Christoph-Hart Thank you for the suggestion. I tried that first, actually, but the MIDI player, and particularly recording, seemed oriented to looping a couple bars (e.g., MidiPlayer.create(int nominator, int denominator, int barLength))?

                        1 Reply Last reply Reply Quote 0
                        • NatanN
                          Natan @clevername27
                          last edited by Natan

                          @clevername27 Thank you so Much Mate <3 :folded_hands:
                          Is there any difference that I Can hear, I Mean the results of the above code are obvious or it's a daw and Midi Thing?

                          IMPORTANT! And one Quick question, Let's say I have 3 MidiPlayers, is It safe to use the code three times? or Inside a Loop?

                          clevername27C 1 Reply Last reply Reply Quote 0
                          • clevername27C
                            clevername27 @Natan
                            last edited by

                            @Natan Can you explain your first question in more detail? If you have three MIDI players, then you'd need to do this for all three—you'd call this at init, not inside a loop.

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

                              @clevername27 except if they are stored in an array:

                              const var yourMidiPlayers = [Synth.getMidiPlayer("myMidiPlayer1"),
                              			     Synth.getMidiPlayer("myMidiPlayer2"),
                              			     Synth.getMidiPlayer("myMidiPlayer3")];
                              
                              for (p in yourMidiPlayers)
                              {
                              	p.setUseTimestampInTicks();
                              	p.setSyncToMasterClock();
                              }
                              

                              Can't help pressing F5 in the forum...

                              clevername27C 1 Reply Last reply Reply Quote 2
                              • clevername27C
                                clevername27 @ustk
                                last edited by clevername27

                                @ustk Ah, OK cheers - I wasn't sure what @Natan meant by an array. Do you know what the error message "You have to enable the master clock before using this method" is?

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

                                  @clevername27 following this:

                                  void ScriptingObjects::ScriptedMidiPlayer::setSyncToMasterClock(bool shouldSyncToMasterClock)
                                  {
                                  	if (shouldSyncToMasterClock && !getScriptProcessor()->getMainController_()->getMasterClock().isGridEnabled())
                                  	{
                                  		reportScriptError("You have to enable the master clock before using this method");
                                  	}
                                  	else
                                  	{
                                  		getPlayer()->setSyncToMasterClock(shouldSyncToMasterClock);
                                  	}
                                  }
                                  

                                  The grid has to be enabled

                                  Can't help pressing F5 in the forum...

                                  clevername27C 1 Reply Last reply Reply Quote 1
                                  • clevername27C
                                    clevername27 @ustk
                                    last edited by

                                    @ustk Cheers!

                                    clevername27C 1 Reply Last reply Reply Quote 0
                                    • clevername27C
                                      clevername27 @clevername27
                                      last edited by clevername27

                                      @clevername27 Solved.

                                      1 Reply Last reply Reply Quote 0
                                      • clevername27C clevername27 has marked this topic as solved on
                                      • First post
                                        Last post

                                      10

                                      Online

                                      1.8k

                                      Users

                                      11.9k

                                      Topics

                                      104.0k

                                      Posts