rsjaffe / MIDI2LR

An application and plugin to remotely control Lightroom with a MIDI controller
http://rsjaffe.github.io/MIDI2LR/
GNU General Public License v3.0
693 stars 83 forks source link

Temperature control--beta test available #52

Closed rsjaffe closed 8 years ago

rsjaffe commented 8 years ago

We removed limits on the temperature control as some people were finding the knobs to be unresponsive in certain situations. Now I've put together a possible fix to that.

If you are interested in trying the fix, first make a backup copy of the MIDI2LR_client.lua file, then replace the three functions: midi_lerp_to_develop, develop_lerp_to_midi and updateParam, by pasting over them the following replacement code. The change will take effect after reloading the plugin or restarting Lightroom. If this doesn't fix it, we'll have to change the PICKUP_THRESHOLD for Temperatures. Please send me any feedback on this fix. Thanks.

function midi_lerp_to_develop(param, midi_value)
    -- map midi range to develop parameter range
    local min,max = LrDevelopController.getRange(param)
    if(param == 'Temperature') then
        min = 3000
        max = 9000
    end

    local result = midi_value/MIDI2LR.CONTROL_MAX * (max-min) + min
    return result
end

function develop_lerp_to_midi(param)
    -- map develop parameter range to midi range
    local min, max = LrDevelopController.getRange(param)
    if(param == 'Temperature') then
        min = 3000
        max = 9000
    end

    local result = (LrDevelopController.getValue(param)-min)/(max-min) * MIDI2LR.CONTROL_MAX
    return result
end

function updateParam(param, midi_value)
    -- this function does a 'pickup' type of check
    -- that is, it will ensure the develop parameter is close 
    -- to what the inputted command value is before updating it
    if LrApplicationView.getCurrentModuleName() ~= 'develop' then
            LrApplicationView.switchToModule('develop')
    end

    if (MIDI2LR.PICKUP_ENABLED and (param == 'Temperature')) then --clamp temperature to limits to allow pickup to work
        local TempValue = LrDevelopController.getValue('Temperature')
        if TempValue > 9000 then
            MIDI2LR.PARAM_OBSERVER['Temperature'] = 9000
            LrDevelopController.setValue('Temperature',9000)
        elseif TempValue < 3000 then
            MIDI2LR.PARAM_OBSERVER['Temperature'] = 3000
            LrDevelopController.setValue('Temperature',3000)
        end
    end

    if((not MIDI2LR.PICKUP_ENABLED) or (math.abs(midi_value - develop_lerp_to_midi(param)) <= MIDI2LR.PICKUP_THRESHOLD)) then
        MIDI2LR.PARAM_OBSERVER[param] = midi_lerp_to_develop(param, midi_value)
        LrDevelopController.setValue(param, midi_lerp_to_develop(param, midi_value))
        MIDI2LR.LAST_PARAM = param
    end
end
rsjaffe commented 8 years ago

This code is now integrated into the latest release v0.5.0