|
|
|
06-20-2017, 05:18 PM
|
#1
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
How to get and set coordinates of a floating fx?
Hello!
How can I get the coordinates of a floating fx window? And how can I set them? (so that I place the floating fx somewhere else on screen - preferably centered on the screen)
Thanks!
|
|
|
06-20-2017, 05:42 PM
|
#2
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,968
|
GetTrackStateChunk, some string parsing and manipulation then SetTrackStateChunk.
Quick and dirty example:
Code:
local PATTERN = 'FLOAT' .. (' (%d+)'):rep(4)
local t = reaper.GetTrack(0, 0)
local ok, chunk = reaper.GetTrackStateChunk(t, '')
if not ok then return end
local x, y, w, h = chunk:match(PATTERN)
reaper.ShowConsoleMsg(string.format("was: position = %dx%d, size = %dx%d\n", x, y, w, h))
chunk = chunk:gsub(PATTERN, 'FLOAT 10, 10, 300, 300')
reaper.SetTrackStateChunk(t, chunk)
Last edited by cfillion; 06-21-2017 at 12:24 AM.
|
|
|
06-21-2017, 12:09 AM
|
#3
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Thank you so much cfillion!!
It works perfect!
Last edited by amagalma; 06-21-2017 at 07:47 AM.
|
|
|
06-21-2017, 07:29 AM
|
#4
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
And another question..
Is there any way to know if an FX belonging to a track is floating (focused or not), by other means than getting the track's chunk?
Edit.. Found it!
Last edited by amagalma; 06-21-2017 at 10:15 AM.
|
|
|
06-21-2017, 10:16 AM
|
#5
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Here is my code:
Code:
function NoUndoPoint() end
local reaper = reaper
function Main()
local track = reaper.GetSelectedTrack(0, 0)
local fxcount = reaper.TrackFX_GetCount(track)
if fxcount == 0 then
reaper.Main_OnCommand(40291,0) -- add FX
reaper.TrackFX_Show(track, 0, 0) -- Hide FX Chain
else
local t = {}
local nextfx = 0
for i = 0, fxcount-1 do -- Find the first open FX, if any
local open = reaper.TrackFX_GetOpen(track, i)
if open then t[#t+1] = i end
end
if #t ~= 0 then nextfx = t[1]+1 end
if nextfx == fxcount then nextfx = 0 end
reaper.TrackFX_Show(track, nextfx, 3) -- Show "next" FX
for i,v in ipairs(t) do -- Close other open FX
if tonumber(v) ~= tonumber(nextfx) then reaper.TrackFX_Show(track, v, 2) end
end
reaper.TrackFX_Show(track, 0, 0) -- Hide FX Chain
local PATTERN = "FLOAT" .. (" (%d+)"):rep(4)
local ok, chunk = reaper.GetTrackStateChunk(track, "")
if not ok then return end
local plx, ply, plw, plh = chunk:match(PATTERN) -- Get FX window position & size
local _, _, scrw, scrh = reaper.my_getViewport(0, 0, plw, plh, 0, 0, plw, plh, 1) -- Get screen size
local x, y = math.floor((scrw - plw)/2), math.floor((scrh - plh)/2) -- Centered FX on screen coordinates
if tonumber(plx) ~= x and tonumber(ply) ~= y then -- Center FX if not centered
local chunk = chunk:gsub(PATTERN, "FLOAT "..x..", "..y..", "..plw..", "..plh)
reaper.SetTrackStateChunk(track, chunk)
end
end
reaper.UpdateArrange()
end
reaper.PreventUIRefresh(1)
Main()
reaper.PreventUIRefresh(-1)
reaper.defer(NoUndoPoint)
Why an undo point is created? What should I do to avoid it?
I went into the trouble of making this action in order to avoid the undo point created with the SWS action "Float next FX (and close others) for selected tracks", and no luck..
Last edited by amagalma; 06-21-2017 at 10:33 AM.
|
|
|
06-21-2017, 10:53 AM
|
#6
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by amagalma
Why an undo point is created? What should I do to avoid it?
|
Hi, I did not really go into it, but it's probably because of
Code:
reaper.Main_OnCommand(40291,0) -- add FX
|
|
|
06-21-2017, 11:08 AM
|
#7
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
|
Yes, as me2beats said, creating undo point seems unavoidable currently when using native actions.
http://forum.cockos.com/showthread.php?t=192670
|
|
|
06-21-2017, 11:16 AM
|
#8
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
I want an undo point to be added if I add an FX.. There is no problem with that part. The problem is when cycling between existing FX.
The action that creates the problem is reaper.TrackFX_Show(track, v, 2)
Just try the code and see
|
|
|
06-21-2017, 11:28 AM
|
#9
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by amagalma
I want an undo point to be added if I add an FX.. There is no problem with that part. The problem is when cycling between existing FX.
The action that creates the problem is reaper.TrackFX_Show(track, v, 2)
Just try the code and see
|
try this:
Code:
local r = reaper
local tr = r.GetSelectedTrack(0,0)
r.Undo_BeginBlock()
r.TrackFX_Show(tr, 0, 2) -- hide 1st fx
r.Undo_EndBlock('script name', 1)
Undo point is not created here, so I think the problem isn't in TrackFX_Show()
|
|
|
06-21-2017, 12:31 PM
|
#10
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
It is created as it should.. 'script name'
If I do this:
Code:
function Main()
reaper.Undo_BeginBlock()
local track = reaper.GetSelectedTrack(0, 0)
local fxcount = reaper.TrackFX_GetCount(track)
if fxcount == 0 then
reaper.Main_OnCommand(40291,0) -- add FX
reaper.TrackFX_Show(track, 0, 0) -- Hide FX Chain
else
local t = {}
local nextfx = 0
for i = 0, fxcount-1 do -- Find the first open FX, if any
local open = reaper.TrackFX_GetOpen(track, i)
if open then t[#t+1] = i end
end
if #t ~= 0 then nextfx = t[1]+1 end
if nextfx == fxcount then nextfx = 0 end
reaper.TrackFX_Show(track, nextfx, 3) -- Show "next" FX
for i,v in ipairs(t) do -- Close other open FX
if tonumber(v) ~= tonumber(nextfx) then reaper.TrackFX_Show(track, v, 2) end
end
reaper.TrackFX_Show(track, 0, 0) -- Hide FX Chain
local PATTERN = "FLOAT" .. (" (%d+)"):rep(4)
local ok, chunk = reaper.GetTrackStateChunk(track, "")
if not ok then return end
local plx, ply, plw, plh = chunk:match(PATTERN) -- Get FX window position & size
local _, _, scrw, scrh = reaper.my_getViewport(0, 0, plw, plh, 0, 0, plw, plh, 1) -- Get screen size
local x, y = math.floor((scrw - plw)/2), math.floor((scrh - plh)/2) -- Centered FX on screen coordinates
if tonumber(plx) ~= x and tonumber(ply) ~= y then -- Center FX if not centered
local chunk = chunk:gsub(PATTERN, "FLOAT "..x..", "..y..", "..plw..", "..plh)
reaper.SetTrackStateChunk(track, chunk)
end
end
reaper.UpdateArrange()
reaper.Undo_EndBlock("next fx", 1)
end
reaper.PreventUIRefresh(1)
Main()
reaper.PreventUIRefresh(-1)
then an undo point is created as expected.. But I do not want to do that.. I want no undo point at all when cycling between FX
|
|
|
06-21-2017, 01:05 PM
|
#11
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by amagalma
It is created as it should.. 'script name'
|
http://imgur.com/a/vkmak
|
|
|
06-21-2017, 01:33 PM
|
#12
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Thanks for getting into the trouble!
You have only one FX loaded in the chain.. Try with more and see
|
|
|
06-21-2017, 02:27 PM
|
#13
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by amagalma
Thanks for getting into the trouble!
You have only one FX loaded in the chain.. Try with more and see
|
Code:
reaper.TrackFX_Show(track, 0, 2)
if you cooment it the script will not create undo points.
there are several API functions with same issue (they clutter Undo history)
for example CSurf_OnPlayRateChange() and TrackFX_SetParam().
As far as I know, there is no alternative - it's impossible to close FX even via track chunk
|
|
|
06-21-2017, 04:42 PM
|
#14
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Yes...
I tried to do it with track chunk, but it was not possible. Setting SHOW 0 and FLOAT to FLOATPOS in the chunk, didn't do anything..
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:37 AM.
|