A technical support community for Apple Logic Pro users.

 
dasan90
Topic Author
Posts: 2
Joined: Thu Aug 24, 2017 2:06 pm

Realtime exponential scaling script?

Thu Aug 24, 2017 2:23 pm

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.

Image

Thanks in advance,
David
 
User avatar
Dewdman42
Posts: 3202
Joined: Tue Sep 09, 2014 3:01 pm
Location: Salt Lake City, UT

Re: Realtime exponential scaling script?

Thu Aug 24, 2017 2:57 pm

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.
OSX 10.15 (Catalina) on OpenCore - Logic Pro 10.6.1, VePro7, Mainstage3
5,1 MacPro 3.46ghz x 12 128gb ram
 
dasan90
Topic Author
Posts: 2
Joined: Thu Aug 24, 2017 2:06 pm

Re: Realtime exponential scaling script?

Fri Aug 25, 2017 6:06 am

It works! Thanks a lot!
 
User avatar
Dewdman42
Posts: 3202
Joined: Tue Sep 09, 2014 3:01 pm
Location: Salt Lake City, UT

Re: Realtime exponential scaling script?

Wed Mar 17, 2021 10:09 am

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

Screen Shot 2021-03-17 at 11.12.03 AM.jpg
Screen Shot 2021-03-17 at 11.12.03 AM.jpg (58.73 KiB) Viewed 351 times


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);
}
OSX 10.15 (Catalina) on OpenCore - Logic Pro 10.6.1, VePro7, Mainstage3
5,1 MacPro 3.46ghz x 12 128gb ram