HISE Logo Forum
    • Categories
    • Register
    • Login

    Randomizing MIDI Notes

    Scheduled Pinned Locked Moved General Questions
    14 Posts 3 Posters 786 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.
    • B
      BWSounds
      last edited by

      I need guidance with this one!
      I've figured out how to add notes using Midiplayer.create and how to randomize THOSE notes. The problem is randomizing notes from a "drag and drop" midi file.
      I've been trying to figure out a way to do this for a while now and my brain hurts ☹ ... any insight if possible would be greatly appreciated.

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

        Do you want to automatically randomize the notes after you dropped them or make it a separate function?

        Making it automatically is not so easy because there is currently no scripting hook for the sequence change event.

        But randomizing notes with a click of a button is pretty easy:

        // Disclaimer: not tested, just something from the top of my head...
        
        const var list = player.getEventList();
        
        for(note in list)
        {
            if(note.isNoteOn())
                note.setTransposeAmount(Math.randInt(-5, 5));
        }
        
        player.flushEventList(list);
        

        EDIT: I could add a post-event callback that you can assign a function to pretty easily:

        // This will be fired everytime a new sequence is being loaded.
        player.setPostLoadingCallback(function()
        {
              local list = this.getEventList();
        
              for(note in list)
              {
                  if(note.isNoteOn())
                      note.setTransposeAmount(Math.randInt(-5, 5));
              }
              
              this.flushEventList(list);
        }
        
        B 2 Replies Last reply Reply Quote 1
        • B
          BWSounds @Christoph Hart
          last edited by

          @Christoph-Hart Humm i'll give it a go!
          Thank you.

          1 Reply Last reply Reply Quote 0
          • B
            BWSounds @Christoph Hart
            last edited by

            @Christoph-Hart got it going!... Is there a way to change the note position instead of transposing them?

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

              Yeah, sure, just adjust the timestamp.

              B 1 Reply Last reply Reply Quote 0
              • B
                BWSounds @Christoph Hart
                last edited by

                @Christoph-Hart
                So I did... (and I may be way off with this)

                if(note.isNoteOn())
                    note.setTimestamp(Math.randInt(3, 6));
                

                but it just stretched them all from the start point.

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

                  note.setTimestamp(note.getTimestamp() + Math.randInt(3, 6));

                  But unless you have super powers, you won't hear the timing differences of 0.00015 seconds :)

                  B 2 Replies Last reply Reply Quote 1
                  • B
                    BWSounds @Christoph Hart
                    last edited by

                    @Christoph-Hart said in Randomizing MIDI Notes:

                    note.setTimestamp(note.getTimestamp() + Math.randInt(3, 6));

                    But unless you have super powers, you won't hear the timing differences of 0.00015 seconds :)

                    Haha... Thank you, I got it rolling now! With a more realistic timing difference.

                    1 Reply Last reply Reply Quote 0
                    • B
                      BWSounds @Christoph Hart
                      last edited by

                      @Christoph-Hart
                      Is it possible to kind of add a more predictable randomization to the notes?
                      like set the transpose to go up or down 12st (nothing in between) or shift the notes forward or back a certain amount? Or an I asking for to much lol?

                      Ive been trying to figure out how the seconds (EX.(-200000.50000, 0.50000)) work and how I could use that to accomplish my goal.

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

                        Up or down 12st:

                        Message.setTransposeAmount(Math.random() > 0.5 ? 12 : -12);
                        

                        The timestamp unit is sample rate, so you need to use Engine.getMillisecondsForSamples() to get the second amount (there are also other conversion functions in the Engine object that you can use to get tempo based values.

                        B 3 Replies Last reply Reply Quote 1
                        • B
                          BWSounds @Christoph Hart
                          last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • B
                            BWSounds @Christoph Hart
                            last edited by

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • B
                              BWSounds @Christoph Hart
                              last edited by

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • NatanN
                                Natan
                                last edited by

                                This post is deleted!
                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post

                                45

                                Online

                                1.7k

                                Users

                                11.7k

                                Topics

                                101.8k

                                Posts