Jump to content

Scripter's script conflict [SOLVED]


Danny Wyatt
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();
  }
}

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

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

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();
  }
}

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

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