Jump to content

need help with script to filter note ons from Arp


swedemason

Recommended Posts

Hello. Happy new year folks. Can anyone on here help me with a script for my live drum roll patch please?. Unfortunately I'm code illiterate and so Im pulling my hair out trying to cut and paste a script together. Basically I want to make my sustain pedal or any momentary on off cc switch to cut off midi notes coming from an arpeggiator at the top of the midi chain - simple enough, but i want to let the next note through just after i press the sustain pedal, and for that note to be sustained. The sustain part i have managed to achieve by filtering note offs - I altered this script that was posted on here:

var thru = false;

 

function HandleMIDI(event) {

 

if (event instanceof ControlChange && event.number==64) {

if(event.value < 50) {

thru = true;

}

else {

thru = false;

}

}

 

if(event instanceof NoteOn && !thru) {

return;

}

 

event.send();

}

 

My problem with this script is that i have to press the pedal just after the note on from the arp, and before the note off, for it to work correctly. This is difficult to time right if the arp is anything above 8th notes, so it's crap for the live thing I'm after.

 

My idea was to use the 'Note triggered midi event gate' factory script to make it wait for the next note on after id pressed the pedal, and then for it to filter out any note ons until the pedal is released, but whatever im doing isnt working.

 

Is there any way to achieve this?

 

Thanks

 

Swede

Link to comment
Share on other sites

Hi Atlas, thanks for the reply. Ive tried smart controls but they don't quite do i what i want. I still need the note to sustain - using smart controls hijacks the normal midi behavior of the sustain pedal. Even if routing to an IAC I can't get the note to sustain at the same time as stopping the arp. The main issue with this method though is the the timing thing. I still have to be spot on, and hit the pedal after the note on message which I find unintuitive for live input.

Basically what I want to say in script form is, when i press cc64 or whatever pedal, after next note on is received (from the arp), filter all note ons until the pedal is released.

Is this possible?

Ta

S

Link to comment
Share on other sites

Hi Atlas, thanks for the reply. Ive tried smart controls but they don't quite do i what i want. I still need the note to sustain - using smart controls hijacks the normal midi behavior of the sustain pedal. Even if routing to an IAC I can't get the note to sustain at the same time as stopping the arp. The main issue with this method though is the the timing thing. I still have to be spot on, and hit the pedal after the note on message which I find unintuitive for live input.

Basically what I want to say in script form is, when i press cc64 or whatever pedal, after next note on is received (from the arp), filter all note ons until the pedal is released.

Is this possible?

Ta

S

Then, I would still suggest using the Smart Control, but using a different CC than #64, since you need it... Opting for a CC that eventually gets hijacked without interfering with your setup should therefore be made.

 

Also, to adjust the delay between the moment you actuate that pedal and the moment the Arpeggiator turns Off/On, I believe that a Delay line object in the environment fits the bill.

 

The CC sent from the pedal would nevertheless require to be transformed into a different CC, looped back in Logic via an IAC, and then be mapped in Smart Control to operate that Arp On/Off switch.

 

Technically speaking, I think that the Delay Line object has to be set to delay the first (and only one tap/echo) within the Arpeggiator's rythmic time unit value, to ensure that it will turn off at the desired moment. Meaning also that the original impulse to be suppressed.

 

In short:

Pedal sends CCx to [DelayLineObj] cabled to [TransformObj: CCx becomes CCy], CCy is sent, via an IAC, looped back into Logic. CCy is then mapped to actuate the Arpeggiator's On/Off switch in the Smart Control.

 

Transforming CCx to CCy permits using the DelayLine object in the Environment. CCx (from the pedal) will not be hijacked; OTOH, CCy will be, once mapped in Smart Control. Theoretically, CCx might be CC#64, but personally I would leave it out of the equation...

 

Some DelayLine Object's parameters tweaking will be required to adjust the proper reaction time between the pedal actuation and the Arp On/Off reaction.

Edited by Atlas007
Link to comment
Share on other sites

So some ideas I have to make usage a little easier to time:

 

  1. Keep an array that keeps track of what note(s) are currently on at any given moment in time.
  2. with that knowledge, your script can detect slightly different situations. For example you could have it so that if a note is sustaining when you hit the pedal, then set a flag and wait for the next note before sustaining that next one. don't block arp until that last note hits.
  3. or there could be other situations, but the point is to make your script a little more aware of what notes are currently sustained at the moment you hit the sustain pedal and how to handle it.

 

In order to keep track of sustaining notes, make an array at the global level and then each time a note on or note off comes in, increment/decrement a counter.

 

var trackNotes = [];
for (var i=0;i<128;i++) {
   trackNotes[i] = 0;
}

function HandleMIDI(event) {

   if (event instanceof NoteOn) {
       trackNotes[event.pitch]++;
   }
   else if (event instanceof NoteOff) {
       trackNotes[event.pitch]--;
   }
   
   
   event.send();
   event.trace();
}

 

Then you can look at that array to see what notes are currently on.

 

Also you will need to keep track of the note you sustained, in order to send a final NoteOff when you release the sustain pedal.

Link to comment
Share on other sites

Hi Atlas. I tried your suggestion. Unfortunately i cant get it to work. I've changed cc64 to 68 in the env. I can delay the cc with the delay line. I can route it out and back in via IAC. It is the only message going through logic from the environment but the smart control still maps cc64 in controller assignments?! I change the input to IAC and nothing happens in smart controls. Ive had this problem before but i cant remember the workaround. This is the end of the line for me in the smart control route. The control mapping in logic is so unintuitive for me I havn't the patience or time to persevere with it atm. From looking at monitors in the env the delay will just delay my initial input, and if my timing is out on the input then itl just shift this timing along by whatever value i choose. This isnt going achieve what im after unfortunately, i need something more forgiving of the initial input. Looks like I'm gonna have to learn how to script! Thanks for your help.

Ta

S

Link to comment
Share on other sites

This might get you closer, but I'm not sure I have exactly right the behavior you want in terms of cutting off the old notes and waiting for the next note to be sustained. Try this and let me know how it goes. Note I had to use CC100 instead of sustain pedal because the Logic Arpegiator eats the sustain pedal for latch modes and stuff, which might be another way for you to do what you're wanting to do BTW. So anyway, edit the script to whatever CC controller you want to use and try that.

 

Also, this script assumes no overlapping notes from the arp. It just cuts off the last note at time of hitting the sustain, then sustains the next one until you release the CC100. If you have the possibility for overlapping notes, then you need to keep track of which notes are sustaining and issue NoteOff's for all of them.

 

var noff = new NoteOff;
noff.velocity = 100;

var lastNote = 0;
var sustained = false;
var held = false;

function HandleMIDI(event) {

   // If CC100 changed, track it
   if (event instanceof ControlChange 
           && event.number == 100) {
       
       // if sustain pedal changed to down
       if ( event.value > 64 ) {
           sustained = true;
           cutOffHeld();
       }
       // sustain pedal released
       else {
           sustained = false;
           cutOffHeld();
           held = false;
       }
       return;
   }
   
   // Handle NoteOn and NoteOff
   if (event instanceof NoteOn) {
   
       noff.channel = event.channel;
   
       if (sustained) {
           if(held) {
              return;
           }
           else {
               event.send();
               held = true;
               lastNote = event.pitch;
           }
       }
       else {
           event.send();
           lastNote = event.pitch;
       }
   }
   
   else if (event instanceof NoteOff) {
       if(held) {
           return;
       }
       else {
           event.send();
           
       }
   }
}


function cutOffHeld() {
   noff.pitch = lastNote;
   noff.send();
}
Link to comment
Share on other sites

Try this:

 

var noff = new NoteOff;
noff.velocity = 100;

var lastNote = 0;
var sustained = false;
var held = false;

function HandleMIDI(event) {

   // If CC100 changed, track it
   if (event instanceof ControlChange 
           && event.number == 100) {
       
       // if sustain pedal changed to down
       if ( event.value > 64 ) {
           sustained = true;
       }
       // sustain pedal released
       else {
           sustained = false;
           cutOffHeld();
           held = false;
       }
       return;
   }
   
   // Handle NoteOn and NoteOff
   if (event instanceof NoteOn) {
   
       noff.channel = event.channel;
   
       if (sustained) {
           if(held) {
              return;
           }
           else {
               event.send();
               held = true;
               lastNote = event.pitch;
           }
       }
       else {
           event.send();
           lastNote = event.pitch;
       }
   }
   
   else if (event instanceof NoteOff) {
       if(held) {
           return;
       }
       else {
           event.send();
       }
   }
   else {
       event.send();
   }
}


function cutOffHeld() {
   noff.pitch = lastNote;
   noff.send();
}
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...