Skip to content

Commit

Permalink
fix: lyrics for songs were being loaded in the wrong place, and so we…
Browse files Browse the repository at this point in the history
…ren't updating from song to song unless the album art also changed.
  • Loading branch information
xxxserxxx committed Dec 20, 2024
1 parent 574b660 commit 19a4dc4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
51 changes: 26 additions & 25 deletions event_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,31 @@ func (ui *Ui) guiEventLoop() {

ui.app.QueueUpdateDraw(func() {
ui.playerStatus.SetText(formatPlayerStatus(statusData.Volume, statusData.Position, statusData.Duration))
cl := ui.queuePage.currentLyrics.Lines
lcl := len(cl)
if lcl == 0 {
ui.queuePage.lyrics.SetText("\n[::i]No lyrics[-:-:-]")
} else {
// We only get an update every second or so, and Position is truncated
// to seconds. Make sure that, by the time our tick comes, we're already showing
// the lyric that's being sung. Do this by pretending that we're a half-second
// in the future
p := statusData.Position*1000 + 500
_, _, _, fh := ui.queuePage.lyrics.GetInnerRect()
ui.logger.Printf("field height is %d", fh)
for i := 0; i < lcl-1; i++ {
if p >= cl[i].Start && p < cl[i+1].Start {
txt := ""
if i > 0 {
txt = cl[i-1].Value + "\n"
}
txt += "[::b]" + cl[i].Value + "[-:-:-]\n"
for k := i + 1; k < lcl && k-i < fh; k++ {
txt += cl[k].Value + "\n"
if ui.queuePage.lyrics != nil {
cl := ui.queuePage.currentLyrics.Lines
lcl := len(cl)
if lcl == 0 {
ui.queuePage.lyrics.SetText("\n[::i]No lyrics[-:-:-]")
} else {
// We only get an update every second or so, and Position is truncated
// to seconds. Make sure that, by the time our tick comes, we're already showing
// the lyric that's being sung. Do this by pretending that we're a half-second
// in the future
p := statusData.Position*1000 + 500
_, _, _, fh := ui.queuePage.lyrics.GetInnerRect()
for i := 0; i < lcl-1; i++ {
if p >= cl[i].Start && p < cl[i+1].Start {
txt := ""
if i > 0 {
txt = cl[i-1].Value + "\n"
}
txt += "[::b]" + cl[i].Value + "[-:-:-]\n"
for k := i + 1; k < lcl && k-i < fh; k++ {
txt += cl[k].Value + "\n"
}
ui.queuePage.lyrics.SetText(txt)
break
}
ui.queuePage.lyrics.SetText(txt)
break
}
}
}
Expand All @@ -99,7 +100,7 @@ func (ui *Ui) guiEventLoop() {
ui.app.QueueUpdateDraw(func() {
ui.startStopStatus.SetText("[red::b]Stopped[::-]")
ui.queuePage.lyrics.SetText("")
ui.queuePage.UpdateQueue()
ui.queuePage.updateQueue()
})

case mpvplayer.EventPlaying:
Expand Down Expand Up @@ -142,7 +143,7 @@ func (ui *Ui) guiEventLoop() {

ui.app.QueueUpdateDraw(func() {
ui.startStopStatus.SetText(statusText)
ui.queuePage.UpdateQueue()
ui.queuePage.updateQueue()
if len(ui.queuePage.currentLyrics.Lines) == 0 {
ui.queuePage.lyrics.SetText("\n[::i]No lyrics[-:-:-]")
} else {
Expand Down
13 changes: 9 additions & 4 deletions page_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type QueuePage struct {
songInfo *tview.TextView
lyrics *tview.TextView
coverArt *tview.Image
infoFlex *tview.Flex

currentLyrics subsonic.StructuredLyrics

Expand Down Expand Up @@ -166,23 +167,27 @@ func (ui *Ui) createQueuePage() *QueuePage {
queuePage.coverArt = tview.NewImage()
queuePage.coverArt.SetImage(STMPS_LOGO)

infoFlex := tview.NewFlex().SetDirection(tview.FlexRow).
queuePage.infoFlex = tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(queuePage.songInfo, 0, 1, false).
AddItem(queuePage.lyrics, 0, 1, false).
AddItem(queuePage.coverArt, 0, 1, false)
infoFlex.SetBorder(true)
infoFlex.SetTitle(" song info ")
queuePage.infoFlex.SetBorder(true)
queuePage.infoFlex.SetTitle(" song info ")

// flex wrapper
queuePage.Root = tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(queuePage.queueList, 0, 2, true).
AddItem(infoFlex, 0, 1, false)
AddItem(queuePage.infoFlex, 0, 1, false)

// private data
queuePage.queueData = queueData{
starIdList: ui.starIdList,
}

// flex wrapper
queuePage.Root = tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(queuePage.queueList, 0, 2, true)

return &queuePage
}

Expand Down

0 comments on commit 19a4dc4

Please sign in to comment.