OpenAssociatedReaperProject_Install Wwise Command.lua (4780B)
1 --[[ 2 @description OpenAssociatedReaperProject_Install Wwise Command 3 @author Audiokinetic 4 @noindex 5 @provides 6 [main=main] . https://raw.githubusercontent.com/audiokinetic/Reaper-Tools/$commit/OpenAssociatedReaperProject/OpenAssociatedReaperProject_Install%20Wwise%20Command.lua 7 @about 8 The script installs the Wwise command to open the associated REAPER project of a rendered wav file. 9 @license 10 Copyright (c) 2023 AUDIOKINETIC Inc. 11 12 The script in this file is licensed to use under the license available at: 13 https://raw.githubusercontent.com/audiokinetic/Reaper-Tools/main/License.txt (the "License"). 14 You may not use this file except in compliance with the License. 15 16 Unless required by applicable law or agreed to in writing, software distributed 17 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 18 CONDITIONS OF ANY KIND, either express or implied. See the License for the 19 specific language governing permissions and limitations under the License. 20 ]]-- 21 22 info = debug.getinfo(1,'S') 23 scriptPath = info.source:match[[^@?(.*[\/])[^\/]-$]] 24 local utils = dofile(scriptPath.."Utilities.lua") 25 26 if not utils.ReaperMinimumVersionCheck() then 27 reaper.ShowMessageBox("Installation aborted!", "Open Associated REAPER Project", utils.OK_MESSAGE_BOX) 28 return 29 end 30 31 if not utils.JSDependencyCheck() then 32 return 33 end 34 35 local introMessage = "This script will install the Open Associated REAPER Project command in Wwise and configure the root lookup directory for the REAPER projects." 36 local userChoice = reaper.ShowMessageBox(introMessage, "Open Associated REAPER Project", utils.OK_CANCEL_MESSAGE_BOX) 37 if userChoice == utils.CANCEL_RESULT then 38 reaper.ShowMessageBox("Installation aborted!", "Open Associated REAPER Project", utils.OK_MESSAGE_BOX) 39 return 40 end 41 42 -- setup Wwise command 43 wwiseCommand = [[ 44 { 45 "version": 2, 46 "commands": [ 47 { 48 "id": "ak.open_associated_reaper_project", 49 "displayName": "Open Associated REAPER Project", 50 "program": "{REAPER_PATH}reaper.exe", 51 "args": "${sound:originalWavFilePath} {SCRIPT_PATH}OpenAssociatedReaperProject_Script.lua", 52 "cwd": "", 53 "contextMenu": { 54 "enabledFor": "Sound", 55 "visibleFor": "Sound" 56 } 57 } 58 ] 59 } 60 ]] 61 62 if not utils.WindowsOS() then 63 wwiseCommand = [[ 64 { 65 "version": 2, 66 "commands": [ 67 { 68 "id": "ak.open_associated_reaper_project", 69 "displayName": "Open Associated REAPER Project", 70 "program": "open", 71 "args": "-n {REAPER_PATH}REAPER.app --args ${sound:originalWavFilePath} '{SCRIPT_PATH}OpenAssociatedReaperProject_Script.lua'", 72 "cwd": "", 73 "contextMenu": { 74 "enabledFor": "Sound", 75 "visibleFor": "Sound" 76 } 77 } 78 ] 79 } 80 ]] 81 end 82 83 reaperPath = utils.getReaperPath() 84 appData = utils.getAppData() 85 86 wwiseCommand = wwiseCommand:gsub("{REAPER_PATH}", reaperPath) 87 88 info = debug.getinfo(1,'S') 89 scriptPath = info.source:match[[^@?(.*[\/])[^\/]-$]] 90 if utils.WindowsOS() then 91 scriptPath = scriptPath:gsub("\\", "\\\\") 92 end 93 94 wwiseCommand = wwiseCommand:gsub("{SCRIPT_PATH}", scriptPath) 95 96 -- Install Wwise command 97 openInReaperPath = appData.."/Audiokinetic/Wwise/Add-ons/Commands/" 98 if utils.WindowsOS() then 99 openInReaperPath = openInReaperPath:gsub("/", "\\") 100 end 101 102 reaper.RecursiveCreateDirectory(openInReaperPath, 0) 103 openInReaperPath = openInReaperPath.."OpenAssociatedReaperProject.json" 104 105 file, err = io.open(openInReaperPath, "w") 106 if file then 107 file:write(wwiseCommand) 108 file:close() 109 else 110 reaper.ShowMessageBox("Failed to write to "..openInReaperPath, "WriteOpenReaper", utils.OK_MESSAGE_BOX) 111 return 112 end 113 114 -- setup ReaperProjectsRoot.txt 115 reaperProjectsRoot = scriptPath.."ReaperProjectsRoot.txt" 116 retval = "" 117 file, err = io.open(reaperProjectsRoot, "r") 118 if file then 119 retval = file:read() 120 file:close() 121 end 122 123 intval, retval = reaper.JS_Dialog_BrowseForFolder("Select root directory of your REAPER projects.", retval) 124 if intval == utils.OK_RESULT and retval then 125 file, err = io.open(reaperProjectsRoot, "w") 126 if file then 127 file:write(retval) 128 file:close() 129 end 130 end 131 132 local importantNote = "Important Note:\nOpen Associated REAPER Project needs the Start offset and Title metadata embedded in the rendered file, make sure \"Embed title/date/time if not provided\" and \"Embed start offset (media position in project)\" in the REAPER Project Render Metadata are enabled before rendering the file." 133 reaper.ShowMessageBox("Installation completed! Restart Wwise to discover the new command.\n\n"..importantNote, "Open Associated REAPER Project", utils.OK_MESSAGE_BOX) 134