PDA

View Full Version : Coding for a "playlist"



ERMEGM
- 5th June 2011, 07:00
Hi Guys,


I think there’s a simple solution to my problem, but I’m making it way too complicated in my head, so I was wondering if someone can just give me a little slap and point me in the right direction. :)


Best analogy I can use for what I’m trying to do is like a jukebox machine. I have a list of songs I’d like to play and want to store the playlist. Let’s say I want to hear song 3 two times and song 6 once and song 1 five times.

I keep thinking of using something like the lookup command by somehow assigning the number in the parenthesis like (3,3,6,1,1,1,1,1), but I know that’s not right. I want the ability to select the songs via pushbuttons and at a later time, when I want to hear something else, change the playlist.


So, like a juke box, start with nothing, enter a bunch of songs in the order I want it and the number of reps. When the songs are done, I can do it all over again in a different order. Does this make any sense and can someone point me in the right direction of where I need to start?


Thanks,
Tony

HenrikOlsson
- 5th June 2011, 10:08
Hi Tony,
Yeah, Lookup stores a list of constants at compile time, these can not be changed at a runtime. Instead you could use an array and a couple of index variables pointing into this array. Something like

PlayListMaximumLength CON 128

PlayList VAR BYTE[PlayListMaximumLength]

PlayPointer VAR BYTE
AddPointer VAR BYTE

Song VAR BYTE

AddPointer = 0 'Start adding songs from beginning of list
PlayPointer = 0 'Start playing songs from beginning of list

' Initilise playlist.
Song = 3 : Gosub AddSong
Song = 3 : Gosub AddSong
Song = 6 : Gosub AddSong
Song = 1 : Gosub AddSong
Song = 1 : Gosub AddSong
Song = 1 : Gosub AddSong
Song = 0 : Gosub Addsong ' Song=0 indicates end of list.

PlaySong:
While PlayList[PlayPointer] <> 0

' Do your thing here.
' Play the song.
' Check user inputs and GOSUB routines to add or manipulate the playlist.

PlayPointer = PlayPointer + 1 'Next song in list.
WEND

PlayPointer = 0 'Start over.
Goto PlaySong

AddSong:
PlayList[AddPointer] = Song
AddPointer = AddPointer + 1
If AddPointer = (PlayListMaximumLength - 1) THEN AddPointer = 0 'Wrap around and start over at the beginning of the list.
RETURN
Completely untested but illustrates one possible aproach. Another is to use the EEPROM (data/read/write) or even the program memory (readcode/writecode) to store and retreive the playlist, that way you can have it persistant.

/Henrik.

ERMEGM
- 5th June 2011, 14:39
Hi Henrik,

Thank you for the response, but I'm looking to do it externally like a jukebox. Everything is programmed into the pic. I have some buttons that I'd like to scroll through the songs and select them with another button. So in essence, scroll through, see what I like, and when I find it, "yeah I want to hear this song" so I press the "select" button. Go onto the next song I like, press the "select" button again. When I'm done selecting my songs, it plays back my selection.

The code you showed, which I appreciate you taking the time, will play the order of songs entered during programming. I am trying to simulate a jukebox when I can create a playlist from external inputs. Your thoughts?

Thanks,
Tony

HenrikOlsson
- 5th June 2011, 15:04
I know, and I think it's all there for you. But you need to implement the userinterface.

If you already have your buttons and everything used to scroll thru the list of available songs list you should be set. When you press "select" you set the Song-variable to whatever number the user has selected from the list and then GOSUB AddSong, the song is added to the list.


If UpButton = 1 Then Song = Song + 1 ' Point to next available song to chose from.
If DownButton = 1 Then Song = Song - 1 'Point to previous available song to chose from.

If SelectButton = 1 Then GOSUB AddSong 'Add selected song to list.

If RemoveButton = 1 then
AddPointer = AddPointer - 1 ' Take one step back in the list
PlayList[AddPointer] = 0 ' Remove last entry from list.
EndIf
If this is not what you mean I'm afraid I don't understand exactly what you're trying to do.

/Henrik.