Marco Vismara Posted January 15, 2018 Share Posted January 15, 2018 (edited) 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 January 15, 2018 by Marco Vismara Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted January 15, 2018 Share Posted January 15, 2018 Sure it could be done. You will need to take care about keeping track of matching note-off's which would be the most complicated part as far as I can see. Quote Link to comment Share on other sites More sharing options...
Marco Vismara Posted January 15, 2018 Author Share Posted January 15, 2018 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 Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted January 15, 2018 Share Posted January 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
Marco Vismara Posted January 16, 2018 Author Share Posted January 16, 2018 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 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.