Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions Envelopes/graysonsolis_Toggle ReaPitch shift (cents) envelope.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-- @description Toggle ReaPitch shift (cents) envelope
-- @author Grayson Solis
-- @version 1.0
-- @about
-- Toggles Shift (cents) envelope lane for ReaPitch on selected track. Adds ReaPitch if missing. Similar to the "volume" or "pan" default track envelopes.
-- The parameter used can be toggled by editing the lines below!

reaper.PreventUIRefresh(1)
reaper.Undo_BeginBlock()

local track = reaper.GetSelectedTrack(0, 0)
if not track then
reaper.PreventUIRefresh(0)

@cfillion cfillion Jul 8, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, while this line here (and same a bit below) is correctly undoing the PreventUIRefresh from above, it forgets to the the same for Undo_BeginBlock.

An easy solution would be to wait until later before enabling PreventUIRefresh and Undo_BeginBlock. 😉

Thankfully REAPER has a fail-safe against scripts doing this kind of mistake so there are no ill effects.

@Buy-One Buy-One Jul 8, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schwa suggests here https://forum.cockos.com/showpost.php?p=2297817&postcount=2

You should always call PreventUIRefresh(1) to initiate and PreventUIRefresh(-1) to end

Is 0 a valid argument as well?

@cfillion cfillion Jul 8, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, nope it is not. (Well, not "invalid" per se, but adding 0 just does nothing.)

return
end

local before = reaper.TrackFX_GetCount(track)

local fx_idx = reaper.TrackFX_AddByName(track, "ReaPitch (Cockos)", false, 0)
if fx_idx < 0 then
fx_idx = reaper.TrackFX_AddByName(track, "ReaPitch (Cockos)", false, 1)
end
if fx_idx < 0 then
reaper.ShowMessageBox("Could not add/find ReaPitch.", "Error", 0)
reaper.PreventUIRefresh(0)
return
end

reaper.TrackFX_Show(track, fx_idx, 2)

local added = (reaper.TrackFX_GetCount(track) > before)

--[[

CUSTOMIZATION TIP
To select a different ReaPitch parameter envelope, change the value
of the `param` variable below to one of the following:

0: Wet
1: Dry
2: Enabled
3: Shift (full range)
4: Shift (cents) <-- current default
5: Shift (semitones)
6: Shift (oct)
7: Formant adjust (full range)
8: Formant adjust (cents)
9: Formant adjust (semitones)
10: Volume
11: Pan
12: Bypass
13: Wet
14: Delta

For example, to toggle the envelope for "Shift (semitones)", set:

local param = 5

--]]

local param = 3 -- Shift (cents) YOU CAN CHANGE THIS!!!!

local env = reaper.GetFXEnvelope(track, fx_idx, param, true)
if not env then
reaper.ShowMessageBox("Failed to access envelope.", "Error", 0)
reaper.PreventUIRefresh(0)
return
end

local ok, chunk = reaper.GetEnvelopeStateChunk(env, "", false)
if not ok then
reaper.ShowMessageBox("Failed to read envelope.", "Error", 0)
reaper.PreventUIRefresh(0)
return
end


local show
if added then
show = true
else
local v1,v2,v3 = chunk:match("VIS (%d+) (%d+) (%d+)")
show = not (v1 == "1" and v2 == "1" and v3 == "1")
end

chunk = chunk
:gsub("ACT %d+", "ACT " .. (show and 1 or 0))
:gsub("VIS %d+ %d+ %d+", "VIS " .. (show and "1 1 1" or "0 0 0"))
:gsub("ARM %d+", "ARM " .. (show and 1 or 0))
:gsub("DEFSHAPE %d+", "DEFSHAPE 0")

reaper.SetEnvelopeStateChunk(env, chunk, false)
reaper.TrackList_AdjustWindows(false)
reaper.UpdateArrange()
reaper.Undo_EndBlock("Toggle ReaPitch shift (cents) envelope (default height)", 0)
reaper.PreventUIRefresh(0)