diff --git a/dbserver/songinfo_delivery.go b/dbserver/songinfo_delivery.go index 3971d02..b8a1212 100644 --- a/dbserver/songinfo_delivery.go +++ b/dbserver/songinfo_delivery.go @@ -40,17 +40,27 @@ func (h *Handler) handleGetDeliveryInfo(msg *proto.DBMessage) []*proto.DBMessage track.songInfoTitle = h.newSongInfoTitle(t, t.ID) markContextType([]*menuItem{track}, uint32(dmstTrackType(msg))) + // Delivery's own fields, with rekordbox's limits (link-spec + // SONG_INFO_SIBLINGS_ORACLE.md, "Delivery-only fields and limits"): + // the composer's ID even when no artist has it, and its name, and + // the lyricist, cut to 127 UTF-16 units; the delivery comment and + // the ISRC to 255. The ISRC row's argument 8 says delivery control + // is on. + control := uint32(0) + if t.DeliveryControl { + control = 1 + } items = []*menuItem{ - {ItemType: 0x36}, // composer (ComposerID lookup) + {ID: t.ComposerID, Label1: truncateUTF16(t.Composer, 127), ItemType: 0x36}, // composer (ComposerID lookup) {ID: uint32(t.BPM * 100), ItemType: 0x0d}, // BPM - {ID: t.ID, ItemType: 0x23}, // DeliveryComment + {ID: t.ID, Label1: truncateUTF16(t.DeliveryComment, 255), ItemType: 0x23}, // DeliveryComment {ID: newKeyID(t.Key), ParentID: keyID, Label2: track.sortKey, ItemType: 0x0f}, // key {ID: uint32(t.FileTypeID), ItemType: 0x12}, // file type {ID: id("genre", t.Genre), Label1: t.Genre, ItemType: 0x06}, {ID: id("label", t.Label), Label1: t.Label, ItemType: 0x0e}, {ID: id("artist", t.Artist), Label1: t.Artist, ItemType: 0x07}, - {ID: t.ID, ItemType: 0x37}, // lyricist - {ParentID: t.ID, ItemType: 0x4f}, // DeliveryControl / ISRC + {ID: t.ID, Label1: truncateUTF16(t.Lyricist, 127), ItemType: 0x37}, // lyricist + {ParentID: t.ID, Label2: truncateUTF16(t.ISRC, 255), ArtID: control, ItemType: 0x4f}, // DeliveryControl / ISRC track, {ID: id("album", t.Album), Label1: t.Album, ItemType: 0x02, noArtHandle: true}, {ID: uint32(t.Duration.Seconds()), ItemType: 0x0b}, // length diff --git a/dbserver/songinfo_siblings_test.go b/dbserver/songinfo_siblings_test.go index 74e8f5a..f47a78b 100644 --- a/dbserver/songinfo_siblings_test.go +++ b/dbserver/songinfo_siblings_test.go @@ -5,6 +5,7 @@ package dbserver import ( "fmt" "slices" + "strings" "testing" "time" @@ -174,3 +175,57 @@ func TestMalformedSongInfoRequests(t *testing.T) { } } } + +// Delivery Info serves the track's own Delivery fields with rekordbox's +// limits (link-spec song-info-delivery-boundaries and -wide-strings): the +// composer's ID, even dangling, and name and the lyricist cut to 127 UTF-16 +// units, the delivery comment and ISRC to 255 (a surrogate pair split by the +// cut becomes U+FFFD), and the ISRC row's argument 8 set when delivery +// control is on. +func TestDeliveryInfoFields(t *testing.T) { + lib := library.New() + lib.AddTrack(&library.Track{ID: 1, Title: "One", ComposerID: 1101, Composer: strings.Repeat("c", 128), + Lyricist: strings.Repeat("l", 128), DeliveryComment: strings.Repeat("d", 256), ISRC: strings.Repeat("i", 256), + DeliveryControl: true}) + lib.AddTrack(&library.Track{ID: 2, Title: "Two", ComposerID: 999999, Composer: strings.Repeat("🙂", 64)}) + h := &Handler{lib: lib} + + rows := func(id uint32) map[uint32]*menuItem { + h.Handle(&proto.DBMessage{TxID: 1, Type: 0x2602, Args: []proto.DBArg{proto.ArgI32(0x01020401), proto.ArgI32(id)}}) + out := map[uint32]*menuItem{} + for _, r := range h.pendingItems { + out[r.ItemType] = r + } + return out + } + r := rows(1) + if c := r[0x36]; c.ID != 1101 || c.Label1 != strings.Repeat("c", 127) { + t.Errorf("composer %d, %d characters; want 1101, 127", c.ID, len(c.Label1)) + } + if l := r[0x37]; l.ID != 1 || len(l.Label1) != 127 { + t.Errorf("lyricist %d, %d characters; want the track ID, 127", l.ID, len(l.Label1)) + } + if d := r[0x23]; d.ID != 1 || len(d.Label1) != 255 { + t.Errorf("delivery comment %d, %d characters; want the track ID, 255", d.ID, len(d.Label1)) + } + if i := r[0x4f]; i.ParentID != 1 || len(i.Label2) != 255 || i.ArtID != 1 { + t.Errorf("ISRC row %d, %d characters, control %d; want the track ID, 255, 1", i.ParentID, len(i.Label2), i.ArtID) + } + + r = rows(2) + if c, want := r[0x36], strings.Repeat("🙂", 63)+"�"; c.ID != 999999 || c.Label1 != want { + t.Errorf("dangling composer %d %q; want 999999 and 63 characters and U+FFFD", c.ID, c.Label1) + } + if i := r[0x4f]; i.ArtID != 0 || i.Label2 != "" { + t.Errorf("no ISRC: control %d, %q; want 0 and empty", i.ArtID, i.Label2) + } + + // On the wire: argument 8 of the ISRC row. + h.Handle(&proto.DBMessage{TxID: 3, Type: 0x2602, Args: []proto.DBArg{proto.ArgI32(0x01020401), proto.ArgI32(1)}}) + for _, m := range h.Handle(&proto.DBMessage{TxID: 4, Type: proto.DBMsgRenderMenu, Args: []proto.DBArg{ + proto.ArgI32(0x01020401), proto.ArgI32(0), proto.ArgI32(13), proto.ArgI32(0), proto.ArgI32(13), proto.ArgI32(12)}}) { + if m.Type == 0x4101 && m.Args[6].Int() == 0x4f && m.Args[8].Int() != 1 { + t.Errorf("ISRC row argument 8 = %d, want 1", m.Args[8].Int()) + } + } +} diff --git a/library/import_masterdb.go b/library/import_masterdb.go index 7e81cee..b839ff9 100644 --- a/library/import_masterdb.go +++ b/library/import_masterdb.go @@ -160,8 +160,15 @@ type masterDBTrack struct { MixName string `json:"mix_name"` AlbumArtist string `json:"album_artist"` Composer string `json:"composer"` - RemixerID string `json:"remixer_id"` - OrigArtistID string `json:"orig_artist_id"` + // Delivery Info's own fields (djmdContent ComposerID, Lyricist, + // DeliveryComment, DeliveryControl, ISRC). + ComposerID string `json:"composer_id"` + Lyricist string `json:"lyricist"` + DeliveryComment string `json:"delivery_comment"` + DeliveryControl string `json:"delivery_control"` + ISRC string `json:"isrc"` + RemixerID string `json:"remixer_id"` + OrigArtistID string `json:"orig_artist_id"` } // ImportedAsset pairs a library Track.ID with the rekordbox-relative paths @@ -622,39 +629,44 @@ func masterDBToLibrary(t *masterDBTrack, path string) *Track { // if the ID is missing or not a uint32. trackID := parseRBID(t.ID) return &Track{ - ID: trackID, - Title: t.Title, - Artist: t.Artist, - Album: t.Album, - Genre: t.Genre, - Duration: DurationSec(time.Duration(t.DurationSec) * time.Second), - BPM: t.BPM, - Key: t.Key, - Rating: uint8(t.Rating), - Year: t.Year, - TrackNum: t.TrackNum, - DiscNum: t.DiscNum, - FilePath: path, - FileType: ft, - FileSize: t.FileSize, - Comment: t.Comment, - Label: t.Label, - DateAdded: dateAdded, - DateAddedText: dateAddedText, - DateCreated: dateCreated, - ReleaseDate: releaseDate, - Bitrate: t.Bitrate, - SampleRate: t.SampleRate, - PlayCount: t.PlayCount, - ColorID: uint8(t.ColorID), - FileTypeID: t.FileTypeID, - AutoLoadHotCue: t.HotCueAutoLoad != "", - Remixer: t.Remixer, - OriginalArtist: t.OriginalArtist, - MixName: t.MixName, - KeyID: parseRBID(t.KeyID), - AlbumArtist: t.AlbumArtist, - Composer: t.Composer, + ID: trackID, + Title: t.Title, + Artist: t.Artist, + Album: t.Album, + Genre: t.Genre, + Duration: DurationSec(time.Duration(t.DurationSec) * time.Second), + BPM: t.BPM, + Key: t.Key, + Rating: uint8(t.Rating), + Year: t.Year, + TrackNum: t.TrackNum, + DiscNum: t.DiscNum, + FilePath: path, + FileType: ft, + FileSize: t.FileSize, + Comment: t.Comment, + Label: t.Label, + DateAdded: dateAdded, + DateAddedText: dateAddedText, + DateCreated: dateCreated, + ReleaseDate: releaseDate, + Bitrate: t.Bitrate, + SampleRate: t.SampleRate, + PlayCount: t.PlayCount, + ColorID: uint8(t.ColorID), + FileTypeID: t.FileTypeID, + AutoLoadHotCue: t.HotCueAutoLoad != "", + Remixer: t.Remixer, + OriginalArtist: t.OriginalArtist, + MixName: t.MixName, + KeyID: parseRBID(t.KeyID), + AlbumArtist: t.AlbumArtist, + Composer: t.Composer, + ComposerID: parseRBID(t.ComposerID), + Lyricist: t.Lyricist, + DeliveryComment: t.DeliveryComment, + DeliveryControl: strings.EqualFold(t.DeliveryControl, "ON"), + ISRC: t.ISRC, } } diff --git a/library/track.go b/library/track.go index f6fa6fe..a789c5f 100644 --- a/library/track.go +++ b/library/track.go @@ -63,6 +63,14 @@ type Track struct { // artist; ComposerID, which rekordbox's smart playlists call producer). AlbumArtist string `json:"album_artist,omitempty"` Composer string `json:"composer,omitempty"` + // Delivery Info's own fields, from a rekordbox import: the composer's + // djmdArtist ID (kept even when no artist has it), the lyricist, the + // delivery comment, whether delivery control is on, and the ISRC. + ComposerID uint32 `json:"composer_id,omitempty"` + Lyricist string `json:"lyricist,omitempty"` + DeliveryComment string `json:"delivery_comment,omitempty"` + DeliveryControl bool `json:"delivery_control,omitempty"` + ISRC string `json:"isrc,omitempty"` // KeyID is the track's rekordbox key row ID, from an import (0 when the // track has no key relation). It tells an empty-named key from no key. KeyID uint32 `json:"key_id,omitempty"` diff --git a/tools/rekordbox_dump.py b/tools/rekordbox_dump.py index ef82589..361be68 100644 --- a/tools/rekordbox_dump.py +++ b/tools/rekordbox_dump.py @@ -321,7 +321,8 @@ def main(): c.GenreID, c.ArtistID, c.AlbumID, c.KeyID, c.LabelID, rmx.Name AS Remixer, oa.Name AS OrigArtist, c.RemixerID, c.OrgArtistID, - c.Subtitle AS MixName, aa.Name AS AlbumArtist, cp.Name AS Composer + c.Subtitle AS MixName, aa.Name AS AlbumArtist, cp.Name AS Composer, + c.ComposerID, c.Lyricist, c.DeliveryComment, c.DeliveryControl, c.ISRC FROM djmdContent c LEFT JOIN djmdArtist a ON c.ArtistID = a.ID LEFT JOIN djmdAlbum al ON c.AlbumID = al.ID @@ -394,6 +395,14 @@ def main(): "mix_name": d.get("MixName") or "", "album_artist": d.get("AlbumArtist") or "", "composer": d.get("Composer") or "", + # Delivery Info's own fields: the ComposerID as stored (a dangling + # one is still served), Lyricist, DeliveryComment, DeliveryControl + # ("ON" in any case turns it on) and ISRC. + "composer_id": str(d.get("ComposerID") or ""), + "lyricist": d.get("Lyricist") or "", + "delivery_comment": d.get("DeliveryComment") or "", + "delivery_control": d.get("DeliveryControl") or "", + "isrc": d.get("ISRC") or "", "remixer_id": str(d.get("RemixerID") or ""), "orig_artist_id": str(d.get("OrgArtistID") or ""), # Paths are relative to the rekordbox `share/` root, e.g.