Skip to content

Commit

Permalink
Update OneSmallStep v0.9.10 > v0.9.11 (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan authored Apr 6, 2024
1 parent 99a6625 commit c8d801c
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 38 deletions.
116 changes: 90 additions & 26 deletions MIDI Editor/talagan_OneSmallStep.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[
@description One Small Step : Alternative Step Input
@version 0.9.10
@version 0.9.11
@author Ben 'Talagan' Babut
@license MIT
@metapackage
Expand Down Expand Up @@ -56,12 +56,7 @@
@screenshot
https://stash.reaper.fm/48269/oss_094.png
@changelog
- [Feature] Compress/Stretch Submode
- [Feature] Stuff Submode
- [Enhance] Force item bound snapping if item grid snap is on
- [Rework] PPQ Precise operations
- [Rework] New code architecture and file hierarchy, big code rework
- [Rework] Addind debugging support for Visual Studio Code (using mavriq lua sockets, thanks @mavriq)
- [Feature] Velocity limiter
@about
# Purpose
Expand Down Expand Up @@ -91,7 +86,7 @@
--]]

VERSION = "0.9.10"
VERSION = "0.9.11"
DOC_URL = "https://bentalagan.github.io/onesmallstep-doc/index.html?ver=" .. VERSION

PATH = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]]
Expand Down Expand Up @@ -850,7 +845,6 @@ function EditModeMiniBar()
SL()
end
end

end

function PlaybackWidget()
Expand All @@ -877,14 +871,19 @@ function SliderReset(setting)
reaper.ImGui_PopStyleVar(ctx);
end

function SettingSlider(setting, in_label, out_label, tooltip, use_help_interrogation_for_tooltip, width)
function SettingSlider(setting, in_label, out_label, tooltip, use_help_interrogation_for_tooltip, options)

options = options or {};

local width = options.width
local spec = S.getSettingSpec(setting)
local min = options.min or spec.min
local max = options.max or spec.max

if width then
reaper.ImGui_SetNextItemWidth(ctx, width)
end

local spec = S.getSettingSpec(setting)

local slider_func = nil
if spec.type == 'int' then
slider_func = reaper.ImGui_SliderInt
Expand All @@ -894,7 +893,7 @@ function SettingSlider(setting, in_label, out_label, tooltip, use_help_interroga
error("Contact developer, forgot to handle type " .. spec.type)
end

local change, v1 = slider_func(ctx, "##slider_" .. setting , S.getSetting(setting), spec.min, spec.max, in_label, reaper.ImGui_SliderFlags_NoInput())
local change, v1 = slider_func(ctx, "##slider_" .. setting , S.getSetting(setting), min, max, in_label, reaper.ImGui_SliderFlags_NoInput())
if change then
S.setSetting(setting, v1);
end
Expand All @@ -905,17 +904,51 @@ function SettingSlider(setting, in_label, out_label, tooltip, use_help_interroga

SL();
SliderReset(setting)
if out_label then
SL();
reaper.ImGui_Text(ctx, out_label);

if out_label and out_label ~= "" then
SL()
reaper.ImGui_Text(ctx, out_label)
end

if use_help_interrogation_for_tooltip and tooltip then
SL()
reaper.ImGui_TextColored(ctx, 0xB0B0B0FF, "(?)");
TT(tooltip)
end
end

function SettingComboBox(setting, pre_label, tooltip, width)

local combo_items = S.getSettingSpec(setting).inclusion
local curval = S.getSetting(setting)

reaper.ImGui_PushStyleVar(ctx, reaper.ImGui_StyleVar_FramePadding(), 5, 3.5)

if pre_label ~= "" then
reaper.ImGui_Text(ctx, pre_label);
SL()
end

reaper.ImGui_SetNextItemWidth(ctx, width);
reaper.ImGui_PushID(ctx, setting .. "_combo")
if reaper.ImGui_BeginCombo(ctx, '', curval) then
for i,v in ipairs(combo_items) do
local is_selected = (curval == v);
if reaper.ImGui_Selectable(ctx, combo_items[i], is_selected) then
S.setSetting(setting, v);
end
if is_selected then
reaper.ImGui_SetItemDefaultFocus(ctx)
end
end
reaper.ImGui_EndCombo(ctx)
end
reaper.ImGui_PopID(ctx);
reaper.ImGui_PopStyleVar(ctx,1);

TT(tooltip)
end

function TargetModeInfo()
local currentop = ED.ResolveOperationMode()

Expand All @@ -934,13 +967,13 @@ function TargetModeInfo()
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_compress"),20,20); _TT("Compress notes between marker and edit cursor", true, "Insert"); SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_stretch"),20,20); ; _TT("Stretch notes between marker and edit cursor", true, "Insert") SL();
reaper.ImGui_Image(ctx, getImage("indicator_stretch"),20,20); _TT("Stretch notes between marker and edit cursor", true, "Insert"); SL();
end
else
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_insert_back"),20,20); _TT("Insert back (delete and shift)", false, "Compress"); SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_insert_forward"),20,20); ; _TT("Insert (add notes and shift)", false, "Stretch") SL();
reaper.ImGui_Image(ctx, getImage("indicator_insert_forward"),20,20); ; _TT("Insert (add notes and shift)", false, "Stretch"); SL();
end
end
elseif currentop.mode == "Replace" then
Expand Down Expand Up @@ -1245,7 +1278,7 @@ function SettingsPanel()
"%.3f seconds",
"Chord Aggregation",
"Key press events happening within this time\nwindow are aggregated as a chord",
true, nil)
true)

SettingSlider("KeyPressModeInertiaTime",
"%.3f seconds",
Expand All @@ -1254,7 +1287,7 @@ function SettingsPanel()
key A was still held for more than this time,\n\z
then A is considered sustained and not released.\n\n\z
This setting allows to enter new notes overlapping sustained notes.",
true, nil)
true)
SL()
local curval = S.getSetting("KeyPressModeInertiaEnabled");
if reaper.ImGui_Checkbox(ctx, "Enabled##kp_inertia", curval) then
Expand All @@ -1271,7 +1304,7 @@ function SettingsPanel()
if other keys are still pressed.\n\n\z
This is used to know if a note should be forgotten/trashed\n\z
or used as part of the input chord.",
true, nil)
true)

ImGui_VerticalSpacer(ctx,5);
SEP("Sustain Pedal")
Expand All @@ -1280,11 +1313,42 @@ function SettingsPanel()
if reaper.ImGui_Checkbox(ctx, "Pedal repeat every", curval) then
S.setSetting("PedalRepeatEnabled", not curval);
end
SL();
SettingSlider("PedalRepeatTime", "%.3f seconds", "and", "Repeat time for the pedal event when pressed", false, 120)
SL();
SettingSlider("PedalRepeatFirstHitMultiplier", "x %.d", "on first hit", "Multiplication factor for first hit", false, 50)
SL()
SettingSlider("PedalRepeatTime",
"%.3f seconds", "and", "Repeat time for the pedal event when pressed",
false,
{ width = 120 } )
SL()
SettingSlider("PedalRepeatFirstHitMultiplier",
"x %.d",
"on first hit",
"Multiplication factor for first hit",
false,
{ width = 50 } )

ImGui_VerticalSpacer(ctx,5);
SEP("Velocity")

curval = S.getSetting("VelocityLimiterEnabled");
if reaper.ImGui_Checkbox(ctx, "Limit velocity between", curval) then
S.setSetting("VelocityLimiterEnabled", not curval);
end
SL()
SettingSlider("VelocityLimiterMin",
"%d",
"and",
"Minimum value",
false,
{ width = 127, min = S.getSettingSpec("VelocityLimiterMin").min, max = S.getSetting("VelocityLimiterMax") } )
SL()
SettingSlider("VelocityLimiterMax",
"%d",
"",
"Maximum value",
false,
{ width = 127, min = S.getSetting("VelocityLimiterMin"), max = S.getSettingSpec("VelocityLimiterMax").max } )
SL()
SettingComboBox("VelocityLimiterMode", "mode", "Velocity limiting label", 100)

reaper.ImGui_EndTabItem(ctx)
end
Expand Down Expand Up @@ -1346,7 +1410,7 @@ function SettingsPanel()
"%.3f seconds",
"Repitch chord aggregation",
"Notes that fit in that time window are aggregated as a chord",
true, nil)
true)

reaper.ImGui_EndTabItem(ctx)
end
Expand Down
58 changes: 47 additions & 11 deletions MIDI Editor/talagan_OneSmallStep/classes/engine_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ local KeyActivityManager = require "input_managers/KeyActivityManager"
local KeyReleaseActivityManager = require "input_managers/KeyReleaseActivityManager"
local KeyPressActivityManager = require "input_managers/KeyPressActivityManager"

local S = require "modules/settings"
local D = require "modules/defines"
local AT = require "modules/action_triggers"
local MK = require "modules/markers"
local T = require "modules/time"
local SNP = require "modules/snap"
local N = require "modules/notes"
local TGT = require "modules/target"
local F = require "modules/focus"
local MOD = require "modules/modifiers"
local ED = require "modules/edition"
local S = require "modules/settings"
local D = require "modules/defines"
local AT = require "modules/action_triggers"
local MK = require "modules/markers"
local T = require "modules/time"
local SNP = require "modules/snap"
local N = require "modules/notes"
local TGT = require "modules/target"
local F = require "modules/focus"
local MOD = require "modules/modifiers"
local ED = require "modules/edition"

local NAVIGATE = require "operations/navigate"
local REPITCH = require "operations/repitch"
Expand Down Expand Up @@ -181,6 +181,30 @@ local function commitBack(track, take, notes_to_shorten, triggered_by_key_event)
end
end

local function normalizeVelocities(notes_from_manager)
if not S.getSetting("VelocityLimiterEnabled") then
return
end

local min = S.getSetting("VelocityLimiterMin")
local max = S.getSetting("VelocityLimiterMax")
local mode = S.getSetting("VelocityLimiterMode")

if min > max then
min, max = max, min
end

for i=1, #notes_from_manager do
local n = notes_from_manager[i]
if mode == "Clamp" then
n.vel = (n.vel < min) and (min) or (n.vel)
n.vel = (n.vel > max) and (max) or (n.vel)
elseif mode == "Linear" then
n.vel = min + (n.vel/127.0) * (max - min)
n.vel = math.floor(n.vel + 0.5) -- This not be an integer, so round
end
end
end

-- Listen to events from instrumented tracks that have the JSFX companion effect installed (or install it if not present)
local function listenToEvents()
Expand Down Expand Up @@ -240,6 +264,10 @@ local function listenToEvents()

manager:tryAdvancedCommitForTrack(track,
function(candidates, held_candidates)

normalizeVelocities(candidates)
normalizeVelocities(held_candidates)

-- The advanced commit is dedicated to key event(s) triggerering
if not spmod then
-- Advance
Expand All @@ -258,13 +286,19 @@ local function listenToEvents()
-- Allow the use of the action or pedal
if (pedal and not spmod) or AT.hasForwardActionTrigger() then
manager:simpleCommit(track, function(commit_candidates, held_candidates)
normalizeVelocities(commit_candidates)
normalizeVelocities(held_candidates)

commit(track, take, commit_candidates, held_candidates, false);
end
);
end

-- Back action pedal
if (pedal and spmod) or AT.hasBackwardActionTrigger() then
manager:simpleCommitBack(track, function(shorten_candidates)
normalizeVelocities(shorten_candidates)

commitBack(track, take, shorten_candidates, false)
end
);
Expand Down Expand Up @@ -361,6 +395,8 @@ return {
F = F,
MOD = MOD,
ED = ED,
SNP = SNP,
N = N,

atStart = atStart,
atExit = atExit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ local SettingDefs = {

AllowKeyEventNavigation = { type = "bool", default = false },

UseDebugger = { type = "bool", default = false }
UseDebugger = { type = "bool", default = false },

VelocityLimiterEnabled = { type = "bool", default = false },
VelocityLimiterMin = { type = "int", default = 0, min = 0, max = 127 },
VelocityLimiterMax = { type = "int", default = 127, min = 0, max = 127 },
VelocityLimiterMode = { type = "string", default = "Linear", inclusion = { "Linear", "Clamp"} }
};


Expand Down

0 comments on commit c8d801c

Please sign in to comment.