Jump to content

Scripter's script conflict [SOLVED]


Go to solution Solved by David Nahmani,

Recommended Posts

So I have these 2 scripts working when used separately, but when I copy-paste them to create a single script, one of them stops working.

 

Here's one, to transpose a certain note:

function HandleMIDI(event) {
   if(event instanceof Note && event.pitch == 40) {
       event.pitch = 37 ;     
   }
   event.send();
}

 

Then another one to choke the crash on my new electronic drum kit:

function HandleMIDI(event)
{    event.trace();

  if (event instanceof PolyPressure) {
     if (event.pitch == 49 && event.value == 127) {      // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure.
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 28;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     } else if (event.pitch == 57 && event.value == 127) {
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 29;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     }
  } else {
  event.send();
  }
}

 

They work when they have their own separate Scripter insert. When I put them together, the transposition stops working:

// Transform snare's rim to sidestick

function HandleMIDI(event) {
   if(event instanceof Note && event.pitch == 40) {
       event.pitch = 37 ;     
   }
   event.send();
}


// Crash choke
function HandleMIDI(event)
{    event.trace();

  if (event instanceof PolyPressure) {
     if (event.pitch == 49 && event.value == 127) {      // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure.
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 28;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     } else if (event.pitch == 57 && event.value == 127) {
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 29;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     }
  } else {
  event.send();
  }
}

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

Link to comment
Share on other sites

Use only one function HandleMIDI(event) and only one event.send();

 

Copy your second if statement in the else portion of the first.

 

I have zero knowledge when it comes to Javascript :P

Can you send me the final script, please?

The first one was actually a script you sent me a while ago, to transpose a snare to the sidestick :)

viewtopic.php?f=1&t=160516&p=842808&hilit=sidestick+snare#p842811

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

Link to comment
Share on other sites

Use only one function HandleMIDI(event) and only one event.send();

 

Copy your second if statement in the else portion of the first.

 

While you look at it, do you know how to play a certain note based on a specific velocity range (1 to 63, for example) and then another note from 64 up to 127?

Here's my post: viewtopic.php?f=1&t=162505

 

I'm trying to make this new drum kit work as expected :)

 

Thanks

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

Link to comment
Share on other sites

  • Solution

I'm not 100% sure and don't have time to test but try something like this:

 

// Transform snare's rim to sidestick

function HandleMIDI(event) {
   if(event instanceof Note && event.pitch == 40) {
       event.pitch = 37 ;     
event.send();
   } else if (event instanceof PolyPressure) {
     if (event.pitch == 49 && event.value == 127) {      // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure.
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 28;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     } else if (event.pitch == 57 && event.value == 127) {
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 29;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     }
  } else {
  event.send();
  }
}

My new Logic Pro Book is out!

Link to comment
Share on other sites

I'm not 100% sure and don't have time to test but try something like this:

 

// Transform snare's rim to sidestick

function HandleMIDI(event) {
   if(event instanceof Note && event.pitch == 40) {
       event.pitch = 37 ;     
event.send();
   } else if (event instanceof PolyPressure) {
     if (event.pitch == 49 && event.value == 127) {      // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure.
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 28;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     } else if (event.pitch == 57 && event.value == 127) {
        var event = new NoteOn;
        event.channel = 10;
        event.pitch = 29;
        event.velocity = 1;
        event.trace();
        event.send();
        var of = new NoteOff(event);
        of.trace();
        of.send();
     }
  } else {
  event.send();
  }
}

 

Like a charm! :) Thanks!

Let me know if you know the answer to the other code I'm looking for. I'm closer to fixing this kit :)

Thanks

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

Link to comment
Share on other sites

By the way, most scripter related questions usually go to the MFX sub forum. easier to find them later in the future.

 

I rarely go to those sub forums... and since those are rarely visited by the users, it's always that feeling of "if I post this here, I have a low chance of it being seen" :P

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

Link to comment
Share on other sites

Scripting related posts generally go there

 

Sure, it makes sense. In this case it's just that the fact that I'm in a bit of a "hurry" to make this drum kit work, having the posts there it would maybe take longer for someone to really go there and check them :)

In the future, will definitely post there ;)

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...