11local OpenBeat = {}
22
3+ local function is_windows ()
4+ return package.config :sub (1 , 1 ) == " \\ "
5+ end
6+
7+ local function path_sep ()
8+ if is_windows () then
9+ return " \\ "
10+ end
11+ return " /"
12+ end
13+
314local function dirname (path )
4- return path :match (" ^(.*)/[^/]+$" ) or " ."
15+ local normalized = tostring (path ):gsub (" \\ " , " /" )
16+ return normalized :match (" ^(.*)/[^/]+$" ) or " ."
517end
618
719local function join_path (...)
820 local items = { ... }
9- return table.concat (items , " / " )
21+ return table.concat (items , path_sep () )
1022end
1123
1224local function file_exists (path )
@@ -29,7 +41,11 @@ local function first_value(items)
2941end
3042
3143local function shell_quote (value )
32- return " '" .. tostring (value ):gsub (" '" , [[ '"'"']] ) .. " '"
44+ local as_string = tostring (value )
45+ if is_windows () then
46+ return ' "' .. as_string :gsub (' "' , ' \\ "' ) .. ' "'
47+ end
48+ return " '" .. as_string :gsub (" '" , [[ '"'"']] ) .. " '"
3349end
3450
3551local function current_script_path ()
@@ -66,7 +82,25 @@ local function repo_root()
6682end
6783
6884local function log (message )
69- local path = os.getenv (" HOME" ) .. " /Library/Application Support/Blackmagic Design/DaVinci Resolve/logs/OpenBeat.log"
85+ local home = os.getenv (" HOME" )
86+ if not home or home == " " then
87+ home = os.getenv (" USERPROFILE" )
88+ end
89+ if not home or home == " " then
90+ return
91+ end
92+
93+ local path
94+ if is_windows () then
95+ local appdata = os.getenv (" APPDATA" )
96+ if appdata and appdata ~= " " then
97+ path = join_path (appdata , " Blackmagic Design" , " DaVinci Resolve" , " Support" , " logs" , " OpenBeat.log" )
98+ else
99+ path = join_path (home , " AppData" , " Roaming" , " Blackmagic Design" , " DaVinci Resolve" , " Support" , " logs" , " OpenBeat.log" )
100+ end
101+ else
102+ path = join_path (home , " Library" , " Application Support" , " Blackmagic Design" , " DaVinci Resolve" , " logs" , " OpenBeat.log" )
103+ end
70104 local handle = io.open (path , " a" )
71105 if not handle then
72106 return
89123
90124local function temp_path (prefix , extension )
91125 local name = string.format (" %s_%d_%d%s" , prefix , os.time (), math.random (1000 , 9999 ), extension or " " )
92- return " /tmp/" .. name
126+ local base = os.getenv (" TMPDIR" ) or os.getenv (" TEMP" ) or os.getenv (" TMP" )
127+ if not base or base == " " then
128+ base = is_windows () and " C:\\ Windows\\ Temp" or " /tmp"
129+ end
130+ return join_path (base , name )
93131end
94132
95133local function python_bin ()
96134 if local_config .python_bin and file_exists (local_config .python_bin ) then
97135 return local_config .python_bin
98136 end
99- local candidate = join_path (repo_root (), " .venv" , " bin" , " python" )
100- if file_exists (candidate ) then
101- return candidate
137+ local candidates = {
138+ join_path (repo_root (), " .venv" , " bin" , " python" ),
139+ join_path (repo_root (), " .venv" , " Scripts" , " python.exe" ),
140+ }
141+ for _ , candidate in ipairs (candidates ) do
142+ if file_exists (candidate ) then
143+ return candidate
144+ end
102145 end
103146 return " python3"
104147end
105148
149+ local function command_prefix ()
150+ local bin = python_bin ()
151+ local lowered = string.lower (bin )
152+ if lowered :match (" python%.exe$" ) or lowered :match (" python$" ) then
153+ return shell_quote (bin ) .. " -m openbeat.cli"
154+ end
155+ return shell_quote (bin )
156+ end
157+
106158local function project_context ()
107159 local resolve_app = resolve or app :GetResolve ()
108160 if not resolve_app then
260312
261313local function analyze_source (source_path )
262314 local output = temp_path (" openbeat_analysis" , " .lua" )
263- local final_command = shell_quote ( python_bin () )
264- .. " -m openbeat.cli analyze --audio "
315+ local final_command = command_prefix ( )
316+ .. " analyze --audio "
265317 .. shell_quote (source_path )
266318 .. " --format lua --output "
267319 .. shell_quote (output )
348400local function render_click_track (source_path , mode )
349401 local suffix = mode == " raw" and " .openbeat-raw-clicks" or " .openbeat-clicks"
350402 local output = output_path_for (source_path , suffix , " .wav" )
351- local command = shell_quote ( python_bin () )
352- .. " -m openbeat.cli click-track --audio "
403+ local command = command_prefix ( )
404+ .. " click-track --audio "
353405 .. shell_quote (source_path )
354406 .. " --mode "
355407 .. shell_quote (mode )
0 commit comments