Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ jukebox/music
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Typhon
USA (112 posts) Bio
|
| Date
| Sun 22 Dec 2002 12:53 PM (UTC) |
| Message
| hi there it seems that there isnt any sort of port f the jukebox stuff from rom to smaug so i ported it myself.. however i have run into a little problem and i dont know enough about file manipulation in C to really know what im doing :p... i have grabbed the music.c and music.h from stock rom 2.4 and i rewrote it to work with smaug. only problem is at this point.. when the music file is loaded it reads everything correctly and it puts the artist and song name correctly into the song table but the lyrics it seems to keep screwing up on. it loads a set of numbers (ie: "2 2 0 0 0 0") for every line in the song.. it has the correct number of lines it just isnt readign the lines in at all :p.. ill post the load_song function and an example from the music.txt if anyone see anything i would greatly appreciate the help :)
//this is what hte song tabel looks like..
Quote:
struct song_data
{
char *group;
char *name;
char *lyrics[MAX_LINES];
int lines;
};
struct song_data song_table[MAX_SONGS];
//load_song: reads all the information from a file into a global table
Quote:
void load_songs(void)
{
FILE *fp;
int count = 0, lines, i;
char letter;
if ((fp = fopen(MUSIC_FILE,"r")) == NULL)
{
bug("Couldn't open music file, no songs available.",0);
fclose(fp);
return;
}
for (count = 0; count < MAX_SONGS; count++)
{
letter = fread_letter(fp);
if (letter == '#')
{
if (count < MAX_SONGS)
song_table[count].name = NULL;
fclose(fp);
return;
}
else
ungetc(letter,fp);
song_table[count].group = fread_string(fp);
song_table[count].name = fread_string(fp);
/* read lyrics */
lines = 0;
for ( ; ;)
{
letter = fread_letter(fp);
if (letter == '~')
{
song_table[count].lines = lines;
break;
}
else
ungetc(letter,fp);
if (lines >= MAX_LINES)
{
bug("Too many lines in a song -- limit is %d.",MAX_LINES);
break;
}
song_table[count].lyrics[lines] = fread_line(fp);
lines++;
}
}
return;
}
//part of music.txt... after the lyrics the ~ means the end of the song and the # means the end of the file :p
Quote:
U2~
With or Without You~
See the stone set in your eyes
See the thorn twist in your side
I wait for you
Slight of hand and twist of fate
On a bed of nails she makes me wait
And I wait....without you
With or without you
With or without you
Through the storm we reach the shore
You give it all but I want more
And I'm waiting for you
With or without you
With or without you
I can't live
With or without you
And you give yourself away
And you give yourself away
And you give
And you give
And you give yourself away
My hands are tied
My body bruised, she's got me with
Nothing left to win
And nothing else to lose
With or without you
With or without you
I can't live
With or without you
~
#
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sun 22 Dec 2002 10:51 PM (UTC) |
| Message
| Your problem is with this line:
song_table[count].lyrics[lines] = fread_line(fp);
You are copying a pointer, not what it is pointing to. If you look at fread_line it returns a pointer to a static piece of memory. Each subsequent read will overwrite that piece of memory so your array will be full of the same pointer to the memory in fread_line, namely:
static char line[MAX_STRING_LENGTH];
Something like this is required, although I am just typing it, not testing it ...
(more declarations)
char * lyric;
(replace processing above)
/* read the line */
lyric = fread_line(fp);
/* allocate memory in song table, add 1 to allow for null at end */
CREATE (song_table[count].lyrics[lines] , char, strlen (lyric) + 1);
/* copy lyric into allocated memory */
strcpy (song_table[count].lyrics[lines] , lyric);
Later on when you have finished with the song table, you should use DISPOSE (song_table[count].lyrics[lines]); to free up the memory you allocated. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Typhon
USA (112 posts) Bio
|
| Date
| Reply #2 on Mon 23 Dec 2002 01:53 AM (UTC) |
| Message
| | worked like a charm.. if anyone wants the port ill clean it up and post it on my page :) | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,789 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top