Monkeymonkey35 Posted April 14, 2018 Share Posted April 14, 2018 I'm using Trace to log the result of some functions that use random numbers. Since every note event in this script producers random numbers, is there a way to continually log that? Currently it takes a press of "Run Script" to log the numbers. Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted April 16, 2018 Share Posted April 16, 2018 could you post the script so we can look? if not, I'd make the created random number a property of the note event itself and add a method to the Note object that traces said property. Alternatively prototype displaying the property to the built in .trace method in the Note (or actually Event) object. But all this might be way too complicated depending on what you are trying to do. Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted April 16, 2018 Share Posted April 16, 2018 Also note there is a way to log arbitrary text with the Trace() function. Quote Link to comment Share on other sites More sharing options...
Monkeymonkey35 Posted April 16, 2018 Author Share Posted April 16, 2018 Sure: ResetParameterDefaults = true; var CutArray = [500, 600]; var RandomCut = CutArray[Math.floor(Math.random() * CutArray.length)]; function Randy(min,max) { var max = 500; var min = 50; return Math.floor(Math.random()*(max-min+1)+min); } function RandomPitch(min,max) { var max = 12; var min = 2 ; return Math.floor(Math.random()*(max-min+1)+min); } function RandomRepeats(min,max) { var max = 9; var min = 1 ; return Math.floor(Math.random()*(max-min+1)+min); } function HandleMIDI(event) { if (event instanceof Note) { var i = 1; while (i <= RandomRepeats() ) { event.pitch += (RandomPitch() ); event.sendAfterMilliseconds( (i-1) * Randy() ); i++ } event.velocity = 0; } else if (event instanceof NoteOff){ event.sendAfterBeat(randomCut); } } Trace("The Random ms offset is " + Randy() ); Trace("The Random pitch is " + RandomPitch() ); Trace("The Random cuttoff is " + RandomCut ); I need to study some more to implement your suggestions guys Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted April 16, 2018 Share Posted April 16, 2018 A couple things.. One, if you didn't figure this out already, if you randomly change the pitch of NoteOn's and NoteOff's, you're going to end up with some stuck notes. Two, In your code you are checking for instanceof Note, and I think you meant to use "instanceof NoteOn" Three, just move the Trace functions inside HandleMIDI to see more messages... you can put the Trace anywhere..put inside the randy functions if you want... But Scripter might start complaining if you try to send too many messages to the console too quickly. there are ways to work around that, but its complicated... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.