Skip to content

Commit

Permalink
add support for composer tag
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jul 19, 2024
1 parent 867e2c4 commit d4066f0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 70 deletions.
50 changes: 26 additions & 24 deletions backend/mediaprovider/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,32 @@ type Genre struct {
}

type Track struct {
ID string
CoverArtID string
ParentID string
Title string
Duration int
TrackNumber int
DiscNumber int
Genres []string
ArtistIDs []string
ArtistNames []string
Album string
AlbumID string
Year int
Rating int
Favorite bool
Size int64
PlayCount int
LastPlayed time.Time
FilePath string
BitRate int
ContentType string
Comment string
BPM int
ReplayGain ReplayGainInfo
ID string
CoverArtID string
ParentID string
Title string
Duration int
TrackNumber int
DiscNumber int
Genres []string
ArtistIDs []string
ArtistNames []string
ComposerIDs []string
ComposerNames []string
Album string
AlbumID string
Year int
Rating int
Favorite bool
Size int64
PlayCount int
LastPlayed time.Time
FilePath string
BitRate int
ContentType string
Comment string
BPM int
ReplayGain ReplayGainInfo
}

type ReplayGainInfo struct {
Expand Down
59 changes: 35 additions & 24 deletions backend/mediaprovider/subsonic/subsonicmediaprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,31 +509,42 @@ func toTrack(ch *subsonic.Child) *mediaprovider.Track {
genres = []string{ch.Genre}
}

var composerIDs []string
var composers []string
for _, ctr := range ch.Contributors {
if strings.EqualFold(ctr.Role, "composer") {
composerIDs = append(composerIDs, ctr.Artist.ID)
composers = append(composers, ctr.Artist.Name)
}
}

return &mediaprovider.Track{
ID: ch.ID,
CoverArtID: ch.CoverArt,
ParentID: ch.Parent,
Title: ch.Title,
Duration: ch.Duration,
TrackNumber: ch.Track,
DiscNumber: ch.DiscNumber,
Genres: genres,
ArtistIDs: artistIDs,
ArtistNames: artistNames,
Album: ch.Album,
AlbumID: ch.AlbumID,
Year: ch.Year,
Rating: ch.UserRating,
Favorite: !ch.Starred.IsZero(),
PlayCount: int(ch.PlayCount),
LastPlayed: ch.Played,
FilePath: ch.Path,
Size: ch.Size,
BitRate: ch.BitRate,
ContentType: ch.ContentType,
Comment: ch.Comment,
BPM: ch.BPM,
ReplayGain: rGain,
ID: ch.ID,
CoverArtID: ch.CoverArt,
ParentID: ch.Parent,
Title: ch.Title,
Duration: ch.Duration,
TrackNumber: ch.Track,
DiscNumber: ch.DiscNumber,
Genres: genres,
ArtistIDs: artistIDs,
ArtistNames: artistNames,
ComposerIDs: composerIDs,
ComposerNames: composers,
Album: ch.Album,
AlbumID: ch.AlbumID,
Year: ch.Year,
Rating: ch.UserRating,
Favorite: !ch.Starred.IsZero(),
PlayCount: int(ch.PlayCount),
LastPlayed: ch.Played,
FilePath: ch.Path,
Size: ch.Size,
BitRate: ch.BitRate,
ContentType: ch.ContentType,
Comment: ch.Comment,
BPM: ch.BPM,
ReplayGain: rGain,
}
}

Expand Down
26 changes: 19 additions & 7 deletions ui/dialogs/trackinfodialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ func (t *TrackInfoDialog) CreateRenderer() fyne.WidgetRenderer {

addFormRow(c, "Title", t.track.Title)

c.Add(newFormText("Artist", true))
c.Add(newFormText("Album", true))
album := widget.NewHyperlink(t.track.Album, nil)
album.OnTapped = func() {
if t.OnNavigateToAlbum != nil {
t.OnNavigateToAlbum(t.track.AlbumID)
}
}
c.Add(album)

c.Add(newFormText("Artists", true))
artists := widgets.NewMultiHyperlink()
artists.BuildSegments(t.track.ArtistNames, t.track.ArtistIDs)
artists.OnTapped = func(id string) {
Expand All @@ -48,14 +57,17 @@ func (t *TrackInfoDialog) CreateRenderer() fyne.WidgetRenderer {
}
c.Add(artists)

c.Add(newFormText("Album", true))
album := widget.NewHyperlink(t.track.Album, nil)
album.OnTapped = func() {
if t.OnNavigateToAlbum != nil {
t.OnNavigateToAlbum(t.track.AlbumID)
if len(t.track.ComposerNames) > 0 {
c.Add(newFormText("Composers", true))
composers := widgets.NewMultiHyperlink()
composers.BuildSegments(t.track.ComposerNames, t.track.ComposerIDs)
artists.OnTapped = func(id string) {
if t.OnNavigateToArtist != nil {
t.OnNavigateToArtist(id)
}
}
c.Add(composers)
}
c.Add(album)

if len(t.track.Genres) > 0 {
c.Add(newFormText("Genres", true))
Expand Down
38 changes: 23 additions & 15 deletions ui/widgets/tracklistrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
ColumnArtist = "Artist"
ColumnTitleArtist = "Title/Artist"
ColumnAlbum = "Album"
ColumnComposer = "Composer"
ColumnTime = "Time"
ColumnYear = "Year"
ColumnFavorite = "Favorite"
Expand All @@ -45,6 +46,7 @@ var (
{Name: ColumnNum, Col: ListColumn{Text: "#", Alignment: fyne.TextAlignTrailing, CanToggleVisible: false}},
{Name: ColumnTitleArtist, Col: ListColumn{Text: "Title / Artist", Alignment: fyne.TextAlignLeading, CanToggleVisible: false}},
{Name: ColumnAlbum, Col: ListColumn{Text: "Album", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
{Name: ColumnComposer, Col: ListColumn{Text: "Composer", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
{Name: ColumnTime, Col: ListColumn{Text: "Time", Alignment: fyne.TextAlignTrailing, CanToggleVisible: true}},
{Name: ColumnYear, Col: ListColumn{Text: "Year", Alignment: fyne.TextAlignTrailing, CanToggleVisible: true}},
{Name: ColumnFavorite, Col: ListColumn{Text: " Fav.", Alignment: fyne.TextAlignCenter, CanToggleVisible: true}},
Expand All @@ -56,14 +58,15 @@ var (
{Name: ColumnPath, Col: ListColumn{Text: "File Path", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
}

// #, Title/Artist, Album, Time, Year, Favorite, Rating, Plays, Comment, Bitrate, Size, Path
ExpandedTracklistRowColumnWidths = []float32{40, -1, -1, 60, 60, 55, 100, 65, -1, 75, 75, -1}
// #, Title/Artist, Album, Composer, Time, Year, Favorite, Rating, Plays, Comment, Bitrate, Size, Path
ExpandedTracklistRowColumnWidths = []float32{40, -1, -1, -1, 60, 60, 55, 100, 65, -1, 75, 75, -1}

CompactTracklistRowColumns = []TracklistColumn{
{Name: ColumnNum, Col: ListColumn{Text: "#", Alignment: fyne.TextAlignTrailing, CanToggleVisible: false}},
{Name: ColumnTitle, Col: ListColumn{Text: "Title", Alignment: fyne.TextAlignLeading, CanToggleVisible: false}},
{Name: ColumnArtist, Col: ListColumn{Text: "Artist", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
{Name: ColumnAlbum, Col: ListColumn{Text: "Album", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
{Name: ColumnComposer, Col: ListColumn{Text: "Composer", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
{Name: ColumnTime, Col: ListColumn{Text: "Time", Alignment: fyne.TextAlignTrailing, CanToggleVisible: true}},
{Name: ColumnYear, Col: ListColumn{Text: "Year", Alignment: fyne.TextAlignTrailing, CanToggleVisible: true}},
{Name: ColumnFavorite, Col: ListColumn{Text: " Fav.", Alignment: fyne.TextAlignCenter, CanToggleVisible: true}},
Expand All @@ -75,8 +78,8 @@ var (
{Name: ColumnPath, Col: ListColumn{Text: "File Path", Alignment: fyne.TextAlignLeading, CanToggleVisible: true}},
}

// #, Title, Artist, Album, Time, Year, Favorite, Rating, Plays, Comment, Bitrate, Size, Path
CompactTracklistRowColumnWidths = []float32{40, -1, -1, -1, 60, 60, 55, 100, 65, -1, 75, 75, -1}
// #, Title, Artist, Album, Composer, Time, Year, Favorite, Rating, Plays, Comment, Bitrate, Size, Path
CompactTracklistRowColumnWidths = []float32{40, -1, -1, -1, -1, 60, 60, 55, 100, 65, -1, 75, 75, -1}
)

type tracklistRowBase struct {
Expand All @@ -103,6 +106,7 @@ type tracklistRowBase struct {
name *widget.RichText // for bold support
artist *MultiHyperlink
album *MultiHyperlink // for disabled support, if albumID is ""
composer *MultiHyperlink
dur *widget.Label
year *widget.Label
favorite *fyne.Container
Expand Down Expand Up @@ -165,7 +169,7 @@ func NewExpandedTracklistRow(tracklist *Tracklist, im *backend.ImageManager, pla

v := makeVerticallyCentered // func alias
container := container.New(tracklist.colLayout,
v(t.num), titleArtistImg, v(t.album), v(t.dur), v(t.year), v(t.favorite), v(t.rating), v(t.plays), v(t.comment), v(t.bitrate), v(t.size), v(t.path))
v(t.num), titleArtistImg, v(t.album), v(t.composer), v(t.dur), v(t.year), v(t.favorite), v(t.rating), v(t.plays), v(t.comment), v(t.bitrate), v(t.size), v(t.path))
t.Content = container
t.setColVisibility = func(colNum int, vis bool) bool {
c := container.Objects[colNum].(*fyne.Container)
Expand All @@ -191,20 +195,21 @@ func NewCompactTracklistRow(tracklist *Tracklist, playingIcon fyne.CanvasObject)
t.playingIcon = playingIcon

t.Content = container.New(tracklist.colLayout,
t.num, t.name, t.artist, t.album, t.dur, t.year, t.favorite, t.rating, t.plays, t.comment, t.bitrate, t.size, t.path)
t.num, t.name, t.artist, t.album, t.composer, t.dur, t.year, t.favorite, t.rating, t.plays, t.comment, t.bitrate, t.size, t.path)

colHiddenPtrMap := map[int]*bool{
2: &t.artist.Hidden,
3: &t.album.Hidden,
4: &t.dur.Hidden,
5: &t.year.Hidden,
6: &t.favorite.Hidden,
7: &t.rating.Hidden,
8: &t.plays.Hidden,
9: &t.comment.Hidden,
10: &t.bitrate.Hidden,
11: &t.size.Hidden,
12: &t.path.Hidden,
4: &t.composer.Hidden,
5: &t.dur.Hidden,
6: &t.year.Hidden,
7: &t.favorite.Hidden,
8: &t.rating.Hidden,
9: &t.plays.Hidden,
10: &t.comment.Hidden,
11: &t.bitrate.Hidden,
12: &t.size.Hidden,
13: &t.path.Hidden,
}
t.setColVisibility = func(colNum int, vis bool) bool {
ptr, ok := colHiddenPtrMap[colNum]
Expand All @@ -226,6 +231,8 @@ func (t *tracklistRowBase) create(tracklist *Tracklist) {
t.artist.OnTapped = tracklist.onArtistTapped
t.album = NewMultiHyperlink()
t.album.OnTapped = func(id string) { tracklist.onAlbumTapped(id) }
t.composer = NewMultiHyperlink()
t.composer.OnTapped = func(id string) { tracklist.onArtistTapped(id) }
t.dur = util.NewTrailingAlignLabel()
t.year = util.NewTrailingAlignLabel()
favorite := NewFavoriteIcon()
Expand Down Expand Up @@ -266,6 +273,7 @@ func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int) {
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
t.artist.BuildSegments(tr.ArtistNames, tr.ArtistIDs)
t.album.BuildSegments([]string{tr.Album}, []string{tr.AlbumID})
t.composer.BuildSegments(tr.ComposerNames, tr.ComposerIDs)
t.dur.Text = util.SecondsToMMSS(float64(tr.Duration))
t.year.Text = strconv.Itoa(tr.Year)
t.plays.Text = strconv.Itoa(int(tr.PlayCount))
Expand Down

0 comments on commit d4066f0

Please sign in to comment.