Jump to content

Scripter Javascript question


Dewdman42

Recommended Posts

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.

Link to comment
Share on other sites

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 by Dewdman42
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...