Skip to content

Commit

Permalink
minor fix: work in progress, fixing error message when pressing Skip …
Browse files Browse the repository at this point in the history
…continuously
  • Loading branch information
tramhao committed May 20, 2021
1 parent 14691ab commit f0a3b51
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
1 change: 1 addition & 0 deletions gomu.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (g *Gomu) quit(args Args) error {
}

if gomu.playingBar.albumPhoto != nil {
gomu.playingBar.albumPhoto.Clear()
gomu.playingBar.albumPhoto.Destroy()
gomu.playingBar.albumPhoto = nil
}
Expand Down
6 changes: 3 additions & 3 deletions player/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewMPDPlayer(volume int, mpdPort string) (*MPDPlayer, error) {
return nil, tracerr.Wrap(err)
}

if _, err := mpdConn.Update(""); err != nil {
if _, err := mpdConn.Update("/"); err != nil {
return nil, tracerr.Wrap(err)
}

Expand Down Expand Up @@ -118,6 +118,7 @@ func (p *MPDPlayer) execSongSkip(a Audio) {
func (p *MPDPlayer) Run(currSong Audio) (err error) {

p.isRunning = true
p.currentSong = currSong
p.execSongStart(currSong)

if p.client == nil {
Expand All @@ -142,7 +143,6 @@ func (p *MPDPlayer) Run(currSong Audio) (err error) {
if err != nil {
return tracerr.Wrap(err)
}
p.currentSong = currSong

fileName := p.currentSong.Name()
var added bool = false
Expand Down Expand Up @@ -369,7 +369,7 @@ func (p *MPDPlayer) UpdateDB() (err error) {
}
}

if _, err = p.client.Update(""); err != nil {
if _, err = p.client.Update("/"); err != nil {
return tracerr.Wrap(err)
}

Expand Down
57 changes: 30 additions & 27 deletions playingbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (p *PlayingBar) newProgress(currentSong *player.AudioFile, full int) {
p.subtitle = nil
p.mu.RUnlock()
if p.albumPhoto != nil {
p.albumPhoto.Clear()
p.albumPhoto.Destroy()
p.albumPhoto = nil
}
Expand Down Expand Up @@ -305,6 +306,7 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
p.tag = tag

if p.albumPhoto != nil {
p.albumPhoto.Clear()
p.albumPhoto.Destroy()
p.albumPhoto = nil
}
Expand Down Expand Up @@ -384,39 +386,40 @@ func (p *PlayingBar) setColRowPixel(colrowPixel int) {
func (p *PlayingBar) updatePhoto() {
// Put the whole block in goroutine, in order not to block the whole apps
// also to avoid data race by adding QueueUpdateDraw
go gomu.app.QueueUpdateDraw(func() {
if p.albumPhotoSource == nil {
return
}
// go gomu.app.QueueUpdateDraw(func() {
if p.albumPhotoSource == nil {
return
}

if p.albumPhoto != nil {
p.albumPhoto.Destroy()
p.albumPhoto = nil
}
if p.albumPhoto != nil {
p.albumPhoto.Clear()
p.albumPhoto.Destroy()
p.albumPhoto = nil
}

// get related size
x, y, width, colPixel, rowPixel, err := p.getConsoleSize()
if err != nil {
logError(err)
return
}
// get related size
x, y, width, colPixel, rowPixel, err := p.getConsoleSize()
if err != nil {
logError(err)
return
}

imageWidth := width * colPixel / 3
imageWidth := width * colPixel / 3

// resize the photo according to space left for x and y axis
dstImage := imaging.Resize(p.albumPhotoSource, imageWidth, 0, imaging.Lanczos)
positionX := x*colPixel + width*colPixel - dstImage.Rect.Dx() - colPixel
positionY := y*rowPixel - dstImage.Rect.Dy() - rowPixel/2
// resize the photo according to space left for x and y axis
dstImage := imaging.Resize(p.albumPhotoSource, imageWidth, 0, imaging.Lanczos)
positionX := x*colPixel + width*colPixel - dstImage.Rect.Dx() - colPixel
positionY := y*rowPixel - dstImage.Rect.Dy() - rowPixel/2

// register new image
p.albumPhoto, err = ugo.NewImage(dstImage, positionX, positionY)
if err != nil {
logError(err)
return
}
p.albumPhoto.Show()
// register new image
p.albumPhoto, err = ugo.NewImage(dstImage, positionX, positionY)
if err != nil {
logError(err)
return
}
p.albumPhoto.Show()

})
// })
}

func (p *PlayingBar) getConsoleSize() (int, int, int, int, int, error) {
Expand Down
5 changes: 4 additions & 1 deletion start.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ func start(application *tview.Application, args Args) {
if len(gomu.playingBar.subtitles) == 0 {
description = name
} else {
lang := gomu.playingBar.subtitle.LangExt
var lang string
if gomu.playingBar.subtitle != nil {
lang = gomu.playingBar.subtitle.LangExt
}

description = fmt.Sprintf("%s \n\n %s lyric loaded", name, lang)
}
Expand Down

0 comments on commit f0a3b51

Please sign in to comment.