Skip to content

Commit

Permalink
Update One Small Step v0.9.8 > 0.9.9 (#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan authored Mar 14, 2024
1 parent 0819830 commit 7114ce9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
9 changes: 6 additions & 3 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.8
@version 0.9.9
@author Ben 'Talagan' Babut
@license MIT
@metapackage
Expand Down Expand Up @@ -54,7 +54,10 @@
@screenshot
https://stash.reaper.fm/48269/oss_094.png
@changelog
- [Bug Fix] Enhancing behaviour of the repitch mode when Reaper's "Autocorrect overlapping notes" is checked (thanks @smandrap !)
- [Rework] Changed toolbar icon color
- [Bug Fix] [Repitch Mode] Patched MIDIUtils API : successive snapped notes would be borked by the automatic overlap correction option (thanks @smandrap)
- [Bug Fix] [Write Mode] CommitBack action would be blocked by sustain pedal blocker if called from action (thanks @hipox !)
- [Bug Fix] [Write Mode] Sustain Pedal blocking system when (stepping back + miss) was broken
@about
# Purpose
Expand Down Expand Up @@ -84,7 +87,7 @@
--]]

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

--------------------------------
Expand Down
52 changes: 31 additions & 21 deletions MIDI Editor/talagan_OneSmallStep/classes/engine_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ function clearAllActionTriggers()
end
end

local function hasActionTrigger(forward)
local res = false
for k,v in pairs(ActionTriggers) do
local cond = false
if forward then
cond = not v.back
else
cond = v.back
end
if cond then
res = (res or getActionTrigger(k))
end
end
return res
end
local function hasForwardActionTrigger()
return hasActionTrigger(true)
end
local function hasBackwardActionTrigger()
return hasActionTrigger(false)
end

------------

Expand Down Expand Up @@ -1894,15 +1915,19 @@ local function commitBack(track, take, notes_to_shorten, triggered_by_key_event)
reaper.UpdateItemInProject(mediaItem)
reaper.MarkTrackItemsDirty(track, mediaItem)

local blockRewind = false
local blockRewind = false
local triggeredByBackAction = hasBackwardActionTrigger()
local pedalStart = currentKeyEventManager():keyActivityForTrack(track).pedal.first_ts

if writeModeON then
if writeModeON and (not triggeredByBackAction) then
-- We block the rewind in certain conditions (when erasing failed, and when during this pedal session, the erasing was blocked)
local pedalStart = currentKeyEventManager():keyActivityForTrack(track).pedal.first_ts
local hadCandidates = (#notes_to_shorten > 0)
local failedToErase = (hadCandidates and (shcount+remcount == 0))

blockRewind = (getSetting("DoNotRewindOnStepBackIfNothingErased") and failedToErase) or ((not hadCandidates) and (pedalStart == blockRewindRef))
local cond1 = getSetting("DoNotRewindOnStepBackIfNothingErased") and failedToErase
local cond2 = (not hadCandidates) and (pedalStart == blockRewindRef)

blockRewind = cond1 or cond2
end

if blockRewind then
Expand All @@ -1919,21 +1944,6 @@ local function commitBack(track, take, notes_to_shorten, triggered_by_key_event)
reaper.Undo_EndBlock(commitDescription(-1, addcount, remcount, shcount, extcount, mvcount),-1);
end

local function hasTrigger(forward)
local res = false
for k,v in pairs(ActionTriggers) do
local cond = false
if forward then
cond = not v.back
else
cond = v.back
end
if cond then
res = (res or getActionTrigger(k))
end
end
return res
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 @@ -2010,14 +2020,14 @@ local function listenToEvents()
);

-- Allow the use of the action or pedal
if (pedal and not spmod) or hasTrigger(true) then
if (pedal and not spmod) or hasForwardActionTrigger() then
manager:simpleCommit(track, function(commit_candidates, held_candidates)
commit(track, take, commit_candidates, held_candidates, false);
end
);
end

if (pedal and spmod) or hasTrigger(false) then
if (pedal and spmod) or hasBackwardActionTrigger() then
manager:simpleCommitBack(track, function(shorten_candidates)
commitBack(track, take, shorten_candidates, false)
end
Expand Down
7 changes: 6 additions & 1 deletion MIDI Editor/talagan_OneSmallStep/classes/lib/MIDIUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,13 @@ local function MIDI_CommitWriteTransaction(take, refresh, dirty)
end
local newMIDIString = ''
local lastPPQPos = 0

local comparator = function(t, a, b)
return ( (t[a].ppqpos == t[b].ppqpos) and (t[a]:type() == NOTEOFF_TYPE) ) or (t[a].ppqpos < t[b].ppqpos)
end

-- iterate sorted to avoid (REAPER Inline MIDI Editor) problems with offset calculation
for _, event in spairs(MIDIEvents, function(t, a, b) return t[a].ppqpos < t[b].ppqpos end) do
for _, event in spairs(MIDIEvents, comparator) do
event.offset = math.floor(event.ppqpos - lastPPQPos)
lastPPQPos = event.ppqpos
local MIDIStr = event:GetMIDIString()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7114ce9

Please sign in to comment.