Skip to content

Split stereo audio to mono tracks - #767

Merged
derekmwright merged 16 commits into
transit-audio:mainfrom
BlueJayLouche:import-split-mono
Nov 24, 2026
Merged

derekmwright merged 16 commits into
transit-audio:mainfrom
BlueJayLouche:import-split-mono

Conversation

@BlueJayLouche

@BlueJayLouche BlueJayLouche commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Split stereo audio to mono tracks

Two microphones recorded onto one stereo track (or any stereo or wider clip) can become mono tracks, one channel each, when you ask for it.

What changes

  • Split to Mono Tracks (clip right-click menu, clip.split_to_mono):
    • Each channel of the selected stereo or wider audio clips goes to a new mono track directly below the clip's track. The tracks are named <track> L and <track> R, numbered past stereo.
    • Each new clip keeps the original's timing, offset, fades, gain and loop. The originals are muted, and the whole split is one undo step. Clips on one track share its new tracks.
    • An in-memory source splits in memory and is written to Audio Files on save.
    • A take played from its file (ADR 0035) gets one mono float WAV per channel written beside it, and the new sources play from disk. If any step fails, every file the split wrote is removed.
    • At most 64 channels.
    • A take whose file failed to read once (a drive unplugged and back) is opened anew, as before an offline render.
  • Import keeps a file's channels, as on main: nothing splits on import.
  • File-manager drops land by the browser drag's rules.
    • The audio goes through import_files, the browser drag's own import path. It lands on the track under the pointer (at the pointer's snapped time on its lane, or on its header, mixer strip or device chain), on a new track when dropped below the tracks, and anywhere else at the cursor, on the cursor's track as on main (a new track when it takes no audio). The mixer's Main strip of a session with no Master track is the main bus, not a track, so a drop there lands at the cursor.
    • A track that takes no audio, or one deleted since the drop was seen, is refused with the reason on the status line.
    • Whether a file is audio is still the engine's call, made by reading its contents as on main. A file it can't use is named on the status line with the reason, even when other files of the same drop import. A file that fails to decode keeps its reason for its drop's last line. When the last file fails, that line gives its own reason, then the Maschine/Kontakt files left out, then the drop's earlier failures. This queue is shared with browser drags, which gain the same.
    • Several files follow each other, and they are decoded in the background, as a browser drag's are.
    • MIDI files import as before.
  • A drop holding a .transit or .dawproject opens it alone through run_or_ask, which asks to save unsaved changes as File > Open does. The status line says which other files were left out.
  • file.import_audio refuses a track that is not an audio track, as file.commit_import already did. The command-line open uses the cursor's track only when it is an audio track.
  • The user guide and K113 describe the drop behavior. The known-issues index is regenerated.

Changes since the review

  • The automatic import split is removed (io.rs is main's plus the split_files module). A test checks that a stereo file on a mono track with a free mono track below lands whole.
  • clip.split_to_mono is kept; the stray comment is gone.
  • Placing several dropped files one after another is kept. It now comes from the browser's import batch instead of a copy of it in drops.rs.
  • Rebased onto main, and cargo xtask indexes was run.
  • Pointer drops respect track compatibility and timeline placement:
    • A drop on a MIDI or instrument track's lane is refused with the reason, where it used to land at the cursor unannounced.
    • A test checks that a drop lands at the exact time drop_target gives for the pointer.
  • A dropped session with unsaved changes brings up the save question, and nothing else of the drop is imported. The test fails if the drop skips run_or_ask.

Evidence

  • Tests:
    • crates/engine/tests/split_to_mono.rs: in memory with save and reopen and undo, a disk-backed take, cleanup when a later take fails, placement with a Master above, duplicate ids, import keeps channels, audio refused on a MIDI track.
    • crates/engine/tests/split_to_mono.rs also covers a take whose file is back after a failed read.
    • crates/ui-studio/src/sampler_panel/drop_routing_tests.rs: a stereo drop on a mono lane lands whole at the pointer; several files on a lane, at the cursor, and at a cursor before bar 1; a MIDI lane refuses with the reason; WAV data named .rf64 or with no extension imports; a text file in a drop is named with its reason, and a drop whose last file fails keeps every reason; a drop at the cursor lands on the cursor's track, not the focused one; a drop on a deleted track says so; a drop on the Main strip lands at the cursor; a dropped session asks to save first, opens alone, and shows why when it fails to open.
    • Each new test fails without its change.
  • Local gates on macOS: fmt, workspace clippy, cargo test --workspace, and the xtask gates. Three test binaries SIGSEGV at exit after test result: ok; that comes from a locally installed plug-in's static destructors and also happens on main.
  • ADR 0009: six fresh-context refutation reviews before the first push, and seven more on this rework. Every valid finding has a fix and a test that fails without it.
    • The rework's blocking findings: Finder drops refused audio the engine reads (.rf64, .opus, extensionless files), because the browser's extension list is narrower than the decoders. A drop on the mixer's Main strip with no Master track was refused as a deleted track.
    • Smaller findings: a decode failure's reason was overwritten by a later file's line, a split didn't reopen a take whose reader had failed once, a drop at the cursor followed the focused track instead of the cursor's, a drop on a deleted track failed silently, and the last-file-fails line could name a stale track or lose a reason.

Follow-ups (non-blocking review notes)

  • Undoing a split of a disk-backed take leaves its mono WAVs on disk, unreferenced. A journal replay after that writes -2 names.
  • Splitting a long disk-backed take runs on the UI thread: about 1.6 s for 27 minutes on an SSD.
  • sanitize_name's 100-character cut can drop the .L or .R from a very long name.
  • A MIDI file that fails in a drop that also holds audio shows its reason only until the audio's status line replaces it. The log keeps it.
  • A drop where no placement target is imports at the cursor, as on main. That covers the mixer background, the keys pane, and the Main strip of a session with no Master track. A browser drag imports nothing there. A real Master track's strip refuses audio with the reason, so the Main bus could refuse too if you'd prefer.
  • After Cancel in the save question of a drop holding a session, the status line still says to drop the files on the session once it is open.
  • Already on main: a Sampler window claims a drop that also holds a session file, and drops are routed while the Save Changes question is open.
  • Already on main: a drop's last status line is replaced at once when another drop is queued behind it, and a remembered decode failure is not named when its drop ends by cancellation, a deleted track, a commit error or expiry.

@derekmwright

Copy link
Copy Markdown
Collaborator

Thanks for this. The split itself is solid: it never overwrites a file, it picks free names, and it cleans up only what it created. I want clip.split_to_mono in.

One thing has to change before it merges: no automatic split on import. Import keeps the source's channel configuration. Splitting a stereo file into independent mono tracks is something the user asks for, not something that happens to them.

So, please:

  • Remove the automatic import-splitting rule.
  • Keep clip.split_to_mono.
  • Keep the multi-file drop correction (sequential placement). That one is a real fix.
  • Remove the stray "ponytail" comment at crates/engine/src/cmd/clip_split.rs:40.
  • Rebase onto main and run cargo xtask indexes.

The other behavior changes are fine with two conditions:

  • Drops at the pointer must respect track compatibility and timeline placement: audio lands on a track that can take it, at the position under the pointer, same rules as any other placement.
  • A drop that includes a session file must go through the same unsaved-changes safeguards as File > Open. And an audio drop that can't be used has to tell the user why, not fail silently.

Once it's updated I'll check those and run the tests again. Nothing else is in the way.

…y mono tracks below it splits across them, one mono source per channel (<name>.L, <name>.R), in one undo step; fewer mono tracks below and it lands whole as before
… each channel of the selected stereo or wider clips on a new mono track below its track, the originals muted, one undo step; a take played from its file gets a mono WAV per channel beside it

Refutation review of the import split (ADR 0009): a frozen mono track below, or one holding a clip where the file goes, is never edited (the file lands whole as before); each split source keeps the peaks the import built; channels past stereo are numbered, not named as a surround layout
… a browser drag does: on the audio track lane or header under the pointer (at the pointer's time on a lane), or on a new track below the tracks; anywhere else at the cursor as before. A stereo file on a mono lane with a mono track below now splits there instead of making a new stereo track
…a failure on a later take removes every file the split wrote; the new tracks sit right below the clip's track with a Master above it; a split take's sources name the files written and keep its BWF stamp; duplicate clip ids split once; at most 64 channels; a write refusal says why; the import split keeps disk-backed audio whole
…(ADR 0009): a drop that also opens a session lands none of its files by the pointer, so none reaches a track of the new session by an old track's id; several files dropped on a track follow each other there instead of each erasing the last; file.import_audio refuses a track that is not an audio track (as file.commit_import does), and a drop at the cursor uses the cursor's track only when it holds audio; K113 notes that the drop position now picks the track
…sion opens it alone and the status line says what was left out, so no file lands by a pointer or cursor that names the closing session's tracks; files dropped at the cursor follow each other there too; the split's file writing, opening and removal move to io/split_files.rs behind the checked file access (the file_access gate)
…pped at a cursor before bar 1 chain from 0, where the engine puts the first, instead of each erasing the last; a session that fails to open keeps its own reason on the status line
…at a dropped session failing to open keeps its own reason on the status line
…le's channels (the automatic split on import is removed; Split to Mono Tracks is the way to split); a file-manager drop lands by the browser drag's rules (import_files: the track under the pointer at its time, or below the tracks, else at the cursor; a track that takes no audio or a file that is not audio is refused with the reason on the status line; queued like a browser drag); a dropped session asks to save unsaved changes as File > Open does (tested); the known-issues index regenerated
…09): whether a dropped file is audio is the engine's call again (import_files leaves out only Maschine/Kontakt files, so WAV data named .rf64 or with no extension imports from a file-manager drop, as on main, and a text file is never called a Maschine/Kontakt file); a file that fails to decode keeps its reason on its drop's last line; a split opens a take's reader anew, so a take whose file is back splits again; the guide says a session drop counts what it left out
…9): a drop at the cursor lands on the cursor's audio track, as on main, not the focused one; when a drop's last file fails, its line names every file of the drop that failed; a drop on a track deleted since its frame says so instead of importing nothing unannounced
…): the mixer's Main strip of a session with no Master track is no drop target (its track id is 0, no track's), so a drop there lands at the cursor instead of being refused as a deleted track; a drop whose last file fails ends on the same "Imported …" line as one whose failure comes first
…9): a drop whose last file fails ends on its "Imported …" line only while the drop's track is still there, never naming a track deleted or undone in between; a test that a real Master track's strip still takes a drop (and refuses audio with the reason)
…): a drop whose last file fails ends on a line that names its failures and the Maschine/Kontakt files left out, never a track (one deleted, undone or reused by id since), so commit_front's "Imported …" line is main's again; the tests go through the real import queue
…): a drop whose last file fails ends on that file's own reason, then the Maschine/Kontakt files left out, then its earlier failures with the first reason, each its own part, so no reason main showed is lost and no file reads as a Maschine/Kontakt file
@BlueJayLouche

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Updated:

  • The automatic import split is gone. Import keeps a file's channels. A test checks that a stereo file on a mono track, with a free mono track below, lands whole.
  • clip.split_to_mono stays. The stray comment is removed.
  • Several dropped files still follow each other. A file-manager drop now goes through the browser drag's own import_files, so it follows the same placement rules: the track under the pointer at the pointer's snapped time, a new track below the tracks, and otherwise the cursor. A track that takes no audio, or a file that isn't audio, is refused with the reason on the status line.
  • A dropped session goes through run_or_ask, the same save question as File > Open. It opens alone, and there's a test for both.
  • Rebased onto main, and I ran cargo xtask indexes.
  • Two small changes to shared browser code came out of review. The import queue keeps a failed file's reason for its drop's last status line. In a session with no Master track, the mixer's Main strip is no longer a drop target (its track id is 0, which no track has), so drops there stop failing silently.

The PR description is updated to match.

@derekmwright
derekmwright merged commit 1c1fee4 into transit-audio:main Nov 24, 2026
6 checks passed
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.

2 participants