# =============================================================================
# DRIVE SPEED — does track 3 read right when WE choose the speed, not the drive?
# =============================================================================
#
#   Run it:   ~/Applications/platterpus-x86_64.AppImage --run-script ~/drivespeed.txt
#             (the AppImage where the installer parks it, and the file you
#             downloaded; 0.7.120 already has every verb it uses)
#   Costs:    typically about 40 to 60 minutes on the reference rig (an
#             estimate, not yet measured): eighteen rips of one track each
#             and one probe that rips nothing.
#             Much shorter if the drive refuses a set speed: each fixed-speed
#             rip then fails in seconds, and that refusal is the answer.
#
# UNATTENDED, LIKE EVERY RIG RUN. It never stops to ask for anything; the disc
# is touched only BETWEEN runs (the owner, 2026-11-04).
#
# -----------------------------------------------------------------------------
# WHY THIS EXISTS (round 38, 2026-11-04)
# -----------------------------------------------------------------------------
# Track 3 of the reference disc reads right in some sessions and wrong in
# others on the same drive and disc (docs/eac-parity.md Part G). Pioneer's own
# help for this drive's utility describes its default speed policy, "Quiet
# Mode": slow after a disc goes in, then it "will adjust its spinning speed
# depending on the situation". Our rips set no speed, so the drive chooses, and
# may choose differently per session. This file takes the choice away from it.
#
# CAN WE SET THE SPEED ON THIS DRIVE? NOT KNOWN, AND THIS FILE FINDS OUT.
# In 2026-07 cyanrip refused `-S` outright on this drive, because the drive does
# not advertise speed selection (docs/dependency-contracts.md, `-S`). Upstream
# cyanrip changed that on 2026-10-10 (commit 0be45a36, "Set the drive speed even
# if the drive doesn't advertise it": try it, give up only if the drive itself
# refuses), and `.29` carries it. Whether THIS drive honours the request has not
# been tried since. If it refuses, cyanrip says "Device does not support
# changing speeds!", each fixed-speed rip fails in seconds with that sentence
# in the transcript, and the run carries on (a finding never stops a run).
#
# RUN AGAIN FOR ROUND 44 (TASKS R255, the owner's word of 2026-12-01). It ran in
# round 38 (2026-11-09 and 10): every rip read at about 3x whatever `-S` asked,
# and no set speed took effect (our round 38 lap 17 S5). What it could not see
# then: the drive's OWN declared read cap (MODE SENSE page 2Ah, GET PERFORMANCE),
# which every rip's -j record now carries, was 14x then and 40x from 2026-11-25
# to 2026-11-30. So each phase below is followed by `record-drive-speed`, which
# reads the cap the drive declared during that phase's first rip, and the run
# ends with `compare-drive-speed`: did `-S 4`, `-S 24` or `-S 48` move the cap, did it
# stay moved once unset (F), and is the cap at the start the one the drive had
# when last probed (the history the Full run's U and U2 keep). If a set speed
# moves the cap and it stays, our own command can set the drive's state; if not,
# the change comes from outside anything we send. It needs a build whose -j
# record carries GET PERFORMANCE (`.33` or later; `.36` is under review).
#
# THE ORDER IS DELIBERATE. Unset speed first, because a speed once set may stay
# set: the last rip is unset again, to show whether it did.
#
# A MEASUREMENT, NOT A VERDICT. Every result is `info`. What can go red is a
# rip that did not finish (`expect-exit 0`) or a comparison that cannot be made.
#
# HOW EACH RIP IS MADE. As drivemode.txt does (the read-bearing flags an app rip
# sends, this drive's offset, `-o flac`, `-r 5`, no `-Z`, plus `--cache-probe`),
# with `-S 4` or `-S 24` added for the fixed-speed rips, each into its own
# folder named for its label.
#
# EVERY RIP ALSO READS EACH SECTOR'S C2 POINTERS, where the build has them
# (round 44: the fork's `.37` `--read-c2`, their lap 3 S17; our lap 2 S19 and
# lap 4 S10 send it from this file and drivecap.txt only, never from an app
# rip). `(read-c2)` expands to `--read-c2` only for a build whose contract lists
# it, and only beside `(diagnostics)`, since the pointers are kept only in the -j
# record; on `.35` and `.36` it expands to nothing and the step says so. A
# measurement, never a verdict. Reading C2 is a different READ CD form, so it
# may change how fast the drive reads: every rip in this file reads the same
# way, so the speeds compare with each other, but a `.37` run's speeds are not
# like for like with round 38's, which read without it.
#
# THE FIRST RIP ALSO ASKS THE DRIVE FOR ITS SETTINGS, READ-ONLY. It adds
# `--read-vendor-settings` (the fork's `.30`, cyanrip@5cc1c6b3): cyanrip sends
# Pioneer's own settings query (READ BUFFER, buffer F4h, a read; nothing is
# written to the drive) only to a drive whose INQUIRY names Pioneer, and keeps
# the answer, with PureRead's support and mode read from it, in that rip's -j
# record (`drive_declared.vendor_settings`). The owner's word of 2026-11-05, "Yes
# do this" (TASKS R137). One rip is enough: the mode is the drive's, not the
# track's. It needs `.30` or later; an earlier build refuses the option, so
# that one rip fails in seconds and the run carries on.
# -----------------------------------------------------------------------------

log =============================================================
log DRIVE SPEED - track 3 (and 5) at the drive's speed, 4x, 24x, 48x, and its own cap
log typically about 40-60 minutes
log =============================================================

set debug_logging on
expect debug_logging on
snapshot atstart

# --- A. IDENTITY -----------------------------------------------------------

log --- A. identity ---
cyanrip --version
expect-exit 0
expect-cyanrip platterpus-fork
snapshot identity

# --- B. THE DRIVE AND THE DISC ---------------------------------------------

log --- B. drive offset, disc, and the time bound ---
set-drive-offset
expect-drive-offset
abort-if-failed the read offset for this drive is not known — set the drive up once (Tools, Setup and Updates, Set up drive), then run again
# NO `rescan` HERE, AND THE PICK WAITS TEN MINUTES (2026-11-09). On 0.7.121 with
# `.30` a single disc read can outlast the app's 120 s probe limit (the owner's
# GUI launch of 2026-11-06 17:29:52 UTC, killed during track 2's ISRC read, with no
# second read beside it), and `rescan` failed the run at its own 120 s while the
# app's two automatic re-reads were still coming. A forced re-read also started a
# second read over the one in flight, which 0.7.121 cannot stop. The app reads the
# disc itself at start-up, so the pick below waits for that read and its retries.
# THE RELEASE IS NAMED, NOT NUMBERED. The owner rips the reference disc as the
# BMG club release (MusicBrainz d14a7546…, the third row of four on 2026-11-05)
# and said so on 2026-11-05: "make sure you are choosing the correct album, i
# have been manually choosing the highlighted 3rd option". Row 1 is the 2003 GB
# release, which this script picked until then; MusicBrainz's order is not stable
# either, so a row number would mean a different release later (round08joint.txt
# names the same MBID for the same reason). The read does not depend on it; the
# tags and the record's release ID do.
pick-release d14a7546-815b-43c6-8af6-35cff6cee1d0 600
expect-tracks 5+
abort-if-failed no disc with five tracks is loaded — put the reference disc in, then run again
cyanrip-timeout 1800
snapshot discready

# --- C. THE DRIVE'S OWN SPEED (no -S), as every rip so far ------------------

log --- C. no speed set ---
# The first rip also asks the drive for its own settings (read-only; see the
# header): its -j record then carries the drive's PureRead answer.
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -l 3 -D dsnospeed1 --read-vendor-settings (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy nospeed1 dsnospeed1
record-drive-speed nospeed
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -l 3 -D dsnospeed2 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy nospeed2 dsnospeed2
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -l 3 -D dsnospeed3 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy nospeed3 dsnospeed3
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -l 5 -D dsfivenospeed1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivenospeed1 dsfivenospeed1
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -l 5 -D dsfivenospeed2 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivenospeed2 dsfivenospeed2
snapshot afternospeed

# --- D. FIXED AT 4x. The first rip also asks: does the drive take -S? ---

log --- D. speed 4 ---
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 4 -l 3 -D dsspeedfour1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy speedfour1 dsspeedfour1
record-drive-speed speedfour
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 4 -l 3 -D dsspeedfour2 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy speedfour2 dsspeedfour2
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 4 -l 3 -D dsspeedfour3 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy speedfour3 dsspeedfour3
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 4 -l 5 -D dsfivespeedfour1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivespeedfour1 dsfivespeedfour1
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 4 -l 5 -D dsfivespeedfour2 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivespeedfour2 dsfivespeedfour2
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 4 -l 5 -D dsfivespeedfour3 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivespeedfour3 dsfivespeedfour3
snapshot afterspeedfour

# --- E. FIXED AT 24x ------------------------------------------------------

log --- E. speed 24 ---
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 24 -l 3 -D dsspeedtwentyfour1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy speedtwentyfour1 dsspeedtwentyfour1
record-drive-speed speedtwentyfour
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 24 -l 3 -D dsspeedtwentyfour2 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy speedtwentyfour2 dsspeedtwentyfour2
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 24 -l 3 -D dsspeedtwentyfour3 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy speedtwentyfour3 dsspeedtwentyfour3
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 24 -l 5 -D dsfivespeedtwentyfour1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivespeedtwentyfour1 dsfivespeedtwentyfour1
snapshot afterspeedtwentyfour

# --- E2. ASKED FOR MORE THAN THE DRIVE CAN DO: 48x (the fork's HW-9) ---------
# Does the drive refuse a speed it cannot do? `-S 4` and `-S 24` are both within
# what this drive declares (a maximum read speed of 40x when its cap is high, on
# MODE SENSE page 2Ah), and it accepted both in round 38. 48 is inside cyanrip's
# own range for -S (0 to INT32_MAX, cyanrip@ce0be45:src/cyanrip_main.c:4152) and
# our own read-speed limit (72x, settings_validation.READ_SPEED_MAX), and above
# the drive's 40x. A MEASUREMENT: no `expect-exit`, so no answer turns the run
# red. One rip of track 3, then a probe that rips nothing, then F unsets it.
# What each answer means, read from this rip's log header (`Speed:`) and -j
# record, and from the probe after it:
#   REFUSES  the header's `Speed:` says the setting failed (the fork reads at
#            the drive's own speed rather than stopping the rip), and the cap
#            after it is the cap before it: the drive turns down what it
#            cannot do, which is what HW-9 hopes to see.
#   CLAMPS   the setting is reported as made, and the record's current read
#            speed is the drive's maximum (40x or the cap in force), not 48x:
#            the drive took the request and gave what it could.
#   IGNORES  the setting is reported as made, and the record and the read
#            speed are those of the no-speed rips: the drive accepts a speed
#            command and acts on none, as round 38 found for 4x and 24x.
# And if the cap itself moves here and stays in F, a speed command can set the
# drive's state (R255's question), which compare-drive-speed says.

log --- E2. speed 48, above the drive's declared 40x (HW-9) ---
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -S 48 -l 3 -D dsspeedfortyeight1 (consumer) (diagnostics) (read-c2)
record-accuracy speedfortyeight1 dsspeedfortyeight1
record-drive-speed speedfortyeight
cyanrip -N -d (device) -I --read-vendor-settings (consumer) (diagnostics)
record-drive-speed afterspeedfortyeight
snapshot afterspeedfortyeight

# --- F. UNSET AGAIN: did a set speed stay set? ------------------------------

log --- F. no speed set, after ---
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 5 --cache-probe -l 3 -D dsnospeedafter1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy nospeedafter1 dsnospeedafter1
record-drive-speed nospeedafter

# --- F2. TRACK 5, UP TO TWELVE READS IN ONE RIP (the fork's round 38 lap 8 S11) ---
# The drive has given the AccurateRip-verified read of track 5 (C96464AB) in three
# earlier sessions; one rip with -Z 4 and twelve retries logs every read it makes.

log --- F2. track 5, -Z 4 -r 12 ---
cyanrip -N -U -W -d (device) -s (offset) -o flac -r 12 -Z 4 --cache-probe -l 5 -D dsfivemanyreads1 (consumer) (diagnostics) (read-c2)
expect-exit 0
record-accuracy fivemanyreads1 dsfivemanyreads1

# --- G. THE COMPARISONS ----------------------------------------------------

log --- G. per speed, per track, and the drive's own cap ---
record-kernel-log drivespeed
compare-drive-speed
compare-conditions 3 nospeed1 nospeed2 nospeed3 speedfour1 speedfour2 speedfour3 speedtwentyfour1 speedtwentyfour2 speedtwentyfour3 speedfortyeight1 nospeedafter1
compare-conditions 5 fivenospeed1 fivenospeed2 fivespeedfour1 fivespeedfour2 fivespeedfour3 fivespeedtwentyfour1 fivemanyreads1

# --- H. LEAVE THE RIG AS WE FOUND IT ---------------------------------------

log --- H. restoring ---
set debug_logging off
expect-drive-offset
expect-dialog none
snapshot atend

log =============================================================
log DONE. Send the ONE .tar.gz named on the "SEND THIS ONE FILE"
log line in the app log - it is under
log ~/.local/share/platterpus/bundles/
log Say with it whether the disc had just been put in.
log =============================================================
