Skip to content

Commit

Permalink
Release Clamp velocity of selected MIDI notes v1.0.3 (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfillion authored Aug 19, 2023
1 parent e073798 commit 80a6033
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions MIDI Editor/cfillion_Clamp velocity of selected MIDI notes.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- @description Clamp velocity of selected MIDI notes
-- @author cfillion
-- @version 1.0.2
-- @changelog Add keyboard shortcuts (Enter for OK and Escape for Cancel)
-- @provides [main=main,midi_inlineeditor,midi_editor] .
-- @version 1.0.3
-- @changelog Improve display and shortcut management
-- @provides [main=main,midi_editor,midi_inlineeditor] .
-- @link Forum thread https://forum.cockos.com/showthread.php?t=281810
-- @screenshot https://i.imgur.com/IdK4mL1.gif
-- @screenshot https://i.imgur.com/SPKgPo1.gif
-- @donation https://reapack.com/donate
-- @about
-- # Clamp velocity of selected MIDI notes
Expand Down Expand Up @@ -51,6 +51,7 @@ end

local presets = loadPresets()
local takes, in_me, selected_notes, pscc = {}, false
local had_any_item_active = false

local function forEachNote(callback)
for take_i, take in ipairs(takes) do
Expand Down Expand Up @@ -133,6 +134,20 @@ local function tooltip(text)
end
end

local function shortcuts(...)
if had_any_item_active then
return false
end

for i = 1, select('#', ...) do
if ImGui.IsKeyPressed(ctx, select(i, ...), false) then
return true
end
end

return false
end

local function presetsCombo()
if #presets < 1 then
return ImGui.TextDisabled(ctx, 'No saved recent ranges')
Expand Down Expand Up @@ -162,26 +177,22 @@ end

local function window()
ImGui.SetNextItemWidth(ctx, 255)
vel_min, vel_max = select(2, ImGui.DragInt2(ctx, 'Velocity range', vel_min, vel_max,
nil, 0, 0x7f, nil, ImGui.SliderFlags_AlwaysClamp()))
if ImGui.IsItemDeactivatedAfterEdit(ctx) then
vel_min, vel_max = math.min(vel_min, vel_max), math.max(vel_min, vel_max)
end
vel_min, vel_max = select(2, ImGui.DragIntRange2(ctx, 'Value range', vel_min, vel_max,
nil, 0, 0x7f, 'Min: %d', 'Max: %d', ImGui.SliderFlags_AlwaysClamp()))
ImGui.SameLine(ctx)
if ImGui.BeginCombo(ctx, '##preset', '', ImGui.ComboFlags_NoPreview()) then
presetsCombo()
ImGui.EndCombo(ctx)
end
tooltip('Recent values')

ImGui.Text(ctx, 'Double-click to enter a specific value')
ImGui.Text(ctx, 'Drag or double-click to enter a specific value')
ImGui.Spacing(ctx)

ImGui.PushStyleVar(ctx, ImGui.StyleVar_ItemSpacing(), 5, 0)
local keep_open = true
if ImGui.Button(ctx, 'OK') or
ImGui.IsKeyPressed(ctx, ImGui.Key_Enter()) or
ImGui.IsKeyPressed(ctx, ImGui.Key_KeypadEnter()) then
shortcuts(ImGui.Key_Enter(), ImGui.Key_KeypadEnter()) then
apply()
keep_open = false
end
Expand All @@ -190,8 +201,7 @@ local function window()
apply()
end
ImGui.SameLine(ctx)
if ImGui.Button(ctx, 'Cancel') or
ImGui.IsKeyPressed(ctx, ImGui.Key_Escape()) then
if ImGui.Button(ctx, 'Cancel') or shortcuts(ImGui.Key_Escape()) then
keep_open = false
end
ImGui.SameLine(ctx)
Expand All @@ -211,6 +221,8 @@ local function loop()
end
ImGui.PopFont(ctx)

had_any_item_active = ImGui.IsAnyItemActive(ctx)

if open then
reaper.defer(loop)
end
Expand Down

0 comments on commit 80a6033

Please sign in to comment.