Randomizing MIDI Notes
-
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. -
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); }
-
@Christoph-Hart Humm i'll give it a go!
Thank you. -
@Christoph-Hart got it going!... Is there a way to change the note position instead of transposing them?
-
Yeah, sure, just adjust the timestamp.
-
@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.
-
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 :)
-
@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.
-
@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.
-
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 theEngine
object that you can use to get tempo based values. -
This post is deleted! -
This post is deleted! -
This post is deleted! -
This post is deleted!