Skip to content

Commit

Permalink
Update One Small Step V0.9.7 > V0.9.8 (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan authored Mar 14, 2024
1 parent d4dc80b commit a0569bf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 18 deletions.
15 changes: 5 additions & 10 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.7
@version 0.9.8
@author Ben 'Talagan' Babut
@license MIT
@metapackage
Expand Down Expand Up @@ -54,12 +54,7 @@
@screenshot
https://stash.reaper.fm/48269/oss_094.png
@changelog
- [Feature] Added repitch (+revel) mode (thanks @smandrap !)
- [Fix] Added missing "Change Edit Mode" actions
- [Doc] Added help button that redirects to current documentation
- [Rework] Re arranged settings panel
- [Rework] Reworked some icons and colors
- [Rework] Started to use MIDI Utils API by sockmonkey72 instead of default MIDI API
- [Bug Fix] Enhancing behaviour of the repitch mode when Reaper's "Autocorrect overlapping notes" is checked (thanks @smandrap !)
@about
# Purpose
Expand Down Expand Up @@ -89,7 +84,7 @@
--]]

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

--------------------------------
Expand Down Expand Up @@ -176,8 +171,8 @@ end
-------------------------------
-- Other global variables

local focustimer = nil;
local showsettings = nil;
local focustimer = nil
local showsettings = nil

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

Expand Down
64 changes: 56 additions & 8 deletions MIDI Editor/talagan_OneSmallStep/classes/engine_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,19 @@ local function GetNote(take, ni, use_mu)
};
end

local CrossApi = {}

CrossApi.GetNote = GetNote

CrossApi.MIDI_CountEvts = function(take, use_mu)
if use_mu then
return midi_utils.MIDI_CountEvts(take)
else
return reaper.MIDI_CountEvts(take)
end
end


local function SetNote(take, n, nosort)
reaper.MIDI_SetNote(take, n.index, n.selected, n.muted, n.startPPQ, n.endPPQ, n.chan, n.pitch, n.vel, nosort)
end
Expand Down Expand Up @@ -1183,6 +1196,20 @@ local function AllowKeyEventNavigation()
return getSetting("AllowKeyEventNavigation")
end

local autoOverlap = nil
local function PushAutoCorrectOverlapOption()
autoOverlap = reaper.GetToggleCommandStateEx(32060, 40681)
if autoOverlap == 1 then
reaper.MIDIEditor_LastFocused_OnCommand(40681, false) -- toggle off
end
end

local function PopAutoCorrectOverlapOption()
if autoOverlap == 1 then
reaper.MIDIEditor_LastFocused_OnCommand(40681, false) -- toggle back on
end
end

local function repitch(track, take, notes_to_add, notes_to_extend, triggered_by_key_event)

local shcount, remcount, mvcount, addcount, extcount = 0, 0, 0, 0, 0
Expand All @@ -1209,19 +1236,24 @@ local function repitch(track, take, notes_to_add, notes_to_extend, triggered_by_
local itemLength = reaper.GetMediaItemInfo_Value(mediaItem, "D_LENGTH")
local itemEndTime = itemStartTime + itemLength;

local _, notecnt, _, _ = midi_utils.MIDI_CountEvts(take)
local ni = 0
local useMidiUtils = true

midi_utils.MIDI_InitializeTake(take)
local _, notecnt, _, _ = CrossApi.MIDI_CountEvts(take, useMidiUtils)


if useMidiUtils then
midi_utils.MIDI_InitializeTake(take)
end

for _, v in pairs(notes_to_extend) do
notes_to_add[#notes_to_add+1] = v
end

local tomod = {}

local ni = 0
while (ni < notecnt) do
local n = GetNote(take, ni, true)
local n = GetNote(take, ni, useMidiUtils)

if noteStartsInWindowPPQ(n, cursorPPQ, aggregationPPQ, false) then
tomod[#tomod + 1] = n
Expand All @@ -1248,7 +1280,11 @@ local function repitch(track, take, notes_to_add, notes_to_extend, triggered_by_
return n1.note < n2.note
end)

midi_utils.MIDI_OpenWriteTransaction(take)
if useMidiUtils then
PushAutoCorrectOverlapOption()
midi_utils.MIDI_OpenWriteTransaction(take)
end

for k, n in ipairs(tomod) do
local newvel = nil
local newpitch = nil
Expand All @@ -1259,18 +1295,30 @@ local function repitch(track, take, notes_to_add, notes_to_extend, triggered_by_
newpitch = notes_to_add[k].note
end

midi_utils.MIDI_SetNote(take, n.index, nil, nil, nil, nil, nil, newpitch, newvel, nil)
if useMidiUtils then
midi_utils.MIDI_SetNote(take, n.index, nil, nil, nil, nil, nil, newpitch, newvel, nil)
else
reaper.MIDI_SetNote(take, n.index, nil, nil, nil, nil, nil, newpitch, newvel, false)
end

if n.startPPQ > cursorPPQ then
cursorPPQ = n.startPPQ
end
end
midi_utils.MIDI_CommitWriteTransaction(take)

if useMidiUtils then
midi_utils.MIDI_CommitWriteTransaction(take)
PopAutoCorrectOverlapOption()
end

cursorTime = reaper.MIDI_GetProjTimeFromPPQPos(take, cursorPPQ)
end
end

reaper.MIDI_Sort(take)
if not useMidiUtils then
reaper.MIDI_Sort(take)
end

reaper.UpdateItemInProject(mediaItem)
reaper.MarkTrackItemsDirty(track, mediaItem)
end
Expand Down

0 comments on commit a0569bf

Please sign in to comment.