Skip to content

feat: Map Matroska AlbumArtistSort and ComposerSort - #138

Merged
decriptor merged 1 commit into
mainfrom
feat/matroska-sort-names
Nov 22, 2026
Merged

decriptor merged 1 commit into
mainfrom
feat/matroska-sort-names

Conversation

@decriptor

@decriptor decriptor commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Description

MatroskaTag now overrides AlbumArtistSort and ComposerSort. Before this change both were no-ops from the Tag base.

  • Album artist. This is the album-level ARTIST (TargetTypeValue 50), per the spec.

    • Exception: if the file carries a flat ALBUM_ARTIST (the name ffmpeg writes), that tag is the album artist. AlbumArtists reads and writes it, so it pairs with the file's ALBUM_ARTIST_SORT, the way ffmpeg and exiftool pair them.
    • Clearing AlbumArtists on such a file removes both ALBUM_ARTIST and ALBUM_ARTIST_SORT.
  • AlbumArtistSort reads SORT_WITH nested in the album-artist SimpleTag described above. The fallback is the flat ALBUM_ARTIST_SORT that belongs to it (see the flat-sort rule below). On a file with a track level that is the album level's run: a value-less ALBUM_ARTIST_SORT at 60 or 70 is read, cleared and replaced like any other sort, and the track and album title sorts follow the same rule.

  • ComposerSort reads SORT_WITH nested in the COMPOSER that Composers reads. The fallback is the flat COMPOSER_SORT that belongs to it.

  • Flat sorts follow the sort ownership model below. It covers which value a sort belongs to, repeated values, value-less sorts, and get, set, clear and CopyTo.

  • Precedence and set/clear follow ArtistSort and AlbumSort:

    • The nested sort wins over the flat name.
    • Setting replaces the nested sort. If the parent has no nested sort, or there is no parent at all, the setter writes the flat name. It never changes what a parent reads. It may copy ARTIST to the track level, as described below.
    • Setting null or "" removes the nested sort and the flat sort at every level where it belongs to that value. All five Matroska sort setters now treat "" like null, the way the parent setters already do.
  • The two artist sorts stay independent. When the track has no ARTIST of its own, it inherits the album's, and ArtistSort and AlbumArtistSort both read one SORT_WITH. Files written by TagLib#, and any single-level file with a nested sort, are like this.

    • Before a write to either property would change that shared sort, the setter copies every ARTIST at that level to the track level (30). If the ARTIST came from above the album, it is also copied to the album level.
    • No flat sort is copied: each copy repeats the same value, so the runs of ARTIST_SORT and ALBUM_ARTIST_SORT still reach the original's, and no second copy is left. After the copy, each property keeps its own value, and Artist, Performers and AlbumArtists read the same names as before.
    • This matches the spec's inheritance rule. It does nothing when the value doesn't change, when the ARTIST has no SORT_WITH, or when the file names its album artist with ALBUM_ARTIST.
  • Item fields are written where their getter reads them. This covers Year, Comment, Genre/Genres, Composers and the other fields that apply to the whole file.

    • A value inherited from a broader target is replaced in place, not shadowed by a second copy at the track level, so TagLib# and other readers that look only at 50 see the change.
    • A clear removes the name at every level the getter reads, so Genre = null no longer leaves an inherited genre showing. That affected any file with a track-level Tag, and the copy above creates one on single-level files.
    • A new field goes beside the file's other fields, not into a Tag that holds only ARTIST (and its sort). It never goes above 50, the album.
    • A Tag that a clear empties is dropped on render (fix: Update Matroska cluster positions and disc numbers #132), and it no longer counts as the item level in memory either.
  • Writing back the value read is a no-op in every setter this PR reaches (the sorts, Title, Artist, Performers, Album, AlbumArtists, Composers and the whole-file fields), so the bytes stay as they were. It follows main's Tag.IsWriteBack (fix: Drop a terminating NUL from ID3 text #136): "" is a write-back only when no value holds text, and CopyTo replaces the target's list, so a copy of ISRC A into a file holding A and B leaves only A, the way ID3v2, APE and Vorbis do (model rules 8 and 9).

    • A null still clears. For a whole-file field, the clear also removes a value that a broader level holds behind an empty one, so other readers stop showing it.
    • Publisher = null also removes LABEL.
    • ReplayGainTrackGain/ReplayGainTrackPeak replace the older REPLAYGAIN_GAIN/REPLAYGAIN_PEAK copy, as their getters read those names.
    • A BPM written back as it was read is unchanged.
  • Custom fields named after a flat sort (TITLE_SORT, ARTIST_SORT, ALBUM_SORT, ALBUM_ARTIST_SORT, COMPOSER_SORT, feat: Read and write an arbitrary field on any tag #139) are read, set and removed through the matching sort property, so they pair with their value exactly as the property does; a sort takes one value. Other names stay raw, as feat: Read and write an arbitrary field on any tag #139 defines them.

  • Pairing a flat sort is linear in the number of Tags. A step counter pins this.

Sort ownership model (Matroska)

Levels are TargetTypeValues. A tag applies at its level and at every narrower level, until a narrower level sets the same name; an empty string counts as setting it (tagging.html, "Target types"; RFC 9559 §24.2). The spec defines only the nested SORT_WITH, "a child SimpleTag ... to indicate what alternative value the parent SimpleTag element can have to be sorted" ("Nested Information"). The flat ARTIST_SORT, ALBUM_ARTIST_SORT and COMPOSER_SORT are the ffmpeg convention: -metadata keys written upper-case into one Tag, beside the value. Only file-level Tags take part: a Tag whose Targets name a chapter, attachment, track or edition UID belongs to that item, and no rule below reads or writes it.

  1. Which value a sort belongs to.
    • A nested SORT_WITH sorts its own parent SimpleTag and nothing else.
    • A flat X_SORT sorts the X in its own Tag.
  2. Runs. Climbing from the item, the levels group into runs of one value.
    • A broader Tag that repeats the same value is the same value, so the run continues through it. The spec allows this: "you can also repeat the value for each track" ("Target types"). "The same value" means the same list of the texts the getter reads (the default-language ones), in order, an empty text included.
    • A broader Tag that holds a different value starts a new run.
    • A property the library reads at one level has its run start there: the track title (30), the album title (50), and the album artist (the ARTIST at 50) once the file has a level below the album, as AlbumArtists reads it there. With no value at that level, the run is that level and the value-less levels above it. Every rule below applies to these runs too.
  3. A value-less sort. A flat X_SORT in a Tag with no X (at 50, 60 or 70) passes down to the value below it, so it belongs to the run of the nearest value below it.
    • Below the item's first value it is the item's own (for example, a track-level sort for an inherited album artist).
    • If a different value sits between it and the item, it belongs to that value.
  4. Get. The item's sort is the nested SORT_WITH on the SimpleTag the getter reads. If there is none, it is the first flat X_SORT in the item's run.
  5. Set.
    • If the SimpleTag read has a SORT_WITH, that child is replaced.
    • Otherwise the flat sort goes in the Tag of the value it sorts (for a one-level property, that level). A value above the album, or no value at all, puts it at the ordinary level, which is still in the run.
    • Either way, every other flat copy in the run is removed, so one copy is left for every reader.
  6. Clear. Removes the SORT_WITH on the SimpleTag read and every flat X_SORT in the run, including value-less ones above it. A null is always a clear, so nothing a broader level holds is left behind for another reader.
  7. Writing a value (Artist, Performers, AlbumArtists, Composers, Title, Album):
    • A value placed between a narrower value and the sort that value reads moves that sort down to the narrower value. This covers a different value inserted between them, and a repeated value renamed at the broader level.
    • A cleared value takes its own Tag's flat sorts and those of the value-less broader Tags up to the next Tag that holds a value. A broader Tag that repeats the cleared value keeps its own sort, as that value still applies to the narrower levels (tagging.html, "Target types"). The exception is a sort that an equal narrower value still reads, which stays.
    • A rename keeps the sorts in its own Tag and SimpleTag, as Title already did on main (Save_SettingTitle_KeepsSortAndOtherLanguages) and as a separate sort field does in every other format.
    • A value written equal to the broader value it now shadows (for example AlbumArtists = ["Coll"] under a collection ARTIST=Coll with a SORT_WITH) repeats that SimpleTag, its SORT_WITH included, so a narrower level that read the broader value reads the same sort.
    • Joins and splits. A write that makes two levels' values equal with nothing different between them joins their runs (rule 2); one that makes them differ, or puts a different value between them, splits them. Each run's sort is then what rule 4 reads in the new layout. This is the only way a write to one property changes another's sort, and only because the two became one value or stopped being one. Examples: renaming the album's ARTIST=Ada (with ARTIST_SORT=Ada sort) to the track's Solo makes Ada sort the track's sort too, which is what main, ffprobe and exiftool already read from those bytes; clearing a Band that sat between two Adas joins them.
  8. Write-back (main's Tag.IsWriteBack, fix: Drop a terminating NUL from ID3 text #136). Every setter checks first, before it changes anything, whether it was handed what its getter returns; the check reads the same list the getter returns the first of, so the two cannot disagree. Outside a copy, writing back the value read is a no-op and the bytes stay as they were. "", or a list with no text, is the value read only when the getter reads none and no value of the name holds text where the setter clears (fix: Drop a terminating NUL from ID3 text #136), so the clear would remove nothing. A null clears every level the getter climbs, including a value a broader level holds behind an empty one; only a setter that writes one level (Title, Artist, Album, Performers, the spec-level AlbumArtists) treats a null over a field that reads null as a no-op, as its clear could only uncover a broader value.
  9. CopyTo goes through these setters, values before sorts. A copy replaces the target's list: a value equal to the one read is unchanged only when the target already holds exactly that one value where the getter reads it; otherwise it is written, and the target holds exactly the source's value. A list equal to the one read is unchanged. A sort read from a SORT_WITH is unchanged in a copy, as the flat sorts beside it are separate fields (main's rule for a Vorbis fallback field); a flat sort read beside other texts is rewritten as the one copy. A source with no sort leaves the target's sort as it was, because CopyTo skips nulls.
  10. The split. The one place two SimpleTags with equal text are deliberately different entities is the album artist and the track artist on a file with no level below the album.
    • The copy of ARTIST at 30 keeps ArtistSort apart from AlbumArtistSort. It is a separate SimpleTag, so its nested SORT_WITH is its own (rule 1).
    • No flat sort is copied: each copy repeats the same value, so its run still reaches the original's ARTIST_SORT and ALBUM_ARTIST_SORT, and no second copy is left.
    • The flat names do not collide: the album artist's flat sort is ALBUM_ARTIST_SORT, not ARTIST_SORT.

What other tools do with each case (black box, on files built from ffmpeg's base.mka; r5/blackbox-model.txt and the review's blackbox.txt):

Case ffmpeg ffprobe / mediainfo exiftool TagLib# 2.3.0 This library
Value and flat sort in one Tag writes it this way (one untargeted Tag) ARTIST=Ada, ARTIST_SORT=Ada sort Artist Ada, ArtistSort Ada sort ignores flat sorts Ada sorts as Ada sort
The same value repeated at 30 (R5) does not write levels merged by name: ARTIST=Ada, ARTIST_SORT=Ada sort Artist Ada ×2, ArtistSort Ada sort reads 50 only Ada sort (same value, one run)
A different value at 30 (R1–R3) — merged: shows Solo beside Ada's sort, no pairing lists both artists and one sort, no pairing reads 50 only Solo has no sort; Ada keeps hers
A nested sort on 50, the same value repeated at 30 — ffprobe ARTIST/SORT_WITH=ada nested, mediainfo Performer_SORT_WITH SortWith ada nested albumArtistsSort ada nested the album artist's sort; the track's copy has none of its own (rule 1)
A value-less sort at 50, 60 or 70 above the track (R4, M5, M7) — merged: the sort beside the track artist the same ignores it the track artist's (rule 3)
A value-less 60 sort with a different album artist between (M6) — merged: shows it beside Solo Artist Band, Artist Solo, one ArtistSort x reads 50 only Band's (rule 3)

No reader pairs a flat sort with a value; ffprobe and mediainfo merge by name. Where they differ from us, the spec's own design, a sort as a child of its value, supports the pairing.

Motivation and Context

Spec: https://www.matroska.org/technical/tagging.html.

  • "Nested Information": SORT_WITH is a child SimpleTag giving the parent's sort value.
  • "Target types": a tag applies to all smaller target type values, and ARTIST at 50 is the album artist.
  • The Tags element is RFC 9559 §5.1.8.

Flat names: ffmpeg writes -metadata keys as upper-case SimpleTags, for example ALBUM_ARTIST and ALBUM_ARTIST_SORT. exiftool reads those as AlbumArtist and AlbumArtistSort, and COMPOSER_SORT as ComposerSort.

Closes #116

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring (no functional changes)

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's code style
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass (dotnet test)
  • I have updated documentation as needed
  • My changes generate no new warnings

Testing

Gates

  • dotnet build -c Release: 0 warnings, 0 errors, all four target frameworks.
  • dotnet test -c Release (on main e1dc0ab): net8.0 7153 passed, 57 skipped, 0 failed (7210). net10.0 the same. The skips are the env-gated integration tests.
  • dotnet format --verify-no-changes: clean.
  • The PublicApi snapshot gains the two overrides.

Unit tests are in MatroskaSortNameTests.cs, MatroskaSortIndependenceTests.cs, MatroskaSortOwnershipTests.cs, MatroskaSortModelTests.cs, MatroskaWriteBackTests.cs and MatroskaCopyReplacesTests.cs, and main's TagCopyReplacesListTests now has Matroska rows. They include:

  • A matrix test over 13 file shapes × 6 operations (set, null and "" on each of the two artist sorts). Each operation must change only its own property. Every other getter (title, album, artist, performers, album artists, composers, and the other sorts) must stay the same in memory and after a render.
  • Nested sort winning over the flat name, on single-level and collection-level files.
  • Pairing with a flat ALBUM_ARTIST: read, set, clear, and the nested sort winning over the flat name.
  • "" clearing all five sort setters.
  • The set and clear order from review, and CopyTo into a single-level nested target.
  • Round trips on built files on disk (sync and async) that run in CI: nested, flat, no parents, single-level shared ARTIST (with a GENRE that must be replaced, not duplicated), and a flat ALBUM_ARTIST.
  • A property test over 108 shapes × 6 sort operations × 4 item fields (Genre, Comment, Year, Genres) × {clear, set}. Each field must read null or the new value from exactly one SimpleTag, in memory and after a render, and the sort must hold.
  • A sort-ownership property test: 4 value/sort pairs × 432 shapes (each of 30/50/70: absent, value, value + flat sort, value with SORT_WITH, both, flat sort only; × track filler) × {sort set, null, "", value set, CopyTo}. It requires that no value or sort belonging to another level changes, and that a copied sort sits with its copied value. It fails at 41fd351.
  • WritingBackTheValueRead_ChangesNoBytes: about 3,800 shapes × 19 setters, each byte-identical. Also tests for null clears behind a blocker and for fallback names.
  • SortPairing_IsLinearInTheTags: 3,000 Tags at distinct TargetTypeValues, at most 64 Tag visits per Tag.
  • SortAndValueWrites_OnHostileAndEmptyFields_StayConsistent: empty and missing TagString, TagName and TargetTypeValue; SORT_WITH nested 200 deep; Tags that were read empty.
  • Guards: no ARTIST copy for a bare ARTIST or beside ALBUM_ARTIST; ALBUM_ARTIST stays at its own level; AlbumArtists = [""] clears; new fields stay at 50 after a copy; the Tag order follows fix: Update Matroska cluster positions and disc numbers #132; an emptied Tag is dropped and memory matches the saved file.

Targeted reverts on the new code. Each one, applied alone, makes the Matroska tests fail:

Revert Tests failing
Album-artist sort setter fixed at level 50 3
Album-artist sort setter always at the item level 20
Album-artist sort getter fixed at level 50 4
Composer sort getter only at the track level 6
Flat name before nested sort on single-level files 2
ALBUM_ARTIST not used as the album artist 9
"" not treated as null 3
No copy of ARTIST to the track before a shared write 7
No copy to the album level for a collection-level ARTIST 3

46 further guard reverts each fail a named test. They are listed in the round-3 fix report: flat-sort pairing and its linear bound, write level, clear range, the album cap, copies carrying their sorts, artist-only and dropped Tags, value clears taking their sorts, the write-back no-ops, null clears, and fallback names.

Integration tests: MatroskaIntegrationTests (sync and async), gated on TAGLIBSHARP2_TEST_MATROSKA. The same helper runs in CI on built files. Locally they passed on all 20 files below, beside the #140 track tests in the same class. The helper now also sets and clears Genre after the sort writes, including the TagLib#-written tls.mka and nest1-plain.mka.

Real files: TaglibSharpSamples matroska/test1-8.mkv, taglib-sharp Turning Lime.mkv, ffmpeg-made gen.mka/gen.mkv/gen.webm/plain.mka, and an ffmpeg file with ALBUM_ARTIST and ALBUM_ARTIST_SORT. Also a TagLib#-written tls.mka, where every tag is at level 50 with a nested ARTIST sort, and fixtures with a nested sort injected. Each file went through set, clear, an injected nested SORT_WITH, then set and clear again.

  • The packets from ffmpeg -c copy -f framemd5 were identical every time. ffmpeg cannot open test4 at all, original included. test7 prints the same "Invalid track number 87" as its original.
  • ffmpeg -f null decodes cleanly.
  • ffprobe, mediainfo and exiftool read the new flat and nested values. TagLib# reads the album sort we write on tls.mka.
  • On tls.mka, ArtistSort stays Various after AlbumArtistSort is set and after it is cleared.

Before/after, round 1 (against 880056d), using the review's 1536-row grid and the corpus of 583 files:

  • In 52 grid rows, ArtistSort is now kept on set and on clear. This is the shared-ARTIST case.
  • All 1536 rows now read null after = "".
  • Grid violations: 0.
  • In the corpus, AlbumArtists changed only on the ffmpeg files that carry ALBUM_ARTIST. Nothing else changed.

Before/after, round 2 (against 228f12a rebased on 304bc06, and against main 304bc06). Grid2 from review: 720 shapes × 9 operations, then Genre = null.

  • The follow-on genre clear failed in 624 to 720 shapes per operation at main and at the old head. Now it fails in 0.

  • The only cells worse than the old head are 4 AlbumArtists = [] cells. There, ALBUM_ARTIST was the only track-level tag, so the cleared Tag is dropped and the collection ARTIST becomes the album artist. At the old head, memory said [] but the saved file read [A70]. Now both say [A70].

  • Round-1 grid and the 569-file corpus are unchanged against the old head.

  • TagLib#-written tls2.mka: ArtistSort = x; Genre = null; Comment = null leaves no genre or comment in our reader, ffprobe or TagLib#. Genre = Jazz reads Jazz in all three. A new Conductor after the copy is read by TagLib#.

  • SortModel_HoldsForEveryShapeAndOperation encodes the model above as an oracle that reads the rendered bytes; no part of it calls or copies the library's pairing code. It runs 333,643 cases: 4 value/sort pairs × (432 shapes with distinct texts, 432 with one text repeated, 3 × 432 mixed AAB/ABA/ABB shapes, 8 × 216 shapes with empty texts, 216 shapes beside Tags of a chapter, attachment, track and edition that hold the pair's names, two values at a level, value-less album-artist sorts at 60/70, the review's shapes R1–R5 and the ffmpeg untargeted Tag) × up to 31 operations. It skips no case. For every case it checks that:

    • the library reads what the model reads, before and after, in memory and after a render;
    • writing back any value or sort changes no byte (an empty whole-file list over a broader text is rule 8's clear, and is checked as one), and a CopyTo of the values read changes no value;
    • after any value write, the flat sorts at every level and the nested sorts are exactly what rule 7 predicts from the layout before (renames keep, clears take their own Tag's and the value-less broader ones up to the next value except the one an equal narrower value reads, a sort the narrower value read from above moves down to it, a shadowing repeat copies the nested sorts, a whole-file clear takes all); joins and splits are not exempt, as their sort is then what rule 4 reads in the predicted layout;
    • a sort set leaves exactly one copy, in its value's Tag (at 50 or below), and a clear leaves none; a sort write keeps every other value's own sort, including the broader value a split copied;
    • a write to another property leaves the pair's layout as it was;
    • a Tag of another item keeps its bytes.

    It fails at 34f8331 (1,868 of 333,643 cases) and passes now.

Before/after, round 6 (against 34f8331 with the review's harnesses; main de3ac07 for the corpus):

  • Grid, grid2, grid3, the flat probe, idem, idem2, interp, perf and the real-file reads are identical to 34f8331. The corpus is identical on every Matroska file.
  • The review's probes: a CopyTo of Title = A over the segment title A and 30{TITLE=A,TITLE=Zq2} leaves 30{TITLE=A}; Composers = Composers over an empty COMPOSER keeps COMPOSER_SORT=x byte for byte; AlbumArtists = [] on 70{ARTIST=Ada,ARTIST_SORT=x} 50{ARTIST=Ada} keeps the collection's x, so the track still reads Ada / x (also for ALBUM_ARTIST_SORT).
  • Real files (the review's T11, T12, T13): ffprobe, exiftool and mediainfo show TITLE=A, COMPOSER_SORT=x and ARTIST_SORT=x; ffmpeg -f null decodes cleanly. Fuzz: 33,936 truncation and bit-flip cases, 0 throws. Env-gated MatroskaIntegrationTests pass on 41 files.

Before/after, round 5 (against b378bea with the review's harnesses; main f1ecb88 for the corpus):

  • Grid2, the flat probe, idem, idem2, interp, perf and the real-file reads are identical to b378bea.
  • Grid: 45 rows change, all in get: a value-less ALBUM_ARTIST_SORT above an album with a track level is now read (F3).
  • The 583-file corpus is identical to b378bea on every Matroska file, and differs from main only on the 8 files with the album-artist or composer sorts this PR reads.
  • The review's probes: the F1 triggers now replace ([A], [C1], Performers [Ada]) while a plain Isrc = "A" stays byte-identical; trigger 4 is a no-op; the F3 triggers read, clear (ffprobe and exiftool no longer show x) and replace in place; AlbumArtists = [Coll] under a nested collection artist keeps coll sort.
  • Real files (the review's builds on ffmpeg's base.mka: T3, T4, T7, T8, T9, T10): ffprobe, exiftool and mediainfo read the new values, and ffmpeg -f null decodes cleanly. Fuzz: 22,586 truncation and bit-flip cases, 0 throws.
  • Env-gated MatroskaIntegrationTests pass on 39 files.

Before/after, round 4 (against 5dd208e and ac510c3, using the review's harnesses):

  • Grid2 and the flat probe are identical to both heads.
  • Grid3 is identical to ac510c3. Against 5dd208e only the 9 fallback-name rows differ.
  • The 569-file corpus is identical to ac510c3.
  • The review's idem/idem2 probes now read Ada sort, Bach, J and x sort for the repeated R5 layouts, and the ffmpeg clear after Artist = Artist removes ARTIST_SORT in ffprobe, exiftool and mediainfo.
  • interp keeps x for the track: it moves to 30 when AlbumArtists = ["Band"] is placed between.
  • perf clears the track's ARTIST_SORT with Performers = [].

Before/after, round 3 (against 41fd351, using the review's harnesses):

  • The flat-sort probe shows all of F1's triggers writing beside their value again, the same layout as main and 228f12a. The exception is a COMPOSER_SORT with no COMPOSER anywhere, which goes to 50 instead of an artist-only 30 Tag; the review called this neutral.
  • On the ffmpeg file ffs.mka, after A=Solo AS="Solo, X" and after CopyTo, exiftool shows Ada / Ada sort and Solo / Solo, X, the same as main.
  • Grid2: sort operations are unchanged. 128 parent-value cells (A=NEWA, AA=-) change only because a sort now follows its value; for example, clearing the only album artist no longer leaves its sort readable.
  • Grid3: 8 layouts change, all a flat sort moving to its value. 2 rows (C=- on the ffmpeg shape) now clear the removed composer's COMPOSER_SORT.
  • Round-1 grid: read changes only where a broader Tag's flat sort belonged to a different value.
  • The 569-file corpus is unchanged. Fuzz: 30,579 cases (the review's harness) plus 9,640 span and stream cases (mine), 0 throws.
  • On 16 real files, a save after writing every property back is byte-identical to an unchanged save. At 5dd208e it differed on all 16.

Additional Notes

  • Pre-existing on main, not changed here. On test1.mkv and test6.mkv, any save moves Tags to the end of the segment and drops its SeekHead entry, so ffprobe and mediainfo then see no tags. TagLibSharp2 still re-reads them.
  • Out of scope:
    • The array forms AlbumArtistsSort and ComposersSort.
    • PERFORMER as the track artist.
    • The base AlbumArtist (singular) on Matroska.
    • Several same-name parents at one level: only the first is written, which is the existing rule.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.63561% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.40%. Comparing base (e1dc0ab) to head (267ea3f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...LibSharp2.Tests/Matroska/MatroskaSortModelTests.cs 95.60% 7 Missing and 12 partials ⚠️
...harp2.Tests/Matroska/MatroskaSortOwnershipTests.cs 96.37% 2 Missing and 10 partials ⚠️
...p2.Tests/Matroska/MatroskaSortIndependenceTests.cs 98.28% 0 Missing and 6 partials ⚠️
...LibSharp2.Tests/Matroska/MatroskaWriteBackTests.cs 96.62% 2 Missing and 3 partials ⚠️
src/TagLibSharp2/Matroska/MatroskaTag.cs 98.99% 2 Missing and 2 partials ⚠️
...agLibSharp2.Tests/Core/TagCopyReplacesListTests.cs 90.90% 1 Missing and 2 partials ⚠️
...bSharp2.Tests/Matroska/MatroskaIntegrationTests.cs 98.66% 0 Missing and 1 partial ⚠️
...gLibSharp2.Tests/Matroska/MatroskaSortNameTests.cs 99.60% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #138      +/-   ##
==========================================
+ Coverage   93.29%   93.40%   +0.10%     
==========================================
  Files         409      415       +6     
  Lines       86202    88291    +2089     
  Branches     9886    10288     +402     
==========================================
+ Hits        80421    82464    +2043     
- Misses       3412     3429      +17     
- Partials     2369     2398      +29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@decriptor
decriptor force-pushed the feat/matroska-sort-names branch 8 times, most recently from a57ba1e to 723be21 Compare November 22, 2026 22:42
MatroskaTag now reads and writes AlbumArtistSort and ComposerSort. Both
were no-ops from the Tag base. Each reads the SORT_WITH nested in the
value it sorts: the album-level ARTIST, or a flat ALBUM_ARTIST when the
file has one, for AlbumArtistSort, and COMPOSER for ComposerSort. A flat
ALBUM_ARTIST_SORT or COMPOSER_SORT is the fallback.

Flat sorts follow one ownership model, written up in the PR:
- A flat sort belongs to the value in its own Tag.
- A repeated equal value is one run.
- A value-less sort at 50, 60 or 70 passes down to the nearest value.
Get, set, clear and CopyTo follow from that model. Setting replaces the
sort in the value's own Tag, and a clear takes only that value's sorts.
Before a write would change a sort shared through inheritance, the
setter copies ARTIST to the track level, so ArtistSort and
AlbumArtistSort stay independent.

Item fields (Year, Comment, Genre, Composers, ...) are written where
their getter reads them, and a clear removes the name at every level
the getter sees.

Writing back the value read changes nothing. Each setter checks that
first, against what its own getter returns, following Tag.IsWriteBack;
CopyTo replaces the target's list. The five sort names reached through
the custom-field API behave exactly like their properties.

A model test checks reads, write-back no-ops, single copies, sort
ownership and clear completeness over 333,643 shape and operation
cases. TagCopyReplacesListTests covers Matroska.

Closes #116
@decriptor
decriptor force-pushed the feat/matroska-sort-names branch from 4859a54 to 267ea3f Compare November 22, 2026 23:14
@decriptor

Copy link
Copy Markdown
Owner Author

Review: 0 findings at 267ea3f. The PR is now squashed to one commit, and its tree is identical to the reviewed fix head 4859a54.

What was checked:

  • Round 7 (a57ba1e) found no blocking issues: 1 minor and 1 trivial. Both are fixed at 4859a54. I verified this directly.
    • The six unpinned write-back and clear guards now have tests: two-value PUBLISHER/ReplayGain write-back, null list clears, the TitleSort and AlbumSort no-ops, and the two empty-string guards. The fix report maps each of the 19 PR-line Stryker survivors from round 7 to the test that now kills it.
    • The PR-body count and rule 8 are corrected.
  • After feat: Read and write an arbitrary field on any tag #139 merged, the five sort names reached through the custom-field API (TITLE_SORT, ARTIST_SORT, ALBUM_SORT, ALBUM_ARTIST_SORT, COMPOSER_SORT) go through their properties. CustomField_ForASortName_BehavesAsTheSortProperty checks the value read and the file bytes over every shape, and disabling the routing turns it red. Value names stay raw, as feat: Read and write an arbitrary field on any tag #139 documents.
  • Earlier rounds: all findings are fixed and pinned. The PR body holds the sort ownership model, which cites the Matroska tagging spec and what ffmpeg, ffprobe, mediainfo, exiftool and TagLib# do.
    • The model test runs 333,643 shape and operation cases with no exemptions. It checks:
      • reads;
      • write-back no-ops (each setter checks first, against its own getter, following Tag.IsWriteBack);
      • one copy per set;
      • sort ownership;
      • clear completeness.
    • Every hand mutant from rounds 5–7 is red.
    • Item fields are written where their getter reads them.
    • TagCopyReplacesListTests covers Matroska.
  • Gates:
    • Release build: 0 warnings.
    • net8.0 and net10.0: 7153 passed / 57 skipped.
    • Format: clean.
    • CI: 8/8 green.
    • GitHub reports the PR clean and mergeable.

@decriptor decriptor added the approved AI has reviewed and signed off label Nov 22, 2026
@decriptor
decriptor merged commit 5069025 into main Nov 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved AI has reviewed and signed off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Map Matroska AlbumArtistSort and ComposerSort

1 participant