Old 08-24-2019, 10:01 AM   #1
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: Southern Vermont
Posts: 864
Default Project Version and Name-Based Scripts

I find it interesting how REAPER has insane capabilities, but every now and then it seems like misses a really basic feature that you might assume would be included in an ordinary menus.

The following are a couple Lua scripts I feel fit this bill.

PLEASE NOTE:

Please, please, please, use these at your your own risk. They go inside your directory and rename your project files using Lua scripting. If in doubt, test them on a tester/empty project. I've only tried them on Windows 10.

Create New Project Version from Unsaved Progress in Current Tab (timestamped)
Code:
local date = "("..os.date("%m").."-"..os.date("%d").."-"..os.date("%y")..", "..os.date("%H").."h"..os.date("%M").."m"..")"

local dir = reaper.GetProjectPathEx( 0, "" )                                                         -- store project directory
local proj_full_name = reaper.GetProjectName( 0, "" )                                                -- store project full name
local proj_name = string.gsub(string.gsub(reaper.GetProjectName( 0, "" ), ".rpp", ""), ".RPP", "")   -- store new project name
reaper.Main_OnCommand( 41895, 0 )  
local new_proj_full_name = reaper.GetProjectName( 0, "" )                                            -- store new project full name                                                                  -- save as new version
  if string.find(proj_name, "%(") ~= nil                                                             -- delete parentheticals 
then 
  proj_name = string.sub(proj_name, 1, string.find(proj_name, "%(")-1 )   
else
  date=" "..date
end                                                                

  if os.rename(dir.."\\"..new_proj_full_name, dir.."\\"..proj_name..date..".rpp") ~= nil             -- rename current project dated
then                                     
  reaper.Main_openProject( dir.."\\"..proj_name..date..".rpp" )                                      -- open new project
else
  os.rename(dir.."\\"..new_proj_full_name, dir.."\\"..string.gsub(string.gsub(new_proj_full_name, ".rpp", ""), ".RPP", "")..".rpp")  
  reaper.Main_openProject( dir.."\\"..string.gsub(string.gsub(new_proj_full_name, ".rpp", ""), ".RPP", "")..".rpp" )   
end
Create New Project Version from Unsaved Progress in Current Tab (prompt for name)
Code:
local dir = reaper.GetProjectPathEx( 0, "" )

local proj_name = reaper.GetProjectName( 0, "" )

local retval, retvals_csv = reaper.GetUserInputs( "[user input]", 1, "New version name:", string.gsub(string.gsub(proj_name, ".rpp", ""), ".RPP", "") )

  if io.open(retvals_csv..".txt", "w") ~= nil                         -- create dummy file and see if input name is valid
then
  
    if retval and proj_name ~= retvals_csv..".rpp"
  then
    reaper.Main_OnCommand( 41895, 0 )                                   -- save as new version
    proj_name = reaper.GetProjectName( 0, "" )                          -- store new project name
    os.rename(dir.."\\"..proj_name, dir.."\\"..retvals_csv..".rpp")     -- rename current project
   reaper.Main_openProject( dir.."\\"..retvals_csv..".rpp" )           -- open new project
  end

else
  reaper.MB( "Version could not be created using inputted text.", "[error]", 0 )
end
Rename Current Project
Code:
local dir = reaper.GetProjectPathEx( 0, "" )

local proj_name = reaper.GetProjectName( 0, "" )

local retval, retvals_csv = reaper.GetUserInputs( "[user input]", 1, "New project name:", string.gsub(string.gsub(proj_name, ".rpp", ""), ".RPP", "") )

  if io.open(retvals_csv..".txt", "w") ~= nil                         -- create dummy file and see if input name is valid
then
  
    if retval and proj_name ~= retvals_csv..".rpp"
  then
    reaper.Main_SaveProject( 0, 0 )                                     -- save current project
    os.rename(dir.."\\"..proj_name, dir.."\\"..retvals_csv..".rpp")     -- rename current project
    reaper.Main_openProject( dir.."\\"..retvals_csv..".rpp" )           -- open new project
  end

else
  reaper.MB( "Project could not be renamed using inputted text.", "[error]", 0 )
end
Hope you enjoy.
__________________

Support my feature request!

Last edited by Dafarkias; 08-28-2019 at 08:51 AM.
Dafarkias is offline   Reply With Quote
Old 08-24-2019, 10:34 AM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

Quote:
Originally Posted by Dafarkias View Post
Save New Project Version (with timestamp)
Code:
local date = "("..os.date("%m").."-"..os.date("%d").."-"..os.date("%y")..", "..os.date("%H").."h"..os.date("%M").."m"..")"

local dir = reaper.GetProjectPathEx( 0, "" )                                                         -- store project directory
local proj_full_name = reaper.GetProjectName( 0, "" )                                                -- store project full name
local proj_name = string.gsub(string.gsub(reaper.GetProjectName( 0, "" ), ".rpp", ""), ".RPP", "")   -- store new project name
reaper.Main_OnCommand( 41895, 0 )  
local new_proj_full_name = reaper.GetProjectName( 0, "" )                                            -- store new project full name                                                                  -- save as new version
  if string.find(proj_name, "%(") ~= nil                                                             -- delete parentheticals 
then 
  proj_name = string.sub(proj_name, 1, string.find(proj_name, "%(")-1 )   
else
  date=" "..date
end                                                                

  if os.rename(dir.."\\"..new_proj_full_name, dir.."\\"..proj_name..date..".rpp") ~= nil             -- rename current project dated
then                                     
  reaper.Main_openProject( dir.."\\"..proj_name..date..".rpp" )                                      -- open new project
else
  os.rename(dir.."\\"..new_proj_full_name, dir.."\\"..string.gsub(string.gsub(new_proj_full_name, ".rpp", ""), ".RPP", "")..".rpp")  
  reaper.Main_openProject( dir.."\\"..string.gsub(string.gsub(new_proj_full_name, ".rpp", ""), ".RPP", "")..".rpp" )   
end
I think you can just save project after or before this (depending on how user interpret this action - to save what was done on last save or to store changes after last save with new version):

Code:
function main()
  date = "("..os.date("%m").."-"..os.date("%d").."-"..os.date("%y")..", "..os.date("%H").."h"..os.date("%M").."m"..")"
  dir = reaper.GetProjectPathEx( 0, "" )
  proj_full_name = reaper.GetProjectName( 0, "" )  
  if proj_full_name == '' then return end
  proj_name = string.sub(proj_full_name, 0,-5)   -- reduce RPP extension
  proj_name_reduced = proj_name:gsub('%(%d+%-%d+%-%d+,%s%d+h%d+m%)', '') -- reduce date stamp
  
  src_proj = io.open(dir..'/'..proj_full_name, 'r') -- get current project data
  src_proj_content = src_proj:read('a')
  src_proj:close()
  
  dest_proj = io.open(dir..'/'..proj_name_reduced..date..'.RPP', 'w')
  dest_proj:write(src_proj_content) -- apply current project data
  dest_proj:close()
  
end

main()

Last edited by mpl; 08-24-2019 at 10:40 AM.
mpl is offline   Reply With Quote
Old 08-24-2019, 10:59 AM   #3
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: Southern Vermont
Posts: 864
Default

Quote:
Originally Posted by mpl View Post
I think you can just save project after or before this (depending on how user interpret this action - to save what was done on last save or to store changes after last save with new version)
I thought about that...

But isn't the point of saving a version so that it doesn't save the data changes to the original .rpp file?

This script (assuming it works correctly for you) creates a new version of the current project using the action command 41895 without saving any changes to the current project, and then adds a timestamp to the new version.

I hope I haven't confused what you were bringing up to me.

Maybe this following script(s) will show a little clearer what I'm trying to streamline:

Create New Project Version from Unsaved Progress in New Tab (timestamped)

Code:
local date = "("..os.date("%m").."-"..os.date("%d").."-"..os.date("%y")..", "..os.date("%H").."h"..os.date("%M").."m"..os.date("%S").."s)"

local dir = reaper.GetProjectPathEx( 0, "" )                                                         -- store project directory
local proj_full_name = reaper.GetProjectName( 0, "" )                                                -- store project full name
local proj_name = string.gsub(string.gsub(reaper.GetProjectName( 0, "" ), ".rpp", ""), ".RPP", "")   -- store new project name

  if string.find(proj_name, "%(") ~= nil                                                             -- delete parentheticals 
then 
  proj_name = string.sub(proj_name, 1, string.find(proj_name, "%(")-1 )   
else
  date=" "..date
end  

local infile = io.open(dir.."\\"..proj_full_name, "r")                                               -- read old file
local old_file = infile:read("*a")
infile:close()

reaper.Main_SaveProject( 0, 0 )                                                                      -- save current project
  
local infile = io.open(dir.."\\"..proj_full_name, "r")                                               -- read new file
local new_file = infile:read("*a")
infile:close()

local outfile = io.open(dir.."\\"..proj_full_name, "w")                                              -- write old file
outfile:write(old_file)
outfile:close()

local outfile = io.open(dir.."\\"..proj_name..date..".rpp", "w")                                     -- write new file
outfile:write(new_file)
outfile:close()

reaper.Main_openProject( dir.."\\"..proj_full_name )                                                 -- open old project
reaper.Main_OnCommand( 40859, 0 )                                                                    -- open new tab                                
reaper.Main_openProject( dir.."\\"..proj_name..date..".rpp" )                                        -- open new project
Create New Project Version from Unsaved Progress in New Tab (prompt for name)

Code:
local dir = reaper.GetProjectPathEx( 0, "" )                                                         -- store project directory
local proj_full_name = reaper.GetProjectName( 0, "" )                                                -- store project full name
local proj_name = string.gsub(string.gsub(reaper.GetProjectName( 0, "" ), ".rpp", ""), ".RPP", "")   -- store new project name

local retval, retvals_csv = reaper.GetUserInputs( "[user input]", 1, "New version name:", proj_name )

  if io.open(retvals_csv..".txt", "w") ~= nil                         -- create dummy file and see if input name is valid
then
  
    if retval and proj_name ~= retvals_csv
  then
    
    local infile = io.open(dir.."\\"..proj_full_name, "r")                                               -- read old file
    local old_file = infile:read("*a")
    infile:close()
    
    reaper.Main_SaveProject( 0, 0 )                                                                      -- save current project
      
    local infile = io.open(dir.."\\"..proj_full_name, "r")                                               -- read new file
    local new_file = io.open(dir.."\\"..proj_full_name, "r") :read("*a")
    infile:close()
    
    local outfile = io.open(dir.."\\"..proj_full_name, "w")                                              -- write old file
    outfile:write(old_file)
    outfile:close()
    
    local outfile = io.open(dir.."\\"..retvals_csv..".rpp", "w")                                         -- write new file
    outfile:write(new_file)
    outfile:close()
    
    reaper.Main_openProject( dir.."\\"..proj_full_name )                                                 -- open old project
    reaper.Main_OnCommand( 40859, 0 )                                                                    -- open new tab                                
    reaper.Main_openProject( dir.."\\"..retvals_csv..".rpp" )                                            -- open new project
    
  end

else
  reaper.MB( "Version could not be created using inputted text.", "[error]", 0 )
end
__________________

Support my feature request!

Last edited by Dafarkias; 08-28-2019 at 08:48 AM.
Dafarkias is offline   Reply With Quote
Old 08-25-2019, 08:01 AM   #4
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: Southern Vermont
Posts: 864
Default

Just finished slapping together a script I think is very similar in functionality to the ones ^^^^^ up there.... But I think it's much more useful.

Simply whack this bad-boy onto your tool bar (use the icon too, if you wish), and let it do its thing!
Attached Images
File Type: png toolbar_dfk_project_manager_icon.png (595 Bytes, 120 views)
Attached Files
File Type: lua Dfk's Project Quick Access.lua (7.8 KB, 100 views)
__________________

Support my feature request!

Last edited by Dafarkias; 08-25-2019 at 02:00 PM.
Dafarkias is offline   Reply With Quote
Old 05-24-2023, 02:19 AM   #5
bamsehopp
Human being with feelings
 
Join Date: Sep 2018
Posts: 73
Default

Hey great scripts, just what I need. However they don't seem to work for me, perhaps because I'm om Mac OS..? Anyone know how to get these to work for mac?
bamsehopp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.