Author Topic: MIDITest: Question about the Lyrics code  (Read 173 times)

KaleidonKep99

  • Posts: 150
MIDITest: Question about the Lyrics code
« on: 3 Aug '17 - 08:21 »
Hello Un4seen community. ;D

I've been trying to convert this code snippet to C#, but the only thing I got was were AccessViolationException and IndexOutOfRangeException exceptions.

Here's the original C code:
Code: [Select]
BASS_MIDI_MARK mark;
const char *text;
char *p;
int lines;
BASS_MIDI_StreamGetMark(channel,(DWORD)user,data,&mark); // get the lyric/text
text=mark.text;
if (text[0]=='@') return; // skip info
if (text[0]=='\\') { // clear display
p=lyrics;
text++;
} else {
p=lyrics+strlen(lyrics);
if (text[0]=='/') { // new line
*p++='\n';
text++;
}
}
sprintf(p,"%.*s",lyrics+sizeof(lyrics)-p-1,text); // add the text to the lyrics buffer
for (lines=1,p=lyrics;p=strchr(p,'\n');lines++,p++) ; // count lines
if (lines>3) { // remove old lines so that new lines fit in display...
int a;
for (a=0,p=lyrics;a<lines-3;a++) p=strchr(p,'\n')+1;
strcpy(lyrics,p);
}
MESS(30,WM_SETTEXT,0,lyrics);

Here's my code:
Code: [Select]
        private void LyricSync(int handle, int channel, int data, IntPtr user)
        {
            BASS_MIDI_MARK mark = new BASS_MIDI_MARK();
            string text;
            string p;
            int lines;
            BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_LYRIC, data, mark);
            text = mark.text;
            if (text[0] == '@')
            {
                return; // skip info
            }
            if (text[0] == '\\')
            { // clear display
                p = lyrics;
                text = text.Substring(1);
            }
            else
            {
                p = lyrics + lyrics.Length;
                if (text[0] == '/')
                { // new line
                    p += '\n';
                    text = text.Substring(1);
                }
            }

            lines = p.Split('\n').Length;
            if (lines > 3)
            { // remove old lines so that new lines fit in display...
                int a;
                for (a = 0, p = lyrics; a < lines - 3; a++)
                {
                    p = p.Substring(p.IndexOf('\n') + 1);
                }
                lyrics = p;
            }
        }

Could someone help me find what the issue is?

Ian @ un4seen

  • Administrator
  • Posts: 20396
Re: MIDITest: Question about the Lyrics code
« Reply #1 on: 3 Aug '17 - 16:57 »
I'm not a C#/.Net user myself, so I probably can't help much with that, but to get a clue about what's wrong, which line(s) in the code are the exceptions happening on?