Dewdman42 Posted August 2, 2017 Share Posted August 2, 2017 Here is a Scripter JavaScript question for you gurus... this is probably simple, but I'm new to JavaScript, having a C++ background... here is the question. Let's say I want to create a DECLARED array of event objects that are hard coded into the script, some of them will be NoteOn, some NoteOff, some ControlChange, etc... Basically I want to have a nice neat and tidy looking table that has the whole array declared statically...so that no object constructors will have to be called during playback. Then later on I will reference array elements in order to send them. Is this possible? The only way I have figured out is like this: var myArray = [ new NoteOn(), new NoteOff(), new ControlChange() ]; The problem is that I can't see a way to declare an array of event objects this way which also have the various values assigned declaratively...in other words for each element in the array, I need the midi event, with the channel, number, value, etc..also declared for each instance. Is this even possible? I wish Scripter provided us with better constructors that include the ability to construct with those values filled in, or a way to add such a constructor perhaps, but this is not presently obvious to me how to do that. Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) Well maybe I figured out a way, but please let me know if you guys have figured out an easier or better way: var _NoteOn = function(beatPos, channel, pitch, velocity) { NoteOn.call(this, beatPos, channel, pitch, velocity); this.beatPos = beatPos; this.channel = channel; this.pitch = pitch; this.velocity = velocity; }; _NoteOn.prototype = Object.create(NoteOn.prototype); _NoteOn.prototype.constructor = _NoteOn; var myArray = [ new _NoteOn(1.2345,16,55,102); new _NoteOn(2.6567,1,34,100); ]; I don't entirely understand how that works, but it does seem to work. This creates a pseudo subclass of NoteOn, which can have its own constructor, and it does seem to work, I called the send() method on it...it worked. Is there an easier or more clear way though, to declare an array of midi events in a nice table like format like this? Edited August 2, 2017 by Dewdman42 Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted August 2, 2017 Share Posted August 2, 2017 You can extend the constructors yourself with ES6 classes: class betterNote extends Note{ constructor... etc } Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted August 2, 2017 Author Share Posted August 2, 2017 That will certainly be more clear once I upgrade to Sierra. Of course my script would only work on computers sierra and up with that...but that is nice to know that is coming in the future. So do you feel subclassing all the midi events is the best way to declaratively create an array of midi events? Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted August 2, 2017 Share Posted August 2, 2017 At least it is the way I will handle timed notes for Chordio in the next version. Can't really say if it's good or not but it works Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted August 2, 2017 Author Share Posted August 2, 2017 That answer works for me and it does seem to work pretty well that way. Thanks! 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.