Jump to content

Strange kind of script [SOLVED]


Recommended Posts

Hi everybody

 

I'm totally new to JS but I need to make a very simple script.

 

Let's say I play a C3 note, I'd like to hear a C3 note,

let's say I play a D3 note, I'd like to hear a D3 note,

let's say I play one more time a D3 note, I'd like to hear the previous C3 note...and so on!

 

What I'm trying to do is to save the last played note in a variable so I can play it again in case a different note is played twice.

 

I have some difficults to explain it in English but I'm sure that you've got the point!

 

Any advices?

 

Thank you very much!

mV

Edited by Marco Vismara
Link to comment
Share on other sites

Hey

 

I did it...and it works!!!

My first Javascript!!!

 

Here it is:

 

var Played = new NoteOn;

var Old = new NoteOn;

Played.pitch = 0;

Played.velocity = 30;

Old.pitch = 0;

Old.velocity = 30;

 

function HandleMIDI(event)

{

event.velocity = 30;

if(event.pitch != Played.pitch) {

event.send();

Old.pitch = Played.pitch;

Played.pitch = event.pitch;

} else

if(event.pitch != Old.pitch) {

Old.send();

Played.pitch = Old.pitch;

} else {

Old.send();

}

}

 

Thank you

mV

Link to comment
Share on other sites

2 things...

 

I would reccomend you use instanceof to limit the processing only to NoteOn events...

 

var Played = new NoteOn;
var Old = new NoteOn;

Played.pitch = 0;
Played.velocity = 30;
Old.pitch = 0;
Old.velocity = 30;

function HandleMIDI(event) {

  if (!(event instanceof NoteOn)) {
     event.send();
     return;
  }
  
  event.velocity = 30;
  
  if(event.pitch != Played.pitch) {
     event.send();
     Old.pitch = Played.pitch;
     Played.pitch = event.pitch;
  } 
  
  else {
     if(event.pitch != Old.pitch)	{
        Old.send();
        Played.pitch = Old.pitch;
     } 
     else {
        Old.send();
     }
  }
}

 

Secondly, you are losing noteoff events and getting hanging notes with this script. In order to do it properly you will need to keep track of which incoming notes have been changed so that the matching incoming noteoff will also be changed.

Link to comment
Share on other sites

Thank you!

 

My poor knowledge of JS doesn't allow me to further modify the script but...

 

The controller that I use to trigger the notes is an old Rolls Midibuddy that sends program changes that are transformed in notes through the environment (Of course no dynamics are allowed), and the VSTi that I use is programmed to not overlap the notes.

 

I've already used this setup in live concert.

 

I have two Midibuddy and one of them behaves like the script that I wrote. I wanted both the chances but I don't want to travel with two pedalboards, so...now I'm satisfied!

 

Thank you

mV

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