Skip to content

fix: preserve TP-7 MTP mode across commands - #4

Open
worm-emoji wants to merge 3 commits into
totocaster:mainfrom
worm-emoji:main
Open

worm-emoji wants to merge 3 commits into
totocaster:mainfrom
worm-emoji:main

Conversation

@worm-emoji

@worm-emoji worm-emoji commented Aug 26, 2026 •

Copy link
Copy Markdown

What this PR does

The TP-7 has two USB personalities:

  • audio/MIDI mode uses product ID 0x8019
  • file-transfer mode uses MTP and product ID 0x0019

File commands need to work across that boundary. With --auto-connect, the CLI detects either personality, switches the recorder to MTP when necessary, opens its storage, performs the requested operation, and leaves it ready for the next command.

The TP-7 also keeps its device-side MTP session alive after a short-lived CLI process exits. A later process can therefore receive SessionAlreadyOpen, while sending CloseSession after every command makes the recorder return to audio/MIDI mode. This PR gives the TP-7 a stable session ID through mtp-rs 0.32.0 and uses reuse_existing_session so separate CLI processes can continue the same device-side session.

Ordinary commands—including connect, status, ls, tree, stat, pull, push, mkdir, rename, and rm—release their host USB handles without sending CloseSession. tp7 eject is the explicit operation that closes the MTP session and returns the recorder to audio/MIDI mode.

On macOS, ptpcamerad can claim the MTP interface before the CLI. tp7 ls --take-over now retries after terminating a process only when IORegistry identifies that process as the exclusive ptpcamerad owner of the TP-7 interface. It does not terminate FieldKit, OpenMTP, or unknown owners.

The file-operation code uses the backend-neutral mtp-rs object, storage, transfer, and error APIs. MTP object and storage IDs are represented as opaque u64 values. The existing JSON keys vendor_extension and free_space_objects remain present but are null, because those protocol-specific values are not exposed by the high-level API.

Result

  • repeated CLI commands keep the TP-7 in MTP mode without a resident helper process
  • tp7 eject cleanly closes the session and returns the device to audio/MIDI mode
  • both TP-7 USB product IDs are detected
  • macOS interface takeover is explicit and narrowly limited to ptpcamerad
  • file listing, metadata, download, upload, overwrite, rename, and delete use mtp-rs 0.32.0
  • TP-7 folder-creation rejection is reported as an unsupported operation with a useful next step

Verification

  • cargo fmt -- --check
  • cargo check
  • cargo clippy -- -D warnings
  • cargo test — 44 tests passed
  • cargo run -- ls --help
  • cargo run -- mkdir --help
  • cargo tree -i mtp-rs — resolves mtp-rs v0.32.0

A real TP-7 running firmware 2.5.7 completed the generated-file hardware sequence in /library: recursive-push preflight, a 19-byte upload, overwrite to 31 bytes, two 25-byte directory uploads, metadata checks, and a clean eject back to audio/MIDI mode. The three generated files were then explicitly removed. No existing recordings were read, rewritten, or deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant