ReaLive-ProjectTabsList/Realive_ProjectTabsList_SaveAllTabs.lua

184 lines
4.8 KiB
Lua

--------------------------------------
----------// HEADER //----------------
--------------------------------------
--[[
* REALIVE: Reaper Setup for a Complete Live Playback Engine
* ReaScript Name: Realive_ProjectTabsList_Compare.lua
* Description: Project Tabs List Compare with last Saved One
* Instructions:
* Author: Alex Paquette, Thanks to Claude Fillion for the Large contribution
* Repository:
* Repository URI:
* File URI:
* Licence: GPL v3
* Forum Thread:
* Forum Thread URI: https://forum.cockos.com/showthread.php?p=1854775#post1854775
* REAPER: 5
* Extensions: SWS/S&M
* Version: 2.00
--]]
--[[
* Changelog:
* v1.0 (2019-06-02)
+ Initial Release
--]]
--------------------------------------
----------// VARIABLES //-------------
--------------------------------------
local reaper = reaper -------// Performance Enhancement //----------
-----// Window Set Numbers //------------------------------
local PlayViewWindowSet = 01 -- Enter Window Set Number Used for the "Live Play" View
local AllTracksViewWindowSet = 02 -- Enter the Window Set Number for the "Show All Tracks" View
local WindowSetBaseNumber = 40453
local PlayView_cmdID = WindowSetBaseNumber+PlayViewWindowSet
local AllView_cmdID = WindowSetBaseNumber+AllTracksViewWindowSet
local EXT_SECTION_PLAYLIST = 'ProjectTabs_Realive_list'
-----// Other Variables //------------------------------
-----// gmem Variables //------------------------------
local gmemSect = 'Realive_Gmem'
local gmem_idx_PlaylistState = 11
local gmem_idx_Management = 12
local gmem_idx_PlaylistState_Clean = 32
local gmem_idx_PlaylistCount_Reaper = 30
local gmem_idx_PlaylistCount_Realive = 31
local gmemPlaylist_SaveRequest = 1
local gmemPlaylist_SaveRefused = 2
local gmemPlaylist_Initialize = 3
local gmemPlaylist_RealiveListItem_Remove = 4
local gmemPlaylist_RealiveListItem_Add = 5
local gmemPlaylist_RealiveListItem_Update = 6
local gmemPlaylist_ProjectTabs_CleanStatus = 9
local gmemPlaylist_RealiveListItem_Cleanup = 10
local gmem_idxRead_Mngmt = reaper.gmem_read(gmem_idx_Management)
local debug = false
-----------------------------------------------------------
-----// DEBUG FUNCTION //----------------------------------
-----------------------------------------------------------
if debug then reaper.ShowConsoleMsg("") end
function Msg(value)
if debug then
reaper.ShowConsoleMsg(tostring(value) .. "\n")
end
end
-----------------------------------------------------------
-----// FUNCTIONS //---------------------------------------
-----------------------------------------------------------
function Playlist_CountProjectTabs()
local ProjCount=-1
local Aretval="t"
while Aretval~=nil do
local Aretval, Aprojfn = reaper.EnumProjects(ProjCount+1, "")
if Aretval~=nil then ProjCount=ProjCount+1
else break
end
end
return ProjCount+1
end
---------------------------------------------------
-----------------------------------------------------------
-----// Realive List Management //-------------------------
-----------------------------------------------------------
function makeKey(i)
return string.format('project%d', i)
end
function enum_RealivePlaylist()
local i = 1
return function()
local key = makeKey(i)
i = i + 1
if reaper.HasExtState(EXT_SECTION_PLAYLIST, key) then
return key
end
end
end
function get_RealivePlaylist()
local Realive_list = {}
for Realive_key in enum_RealivePlaylist() do
local Realive_projfn = reaper.GetExtState(EXT_SECTION_PLAYLIST, Realive_key)
table.insert(Realive_list, Realive_projfn)
end
return Realive_list
end
function SaveProject(proj, proj_fn)
local drtyState = reaper.IsProjectDirty(proj)
-- Msg('proj_fn: '..proj_fn)
if drtyState == 1 or proj_fn == '' then
local before_projfn = reaper.GetProjectPathEx(proj, '')
Msg('before_projfn: '..before_projfn)
reaper.Main_SaveProject(proj, false)
local after_projfn= reaper.GetProjectPathEx(proj, '')
Msg('after_projfn: '..after_projfn)
if before_projfn ~= after_projfn then
Msg('Project Updated!!!')
reaper.SelectProjectInstance(proj)
end
end
end
function SaveAllTabs()
local playlist = get_RealivePlaylist()
----- Loop...
for i = 1, #playlist do
local retval, projfn= reaper.EnumProjects( i-1, '' )
SaveProject(retval, projfn)
end
end
------------------------------------------
---------// RUN FUNCTION //--------------
------------------------------------------
function run()
local current_proj, current_projfn= reaper.EnumProjects(-1, '')
SaveAllTabs()
-- reaper.gmem_write(gmem_idx_Management, gmemPlaylist_RealiveListItem_Cleanup)
reaper.gmem_write(gmem_idx_Management, gmemPlaylist_Initialize)
reaper.SelectProjectInstance(current_proj)
end
------------------------------------------
---------// RUNTIME //-------------------
------------------------------------------
reaper.gmem_attach(gmemSect)
run()