Jump to content

Need help writing my custom Scripter code


rjp9

Recommended Posts

Hi forum.

 

Trying to convert my thought into Javascript for a Scripter plugin, and need help with the Javascript syntax.

 

Here's what I'm trying to do: I have a drum pad that I want to use to trigger synth drones.

 

Here's the logic as far as I can work it out:

 

Look at incoming MIDI messages with function HandleMIDI(event){};

If the incoming message is a note on message:

Check to see if a note is already playing. If not, begin a new note

If a note is already playing, send a note off message for that note and a note on message for the new note, with a velocity of 127 (so drones don't overlap).

If I repeat note, send a note off message for that note and do not start a new note.

 

If it's a noteoff message, do nothing (noteoffs should be handled above)

 

Now some special things:

I have 5 drones to trigger. Drone 1 consists of MIDI notes 42 and 49 played simultaneously. Drone 2 is 38 and 45 ...and so on. However, my drum pad is hardwired to output other MIDI notes. I know I can fix this in Chord Trigger or something but I want to learn how to do all in one Scripter plugin! So for example if the incoming MIDI note is 26, I want to send a perfect 5th of 42 and 49 to my synthesizer. If the incoming MIDI note is 28, I want to send 38 and 45 ...and so on. How do I do that in Javascript?

 

BONUS: Also, I want to have an epic bass sample play when I start each drone. The synthesizer for the bass sample is on channel 2. How do I include a noteon message for a synth on a different channel?

Link to comment
Share on other sites

Everything except how to store a value (i.e how to use the note value for the last NoteOn for a new NoteOff), and how to "send" multiple notes simultaneously and on independent channels.

 

for your first question:

 

if you use 'event' as the name of the expression in

function HandleMIDI(event)

 

you create a new instance like this (example):

var killEvent = new NoteOff(event);

 

send it like this:

killEvent.send();

 

 

to alter the channel of an existing event or a new event (example):

event.channel = 2;

OR

killEvent.channel = 2;

you do this after creating the event if it is a new one.

 

 

you can create as many NoteOns and NoteOffs (and send them on any channel) as you like in the HandleMIDI function.

easiest way to handle this is with switches combined with if statements.

 

 

 

To achieve what you want in full you need a variable to keep track of which notes are playing. I'd probably go with an array that contains all 128 notes and toggle state between 0 and 1 via the midi events received and triggered - and check against this array for current status of notes to determine how the HandleMIDI function should behave. There are several ways to do this though, not only with an array. I am not sure if you need to keep track of several channels as well, in which case an array might be a bit chunky (16x128) - it wouldn't really affect performance though.

 

If you post your code so far (or PM it to me) I am sure we can help you.

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...