What's new

Mr.Garibaldi

New Member
Hey,

I made a scripter plugin that allows me to "hotswap" samples in my sampler using MIDI CC. However I can't seem to make the CC values persist once I hit play or record or when I reload the project.

I made a video (w/ sound) that will probably demonstrate what I mean a little more clearly



This is the Script I made.
(Trigger warning for anybody who is an actual programmer)

If anybody has any suggestions how to improve this or where I could ask for help I would really appreciate it.
Thanks

var PluginParameters = [ {name:"Kick1", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0}, {name:"Kick2", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0}, {name:"Kick3", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0}, {name:"Snare", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0}, {name:"Snare2", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0} ]; function ParameterChanged(param, value) { if (param == 0) {var newControl = new ControlChange(); newControl.number = 2; newControl.value = value; newControl.send()}; if (param == 1) {var newControl = new ControlChange(); newControl.number = 3; newControl.value = value; newControl.send()}; if (param == 2) {var newControl = new ControlChange(); newControl.number = 5; newControl.value = value; newControl.send()}; if (param == 3) {var newControl = new ControlChange(); newControl.number = 8; newControl.value = value; newControl.send()}; if (param == 4) {var newControl = new ControlChange(); newControl.number = 9; newControl.value = value; newControl.send()}; }
 

robh

Senior Member
From what I can tell, your script is working. I think the instrument defaults to Layer one once you start the transport. The only way around it as far as I can tell is to actually record the Controller data in your region.

Rob
 

Dewdman42

Senior Member
Here is a reformatted source listing. I removed some unnecessary semi-colons which may or may not be related to the problem. I do not have access to a mac today to test anything.

One comment I have is that this script looks like it will send a CC value when a slider is moved, but may or may not actually send the midi when the script loads (most likely not) and definitely won't send the midi when you hit play.

If you want to try to have all the slider CC values sent when you hit PLAY, than try using the Reset() callback function. I'm not entirely sure if midi can be sent from that function, but try it. If that won't work, then you'll have to use Reset() to set a flag and then inside the ProcessMIDI() function you can look for the flag, send the midi and then tujrn off the flag.

In order to get things to be sent on project load, you have to remember that midi can't really be sent out right away when the script loads. It has to do a bunch of bootstrapping actions first. The GUI parameters cannot even be accessed right away either. When the LPX project loads it will process the top level of the script and then go into waiting mode where its waiting for callback functions to be triggered by LogicPro. Once it gets to that point in time, then you can start sending out midi. Same as before you could set a flag at the global level, and then inside ProcessMIDI() look for that flag, send the midi, then turn off the flag so that it doesn't happen again (unless you tell it to in the Reset function). Don't forget inside ProcessMIDI you'll have to also do some checks to see if the transport is actually playing or not too.

There is an undocumented Initialize callback function you can try to send the midi from there to see if it works, it may or may not. That would be a lot more simple then the above flag setting approach.

another thing you could try to do inside the Initialize function is basically Get and Set each GUI parameter, so that the ParameterChanged function will subsequently get called at that point during Initialize, and send the midi, maybe.

JavaScript:
var PluginParameters = [
        {
            name: "Kick1",
            type: "lin",
            minValue: 0,
            maxValue: 127,
            numberOfSteps: 127,
            defaultValue: 0
        },


        {
            name: "Kick2",
            type: "lin",
            minValue: 0,
            maxValue: 127,
            numberOfSteps: 127,
            defaultValue: 0
        },


        {
            name: "Kick3",
            type: "lin",
            minValue: 0,
            maxValue: 127,
            numberOfSteps: 127,
            defaultValue: 0
        },


        {
            name: "Snare",
            type: "lin",
            minValue: 0,
            maxValue: 127,
            numberOfSteps: 127,
            defaultValue: 0
        },


        {
            name: "Snare2",
            type: "lin",
            minValue: 0,
            maxValue: 127,
            numberOfSteps: 127,
            defaultValue: 0
        }
];

function ParameterChanged(param, value) {

    if (param == 0) {
        var newControl = new ControlChange();
        newControl.number = 2;
        newControl.value = value;
        newControl.send()
    }

    if (param == 1) {
        var newControl = new ControlChange();
        newControl.number = 3;
        newControl.value = value;
        newControl.send()
    }

    if (param == 2) {
        var newControl = new ControlChange();
        newControl.number = 5;
        newControl.value = value;
        newControl.send()
    }

    if (param == 3) {
        var newControl = new ControlChange();
        newControl.number = 8;
        newControl.value = value;
        newControl.send()
    }

    if (param == 4) {
        var newControl = new ControlChange();
        newControl.number = 9;
        newControl.value = value;
        newControl.send()
    }
}
 
Top Bottom