diff --git a/mousiki/message.go b/mousiki/message.go new file mode 100644 index 0000000..a93282a --- /dev/null +++ b/mousiki/message.go @@ -0,0 +1,8 @@ +package mousiki + +import "github.com/nlowe/mousiki/pandora" + +type MessageTrackChanged struct { + Track *pandora.Track + Station pandora.Station +} diff --git a/mousiki/station_controller.go b/mousiki/station_controller.go index 9d7bd1f..7db93e5 100644 --- a/mousiki/station_controller.go +++ b/mousiki/station_controller.go @@ -33,7 +33,7 @@ type StationController struct { queue []pandora.Track skip chan struct{} - notifications chan *pandora.Track + notifications chan MessageTrackChanged stationChanged chan pandora.Station narrativeCache narrativeCache @@ -51,7 +51,7 @@ func NewStationController(c api.Client, p audio.Player) *StationController { player: p, station: noStationSelected, - notifications: make(chan *pandora.Track, 1), + notifications: make(chan MessageTrackChanged, 1), stationChanged: make(chan pandora.Station, 1), log: logrus.WithFields(logrus.Fields{ @@ -87,7 +87,7 @@ func (s *StationController) Play(ctx context.Context) { s.log.WithField("track", s.playing.String()).Info("Playing new track") select { - case s.notifications <- s.playing: + case s.notifications <- MessageTrackChanged{Track: s.playing, Station: s.station}: } s.player.UpdateStream(s.playing.AudioUrl, s.playing.FileGain) s.stationLock.Unlock() @@ -231,6 +231,6 @@ func (s *StationController) CurrentStation() pandora.Station { return s.station } -func (s *StationController) NotificationChan() <-chan *pandora.Track { +func (s *StationController) NotificationChan() <-chan MessageTrackChanged { return s.notifications } diff --git a/mousiki/station_controller_test.go b/mousiki/station_controller_test.go index 523a29d..425d79d 100644 --- a/mousiki/station_controller_test.go +++ b/mousiki/station_controller_test.go @@ -52,7 +52,7 @@ func TestStationController_Play(t *testing.T) { p.On("UpdateStream", mock.Anything, mock.Anything).Run(func(args mock.Arguments) { url := args.String(0) played = append(played, url) - assert.Equal(t, url, (<-sut.NotificationChan()).AudioUrl) + assert.Equal(t, url, (<-sut.NotificationChan()).Track.AudioUrl) if len(played) == 3 { cancel() diff --git a/mousiki/ui/main.go b/mousiki/ui/main.go index 3379d76..9c09c32 100644 --- a/mousiki/ui/main.go +++ b/mousiki/ui/main.go @@ -25,7 +25,7 @@ type mainWindow struct { stationPicker *stationPicker narrativePopup *narrativePopup - nowPlaying *pandora.Track + nowPlaying mousiki.MessageTrackChanged nowPlayingSong *cview.TextView nowPlayingArtist *cview.TextView nowPlayingAlbum *cview.TextView @@ -200,6 +200,7 @@ func (w *mainWindow) HandleKey(app *cview.Application) func(ev *tcell.EventKey) w.log.WithError(err).Error("Failed to add feedback") } + // Update NowPlaying with the same message to pick up the feedback w.updateNowPlaying(app, w.nowPlaying) } else if ev.Key() == tcell.KeyRune && ev.Rune() == 't' { if err := w.controller.ProvideFeedback(pandora.TrackRatingTired); err != nil { @@ -308,19 +309,17 @@ func (w *mainWindow) updateProgress(app *cview.Application, p audio.PlaybackProg }) } -func (w *mainWindow) updateNowPlaying(app *cview.Application, t *pandora.Track) { +func (w *mainWindow) updateNowPlaying(app *cview.Application, m mousiki.MessageTrackChanged) { app.QueueUpdateDraw(func() { - station := w.controller.CurrentStation() - - w.nowPlayingSong.SetText(FormatTrackTitle(t)) - w.nowPlayingArtist.SetText(FormatTrackArtist(t)) - w.nowPlayingAlbum.SetText(FormatTrackAlbum(t)) + w.nowPlayingSong.SetText(FormatTrackTitle(m.Track)) + w.nowPlayingArtist.SetText(FormatTrackArtist(m.Track)) + w.nowPlayingAlbum.SetText(FormatTrackAlbum(m.Track)) - if w.nowPlaying != nil && w.nowPlaying != t { - _, _ = w.history.Write([]byte("\n" + FormatTrack(w.nowPlaying, station))) + if w.nowPlaying.Track != nil && w.nowPlaying.Track != m.Track { + _, _ = w.history.Write([]byte("\n" + FormatTrack(w.nowPlaying.Track, w.nowPlaying.Station))) } - w.nowPlaying = t + w.nowPlaying = m }) }