Jump to content

Realtime exponential scaling script?


dasan90

Recommended Posts

Hey guys, I want to be able to scale midi cc values, for instance mod wheel values 0-127, to grow exponentially by a specified constant (see picture). Any idea how you could do this in logic pro x scripter? When input is 0, i want output to be 0, and when input is 127 i want output to be 127 etc, but everything in between is scaled accordingly.

z4Bid.png

Thanks in advance,

David

Link to comment
Share on other sites

var GAMMA = 2.2;  // gamma

function HandleMIDI(event) {
    if (event instanceof ControlChange) {
        event.value = 127 * Math.pow((event.value/127),GAMMA);
    }
    event.send();
}

Try the above.  Gamma values between 0-1 will result in a curve above the diagonal line and values above 1 will result in curves below the diagonal line.

Link to comment
Share on other sites

  • 3 years later...

Here's a version with a GUI that is made specifically for velocity:

472798148_ScreenShot2021-03-17at11_12_03AM.jpg.4ce660801a98679f126a51afbfc5db66.jpg

var scaled = [];

function calculateCurve(gamma) {
   for(let i=0; i<=127; i++) {
       scaled[i] = 127 * Math.pow((i/127), gamma ); 
   }
}

function HandleMIDI(event) {

   if (event instanceof NoteOn) {
       event.velocity = scaled[event.velocity];
   }
   event.send();

}

//-------
// GUI
//-------
var PluginParameters = [];

PluginParameters.push({
   name: "Gamma",
   type: "lin",
   defaultValue: 2.2,
   minValue: 0,
   maxValue: 10,
   numberOfSteps: 100
});

var GuiParameters = {
   data: [],
   set: function(id, val) {
       if(typeof id != "string") id = PluginParameters[id].name;
       this.data[id] = val;
   },
   get: function(id) {
       if(typeof id != "string") id = PluginParameters[id].name;
       if(this.data[id] == undefined) {
           this.data[id] = GetParameter(id);
       }
       return this.data[id];
   }
};
function ParameterChanged(id, val) {
   GuiParameters.set(id, val);    
   calculateCurve(val);
}
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...