Skip to content

Commit a59a277

Browse files
committed
Press up on audio player to select artist
Fixes #24
1 parent 741a8f6 commit a59a277

File tree

6 files changed

+144
-55
lines changed

6 files changed

+144
-55
lines changed

components/manager/ViewCreator.bs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "pkg:/source/enums/TaskControl.bs"
44
sub CreateAudioPlayerView()
55
m.view = CreateObject("roSGNode", "AudioPlayerView")
66
m.view.observeField("state", "onStateChange")
7+
m.view.observeField("selectedArtist", "onSelectedArtistChange")
78
m.global.sceneManager.callFunc("pushScene", m.view)
89
end sub
910

@@ -226,6 +227,12 @@ sub onPlaybackInfoLoaded()
226227
end if
227228
end sub
228229

230+
sub onSelectedArtistChange()
231+
if isValidAndNotEmpty(m.view.selectedArtist)
232+
m.global.jumpToArtist = m.view.selectedArtist
233+
end if
234+
end sub
235+
229236
' Playback state change event handlers
230237
sub onStateChange()
231238
if LCase(m.view.state) = "finished"

components/music/AudioPlayerView.bs

Lines changed: 112 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import "pkg:/source/api/Image.bs"
33
import "pkg:/source/enums/ColorPalette.bs"
44
import "pkg:/source/enums/ImageType.bs"
55
import "pkg:/source/enums/KeyCode.bs"
6+
import "pkg:/source/enums/String.bs"
67
import "pkg:/source/enums/TaskControl.bs"
78
import "pkg:/source/utils/config.bs"
89
import "pkg:/source/utils/misc.bs"
@@ -55,8 +56,8 @@ sub init()
5556
song = m.top.findNode("song")
5657
song.font.size = 60
5758

58-
artist = m.top.findNode("artist")
59-
artist.font.size = 35
59+
m.artist = m.top.findNode("artist")
60+
m.artist.font.size = 35
6061

6162
numberofsongs = m.top.findNode("numberofsongs")
6263
numberofsongs.font.size = 25
@@ -293,7 +294,7 @@ sub audioStateChanged()
293294
if m.global.audioPlayer.loopMode = "one"
294295
m.scrubTimestamp = -1
295296
playAction()
296-
exitScrubMode()
297+
exitScrubMode(m.buttons)
297298
return
298299
end if
299300

@@ -355,7 +356,7 @@ function previousClicked() as boolean
355356
end if
356357
end if
357358

358-
exitScrubMode()
359+
exitScrubMode(m.buttons)
359360

360361
m.lastRecordedPositionTimestamp = 0
361362
m.positionTimestamp.text = "0:00"
@@ -415,7 +416,7 @@ function nextClicked() as boolean
415416
end if
416417
end if
417418

418-
exitScrubMode()
419+
exitScrubMode(m.buttons)
419420

420421
m.lastRecordedPositionTimestamp = 0
421422
m.positionTimestamp.text = "0:00"
@@ -482,7 +483,7 @@ sub LoadNextSong()
482483
m.global.audioPlayer.control = "stop"
483484
end if
484485

485-
exitScrubMode()
486+
exitScrubMode(m.buttons)
486487

487488
' Reset playPosition bar without animation
488489
m.playPosition.width = 0
@@ -789,8 +790,12 @@ end sub
789790

790791
' exitScrubMode: Moves player out of scrub mode state, resets back to standard play mode
791792
'
792-
sub exitScrubMode()
793-
m.buttons.setFocus(true)
793+
sub exitScrubMode(nodeReceivingFocus = m.buttons as dynamic)
794+
if not isValid(nodeReceivingFocus)
795+
nodeReceivingFocus = m.buttons
796+
end if
797+
798+
nodeReceivingFocus.setFocus(true)
794799
m.thumb.setFocus(false)
795800

796801
if m.seekPosition.visible
@@ -801,7 +806,12 @@ sub exitScrubMode()
801806

802807
m.inScrubMode = false
803808
m.thumb.visible = false
804-
setSelectedButtonState(ButtonState.SELECTED)
809+
810+
if isValid(nodeReceivingFocus.id)
811+
if LCase(nodeReceivingFocus.id) = "buttons"
812+
setSelectedButtonState(ButtonState.SELECTED)
813+
end if
814+
end if
805815
end sub
806816

807817
' checkDisplaySiblingItem: Determine visible state for both previous and next item popups
@@ -848,17 +858,63 @@ sub checkDisplaySiblingItem()
848858
m.previousItem.visible = showPreviousItem
849859
end sub
850860

861+
sub setFocusOnThumb()
862+
if not m.thumb.visible
863+
m.thumb.visible = true
864+
setSelectedButtonState(ButtonState.DEFAULT)
865+
end if
866+
867+
if not m.seekPosition.visible
868+
m.seekPosition.visible = true
869+
end if
870+
871+
m.thumb.setFocus(true)
872+
end sub
873+
851874
' Process key press events
852875
function onKeyEvent(key as string, press as boolean) as boolean
853876

854-
' Key bindings for remote control buttons
855877
if press
856878
' If user presses key to turn off screensaver, don't do anything else with it
857879
if screenSaverActive()
858880
endScreenSaver()
859881
return true
860882
end if
861883

884+
' Key Event handler when m.artist is in focus
885+
if m.artist.hasFocus()
886+
if key = KeyCode.DOWN
887+
m.artist.setFocus(false)
888+
m.artist.color = ColorPalette.WHITE
889+
setFocusOnThumb()
890+
return true
891+
end if
892+
893+
if key = KeyCode.OK or key = KeyCode.PLAY
894+
currentItem = m.global.queueManager.callFunc("getCurrentItem")
895+
896+
if isChainValid(currentItem, "ArtistItems")
897+
if isValidAndNotEmpty(currentItem.ArtistItems)
898+
m.global.audioPlayer.control = "stop"
899+
m.global.audioPlayer.loopMode = ""
900+
m.top.selectedArtist = currentItem.ArtistItems[0]
901+
end if
902+
end if
903+
904+
if not isValidAndNotEmpty(m.top.selectedArtist)
905+
if isChainValid(currentItem, "json.ArtistItems")
906+
if isValidAndNotEmpty(currentItem.json.ArtistItems)
907+
m.global.audioPlayer.control = "stop"
908+
m.global.audioPlayer.loopMode = ""
909+
m.top.selectedArtist = currentItem.json.ArtistItems[0]
910+
end if
911+
end if
912+
end if
913+
914+
return true
915+
end if
916+
end if
917+
862918
' Key Event handler when m.thumb is in focus
863919
if m.thumb.hasFocus()
864920
if key = KeyCode.RIGHT
@@ -873,6 +929,14 @@ function onKeyEvent(key as string, press as boolean) as boolean
873929
return true
874930
end if
875931

932+
if key = KeyCode.UP
933+
m.artist.color = ColorPalette.HIGHLIGHT
934+
if m.thumb.visible
935+
exitScrubMode(m.artist)
936+
end if
937+
return true
938+
end if
939+
876940
if key = KeyCode.OK or key = KeyCode.PLAY
877941
if m.inScrubMode
878942
startLoadingSpinner()
@@ -892,24 +956,51 @@ function onKeyEvent(key as string, press as boolean) as boolean
892956
return playAction()
893957
end if
894958

895-
if key = KeyCode.UP
896-
if not m.thumb.visible
897-
m.thumb.visible = true
898-
setSelectedButtonState(ButtonState.DEFAULT)
959+
if m.buttons.hasFocus()
960+
if key = KeyCode.UP
961+
setFocusOnThumb()
962+
m.buttons.setFocus(false)
963+
checkDisplaySiblingItem()
964+
return true
899965
end if
900-
if not m.seekPosition.visible
901-
m.seekPosition.visible = true
966+
967+
if key = KeyCode.OK
968+
if m.buttons.getChild(m.top.selectedButtonIndex).id = "play"
969+
return playAction()
970+
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "previous"
971+
return previousClicked()
972+
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "next"
973+
return nextClicked()
974+
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "shuffle"
975+
return shuffleClicked()
976+
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "loop"
977+
return loopClicked()
978+
end if
902979
end if
903980

904-
m.thumb.setFocus(true)
905-
m.buttons.setFocus(false)
906-
checkDisplaySiblingItem()
907-
return true
981+
if key = KeyCode.RIGHT
982+
if m.global.queueManager.callFunc("getCount") = 1 then return false
983+
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
984+
if m.top.selectedButtonIndex < m.buttonCount - 1 then m.top.selectedButtonIndex = m.top.selectedButtonIndex + 1
985+
checkDisplaySiblingItem()
986+
return true
987+
end if
988+
989+
if key = KeyCode.LEFT
990+
if m.global.queueManager.callFunc("getCount") = 1 then return false
991+
992+
if m.top.selectedButtonIndex > 0
993+
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
994+
m.top.selectedButtonIndex = m.top.selectedButtonIndex - 1
995+
checkDisplaySiblingItem()
996+
end if
997+
return true
998+
end if
908999
end if
9091000

9101001
if key = KeyCode.DOWN
9111002
if m.thumb.visible
912-
exitScrubMode()
1003+
exitScrubMode(m.buttons)
9131004
end if
9141005
checkDisplaySiblingItem()
9151006
return true
@@ -922,40 +1013,6 @@ function onKeyEvent(key as string, press as boolean) as boolean
9221013
return previousClicked()
9231014
else if key = KeyCode.FASTFORWRD
9241015
return nextClicked()
925-
else if key = KeyCode.left
926-
if m.buttons.hasFocus()
927-
if m.global.queueManager.callFunc("getCount") = 1 then return false
928-
929-
if m.top.selectedButtonIndex > 0
930-
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
931-
m.top.selectedButtonIndex = m.top.selectedButtonIndex - 1
932-
checkDisplaySiblingItem()
933-
end if
934-
return true
935-
end if
936-
else if key = KeyCode.RIGHT
937-
if m.buttons.hasFocus()
938-
if m.global.queueManager.callFunc("getCount") = 1 then return false
939-
940-
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
941-
if m.top.selectedButtonIndex < m.buttonCount - 1 then m.top.selectedButtonIndex = m.top.selectedButtonIndex + 1
942-
checkDisplaySiblingItem()
943-
return true
944-
end if
945-
else if key = KeyCode.OK
946-
if m.buttons.hasFocus()
947-
if m.buttons.getChild(m.top.selectedButtonIndex).id = "play"
948-
return playAction()
949-
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "previous"
950-
return previousClicked()
951-
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "next"
952-
return nextClicked()
953-
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "shuffle"
954-
return shuffleClicked()
955-
else if m.buttons.getChild(m.top.selectedButtonIndex).id = "loop"
956-
return loopClicked()
957-
end if
958-
end if
9591016
end if
9601017
end if
9611018

components/music/AudioPlayerView.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
</children>
173173
<interface>
174174
<field id="state" type="string" />
175+
<field id="selectedArtist" type="assocarray" />
175176
<field id="selectedButtonIndex" type="integer" />
176177
</interface>
177178
</component>

source/Main.bs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ sub Main (args as dynamic) as void
4444
m.global.addFields({ app_loaded: false, playstateTask: playstateTask, sceneManager: sceneManager })
4545
m.global.addFields({ queueManager: CreateObject("roSGNode", "QueueManager") })
4646
m.global.addFields({ audioPlayer: CreateObject("roSGNode", "AudioPlayer") })
47+
m.global.addFields({ jumpToArtist: {} })
48+
49+
m.global.observeField("jumpToArtist", m.port)
4750

4851
app_start:
4952
' First thing to do is validate the ability to use the API
@@ -130,9 +133,20 @@ sub Main (args as dynamic) as void
130133
' m.scene's children is the "previous view" stack
131134
while true
132135
msg = wait(0, m.port)
136+
133137
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
134138
print "CLOSING SCREEN"
135139
return
140+
else if isNodeEvent(msg, "jumpToArtist")
141+
selectedItem = msg.getData()
142+
if isValid(selectedItem)
143+
m.global.sceneManager.callFunc("clearPreviousScene")
144+
group = CreateArtistView(selectedItem)
145+
if not isValid(group)
146+
stopLoadingSpinner()
147+
message_dialog(tr("Unable to find any albums or songs belonging to this artist"))
148+
end if
149+
end if
136150
else if isNodeEvent(msg, "exit")
137151
return
138152
else if isNodeEvent(msg, "closeSidePanel")

source/ShowScenes.bs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ function CreateArtistView(artist as object) as dynamic
712712
group.observeField("quickPlayNode", m.port)
713713
m.global.sceneManager.callFunc("pushScene", group)
714714

715+
overhang = group.getScene().findNode("overhang")
716+
if isValid(overhang)
717+
overhang.visible = true
718+
overhang.isVisible = true
719+
end if
720+
715721
return group
716722
end function
717723

source/static/whatsNew/1.0.5.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[
2+
{
3+
"description": "Press up on audio player to allow selecting playing artist",
4+
"author": "1hitsong"
5+
},
26
{
37
"description": "Add support for folders in favorites row on home screen",
48
"author": "1hitsong"

0 commit comments

Comments
 (0)