I am sorry to say that I am still having problems with cuesheet generation with REACT.
In an effort to understand why this continually fails, I've drafted up a demonstration that works pretty well with a few notable exceptions. Here's the code:
Global $g_eacTitle = "Exact Audio Copy"
Global $g_eacText = "CD Artist"
Global $g_cueMenu = StringSplit("&Action|Create CUE &Sheet|Multiple WAV Files With Gaps... (Noncompliant)", "|")
global $CueRetryWait = 10;Frequency in MS to check for Cuesheet or to attempt moving it again
global $CueRetryAttempts = 500;Total times to perform above waiting period, so resultant waiting time is 500*10=5000ms (5 seconds)
global $Cuesheet = "C:\Program Files\Exact Audio Copy\TMP\Indestructible Object.cue"
FileDelete("debug.txt")
fMakeCuesheet("Key","!m","(M)")
fMakeCuesheet("Key","!o","(MC)")
fMakeCuesheet("Key","!s","(S)")
fMakeCuesheet("Menu",$g_cueMenu,"(MG)")
Func fMakeCuesheet($action,$keypress,$suffix)
FileDelete($cuesheet);Delete any cuesheet that matches the filename we're expecting to prevent renaming an existing cuesheet that may not be what we requested
if $action = "Key" Then ControlSend($g_eacTitle,$g_eacText, "", $keypress);Send the keypress
if $action = "Menu" Then WinMenuSelectItem($g_eacTitle,$g_eacText, $keypress[1], $keypress[2], $keypress[3]);Or the MenuSelection
local $r = 0
While WinExists("Analyzing","Detecting Track Indices")
sleep(10)
$r = $r + 1
WEnd
FileWrite("debug.txt",$suffix & "Waited for Index Analysis to Finish... (" & $r & ") repetitions, " & $r * 10 & "ms" & @CRLF)
local $r = 0
While WinExists("Analyzing","Detecting Pre-Track Gaps")
sleep(1000)
$r = $r + 1
WEnd
FileWrite("debug.txt",$suffix & "Waited for Gap Analysis to Finish... (" & $r & ") repetitions, " & $r * 1000 & "ms" & @CRLF)
local $s = 0;Set the number of attempts to 0
While Not FileExists($cuesheet);If the file isn't found...
sleep($CueRetryWait);Sleep for a certain number of milliseconds. In my demo, this is 10ms.
$s = $s + 1;Increment the number of attempts for looking for the cuesheet.
if $s = $CueRetryAttempts Then ExitLoop;If the number of retry attempts has reached the maximum amount, give up on this cuesheet.
WEnd
FileWrite("debug.txt",$suffix & "Waited for cuefile to exist... (" & $s & ") repetitions, " & $CueRetryWait * $s & "ms" & @CRLF);Write to debug how long we've waited for file to appear.
If FileExists($cuesheet) Then;If the file does indeed exist...
local $s = 1
While FileMove($cuesheet,"C:\Program Files\Exact Audio Copy\TMP\" & $suffix & ".cue",1) = 0;While MoveCuesheet Fails ... (In this case, the renamed file is simply ONLY the suffix, but it's sufficient for this demo)
sleep($CueRetryWait);Sleep for a certain number of milliseconds again. In my demo, this is 10ms.
$s = $s + 1;Increment the number of attempts for moving the cuesheet.
if $s = $CueRetryAttempts Then ExitLoop;If the number of retry attempts has reached the maximum amount, give up on moving this cuesheet.
WEnd
FileWrite("debug.txt",$suffix & "Waited to move cuefile... Took (" & $s & ") attempts, " & $CueRetryWait * $s & "ms" & @CRLF);Write to debug how long we've waited for file to appear.
;FileWrite("debug.txt",$suffix & "Moving Cuesheet... took " & $s & " attempts." & @CRLF);Write to debug to let it know which condition fired.
Else;If File didn't exist, most likely because the first loop timed out waiting for it to show up
FileWrite("Debug.txt",$suffix & "Loop has ended, but file didn't exist... Presumably, ControlSend() failed." & @CRLF);Write to debug to let it know which condition fired.
EndIf
EndFunc
What happens in the above code:
1) Declare Globals, Delete stagnant debug.txt (if any)
2) Call fMakeCuesheet function for the Multiple w/ Leftout Gaps cuesheet.
3) Delete stagnant cuefile if any
4) Send our Key Press.
5) Wait for Analyzing window to subside (Different loops used for Index detection and Gap detection, so we can stall differently for each.) Waits until Analyzing window goes away.
6) Stall until the cuesheet exists. At this point, since the Analyzing window has subsided, it usually exists at this point, but doesn't always. Waits a maximum of 5 seconds before giving up.
7) Stall until the cuesheet is MOVABLE. Sometimes moving fails the first time, so we loop until we are sure to be able to move it. Waits a maximum of 5 seconds before giving up.
Repeat steps 3-7 for remaining 3 cuesheets.
Some sample outputs from the debug.txt, which I feel are very telling about the different stages at which Cuesheet extraction has failed in the past:
Example debug.txt for a CD that has had gaps pre-detected:
(M)Waited for Index Analysis to Finish... (0) repetitions, 0ms
(M)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(M)Waited for cuefile to exist... (9) repetitions, 90ms
(M)Waited to move cuefile... Took (2) attempts, 20ms
(MC)Waited for Index Analysis to Finish... (1) repetitions, 10ms
(MC)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(MC)Waited for cuefile to exist... (0) repetitions, 0ms
(MC)Waited to move cuefile... Took (1) attempts, 10ms
(S)Waited for Index Analysis to Finish... (0) repetitions, 0ms
(S)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(S)Waited for cuefile to exist... (5) repetitions, 50ms
(S)Waited to move cuefile... Took (2) attempts, 20ms
(MG)Waited for Index Analysis to Finish... (0) repetitions, 0ms
(MG)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(MG)Waited for cuefile to exist... (9) repetitions, 90ms
(MG)Waited to move cuefile... Took (1) attempts, 10ms
Things to notice:
1) Sometimes the script required waiting for the "Index Analysis" window to go away (this is the window you see flicker sometimes when you go to extract cuesheets.) You can see this for the (MC) loop.
2) Sometimes the script required waiting to be able to move the cuesheet, you can see this on the (S) loop.
3) Usually the script needs to wait various periods of time for the cuefile to actually exist. (seen on M, S, and MG loops)
Example debug.txt for a CD that requires Gap Analysis:
(M)Waited for Index Analysis to Finish... (0) repetitions, 0ms
(M)Waited for Gap Analysis to Finish... (14) repetitions, 14000ms
(M)Waited for cuefile to exist... (0) repetitions, 0ms
(M)Waited to move cuefile... Took (1) attempts, 10ms
(MC)Waited for Index Analysis to Finish... (0) repetitions, 0ms
(MC)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(MC)Waited for cuefile to exist... (2) repetitions, 20ms
(MC)Waited to move cuefile... Took (1) attempts, 10ms
(S)Waited for Index Analysis to Finish... (1) repetitions, 10ms
(S)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(S)Waited for cuefile to exist... (1) repetitions, 10ms
(S)Waited to move cuefile... Took (2) attempts, 20ms
(MG)Waited for Index Analysis to Finish... (0) repetitions, 0ms
(MG)Waited for Gap Analysis to Finish... (0) repetitions, 0ms
(MG)Waited for cuefile to exist... (2) repetitions, 20ms
(MG)Waited to move cuefile... Took (2) attempts, 20ms
Things to notice:
1) Waits a long period of time only on the first Gap Analysis wait period for (M) loop (14s)
2) Never waits at Gap Analysis for any amount of time ever again.
Remaining Issues this Demonstration does not solve:
1) ControlSend() will fail if the EAC window is minimized, but NOT if the window is merely inactive.
Key Points:
1) It never mistakes cuefiles for the wrong type.
2) Won't fail because it works too fast. (e.g, doesn't get ahead of itself.)
3) Will finish quickly (with loops between 10, 100 and 1000ms) for different checks, potentially finishes even faster than the current CueSheet loop and without repercussion.
4) Good debug output!