aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Garrelou <simon.garrelou@gmail.com>2022-12-10 17:49:07 +0100
committerSimon Garrelou <simon.garrelou@gmail.com>2022-12-10 17:49:07 +0100
commitaab665356867143cd471855f46e9fed617f4c3b9 (patch)
tree6e538a52ec8a40d13361406df5b8239f3b49cfba
parente674c1245206ad055760235ae3d2156bebfcefe1 (diff)
downloadtermsonic-aab665356867143cd471855f46e9fed617f4c3b9.tar.gz
termsonic-aab665356867143cd471855f46e9fed617f4c3b9.zip
Play album/song next / end
-rw-r--r--music/playqueue.go10
-rw-r--r--src/app.go5
-rw-r--r--src/footer.go6
-rw-r--r--src/keybinds.go66
-rw-r--r--src/page_artists.go19
5 files changed, 91 insertions, 15 deletions
diff --git a/music/playqueue.go b/music/playqueue.go
index 7c21b9b..235007e 100644
--- a/music/playqueue.go
+++ b/music/playqueue.go
@@ -43,9 +43,17 @@ func (q *Queue) Append(s *subsonic.Child) {
43 q.songs = append(q.songs, s) 43 q.songs = append(q.songs, s)
44} 44}
45 45
46func (q *Queue) Insert(i int, s *subsonic.Child) {
47 q.songs = append(q.songs[:i], append([]*subsonic.Child{s}, q.songs[i:]...)...)
48}
49
46func (q *Queue) Clear() { 50func (q *Queue) Clear() {
47 q.songs = make([]*subsonic.Child, 0) 51 q.songs = make([]*subsonic.Child, 0)
48 speaker.Clear() 52 if q.isPaused {
53 q.TogglePause()
54 }
55 q.Stop()
56 q.triggerChange()
49} 57}
50 58
51func (q *Queue) PlaySong(s *subsonic.Child) error { 59func (q *Queue) PlaySong(s *subsonic.Child) error {
diff --git a/src/app.go b/src/app.go
index 3a02dbe..f1995a4 100644
--- a/src/app.go
+++ b/src/app.go
@@ -20,8 +20,9 @@ type app struct {
20 cfg *Config 20 cfg *Config
21 21
22 // Artists page 22 // Artists page
23 artistsTree *tview.TreeView 23 artistsTree *tview.TreeView
24 songsList *tview.List 24 songsList *tview.List
25 currentSongs []*subsonic.Child
25 26
26 // Play queue page 27 // Play queue page
27 playQueueList *tview.List 28 playQueueList *tview.List
diff --git a/src/footer.go b/src/footer.go
index 96b0aa3..be275c3 100644
--- a/src/footer.go
+++ b/src/footer.go
@@ -3,7 +3,11 @@ package src
3func (a *app) updateFooter() { 3func (a *app) updateFooter() {
4 switch a.headerSections.GetHighlights()[0] { 4 switch a.headerSections.GetHighlights()[0] {
5 case "artists": 5 case "artists":
6 a.footer.SetText("[blue]l:[yellow] Next song [blue]p:[yellow] Toggle pause") 6 if a.tv.GetFocus() == a.artistsTree {
7 a.footer.SetText("[blue]l:[yellow] Next song [blue]p:[yellow] Toggle pause [blue]e:[yellow] Play album last [blue]n:[yellow] Play album next")
8 } else if a.tv.GetFocus() == a.songsList {
9 a.footer.SetText("[blue]l:[yellow] Next song [blue]p:[yellow] Toggle pause [blue]e:[yellow] Play song last [blue]n:[yellow] Play song next")
10 }
7 case "playqueue": 11 case "playqueue":
8 a.footer.SetText("[blue]l:[yellow] Next song [blue]p:[yellow] Toggle pause [blue]d:[yellow] Remove [blue]j:[yellow] Move up [blue]k:[yellow] Move down") 12 a.footer.SetText("[blue]l:[yellow] Next song [blue]p:[yellow] Toggle pause [blue]d:[yellow] Remove [blue]j:[yellow] Move up [blue]k:[yellow] Move down")
9 case "playlists": 13 case "playlists":
diff --git a/src/keybinds.go b/src/keybinds.go
index 2a9c16b..ffdf64a 100644
--- a/src/keybinds.go
+++ b/src/keybinds.go
@@ -54,6 +54,72 @@ func (a *app) setupMusicControlKeys(p *tview.Box) {
54 } 54 }
55 } 55 }
56 56
57 if a.tv.GetFocus() == a.songsList {
58 if event.Rune() == 'e' {
59 // Add to end
60 sel := a.songsList.GetCurrentItem()
61 a.playQueue.Append(a.currentSongs[sel])
62
63 a.updatePageQueue()
64 } else if event.Rune() == 'n' {
65 // Add next
66 sel := a.songsList.GetCurrentItem()
67 a.playQueue.Insert(1, a.currentSongs[sel])
68
69 a.updatePageQueue()
70 }
71 } else if a.tv.GetFocus() == a.artistsTree {
72 if event.Rune() == 'e' {
73 // Add to end
74 sel := a.artistsTree.GetCurrentNode()
75 ref := sel.GetReference()
76 if ref == nil {
77 return nil
78 }
79
80 if ref.(selection).entryType != "album" {
81 return nil
82 }
83
84 id := ref.(selection).id
85 album, err := a.sub.GetMusicDirectory(id)
86 if err != nil {
87 a.alert("Error: %v", err)
88 return nil
89 }
90
91 for _, s := range album.Child {
92 a.playQueue.Append(s)
93 }
94
95 a.updatePageQueue()
96 } else if event.Rune() == 'n' {
97 // Add next
98 sel := a.artistsTree.GetCurrentNode()
99 ref := sel.GetReference()
100 if ref == nil {
101 return nil
102 }
103
104 if ref.(selection).entryType != "album" {
105 return nil
106 }
107
108 id := ref.(selection).id
109 album, err := a.sub.GetMusicDirectory(id)
110 if err != nil {
111 a.alert("Error: %v", err)
112 return nil
113 }
114
115 for i := len(album.Child) - 1; i >= 0; i-- {
116 a.playQueue.Insert(1, album.Child[i])
117 }
118
119 a.updatePageQueue()
120 }
121 }
122
57 return event 123 return event
58 }) 124 })
59} 125}
diff --git a/src/page_artists.go b/src/page_artists.go
index 6cbaee1..874a675 100644
--- a/src/page_artists.go
+++ b/src/page_artists.go
@@ -47,6 +47,7 @@ func (a *app) artistsPage() tview.Primitive {
47 a.artistsTree.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { 47 a.artistsTree.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
48 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight { 48 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight {
49 a.tv.SetFocus(a.songsList) 49 a.tv.SetFocus(a.songsList)
50 a.updateFooter()
50 return nil 51 return nil
51 } 52 }
52 return event 53 return event
@@ -55,6 +56,7 @@ func (a *app) artistsPage() tview.Primitive {
55 a.songsList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { 56 a.songsList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
56 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight { 57 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight {
57 a.tv.SetFocus(a.artistsTree) 58 a.tv.SetFocus(a.artistsTree)
59 a.updateFooter()
58 return nil 60 return nil
59 } 61 }
60 return event 62 return event
@@ -112,22 +114,17 @@ func (a *app) loadAlbumInPanel(id string) error {
112 return err 114 return err
113 } 115 }
114 116
115 var songs []*subsonic.Child
116
117 a.songsList.Clear() 117 a.songsList.Clear()
118 for i := len(album.Child) - 1; i >= 0; i-- { 118 a.currentSongs = make([]*subsonic.Child, 0)
119 song := album.Child[i] 119 for _, song := range album.Child {
120 songNoPtr := *song 120 a.currentSongs = append(a.currentSongs, song)
121 songs = append([]*subsonic.Child{&songNoPtr}, songs...)
122
123 songsCopy := make([]*subsonic.Child, len(songs))
124 copy(songsCopy, songs)
125 121
126 txt := fmt.Sprintf("%-2d - %s", song.Track, song.Title) 122 txt := fmt.Sprintf("%-2d - %s", song.Track, song.Title)
127 123
128 a.songsList.InsertItem(0, txt, "", 0, func() { 124 a.songsList.AddItem(txt, "", 0, func() {
125 sel := a.songsList.GetCurrentItem()
129 a.playQueue.Clear() 126 a.playQueue.Clear()
130 for _, s := range songsCopy { 127 for _, s := range a.currentSongs[sel:] {
131 a.playQueue.Append(s) 128 a.playQueue.Append(s)
132 } 129 }
133 err := a.playQueue.Play() 130 err := a.playQueue.Play()