Index: smf.c =================================================================== RCS file: /midish/midish/smf.c,v retrieving revision 1.55 diff -u -r1.55 smf.c --- smf.c 13 Sep 2013 08:47:06 -0000 1.55 +++ smf.c 16 Nov 2013 15:15:37 -0000 @@ -167,6 +167,32 @@ return 1; } +/* + * read a variable length string of marker meta event, return 0 on error + */ +unsigned +smf_getmarkstr(struct smf *o, unsigned length, char *markname) +{ + int c, i; + char name[MAXMARKNAME]; + + if (length > MAXMARKNAME) { + length = MAXMARKNAME; + cons_err("Marker name is too long, truncated"); + } + for (i = 0; i < length; i++) { + if (o->index + 1 > o->length || (c = fgetc(o->file)) == EOF) { + cons_err("failed to read varlength number"); + return 0; + } + name[i] = c; + o->index++; + } + /* add missing NUL character at end of string */ + name[i] = '\0'; + markname = str_new(name); + return 1; +} /* * read a chunk header, compare it with ethe given 4-byte header and @@ -584,6 +610,7 @@ { unsigned delta, i, status, type, length, abspos; unsigned tempo, num, den, dummy; + char markerstr[MAXMARKNAME]; struct statelist slist; struct songsx *songsx; struct seqev *pos, *se; @@ -664,6 +691,25 @@ log_puts("\n"); */ goto putev; + } else if (type == 0x06) { + /* midi marker */ + ev.cmd = EV_MARK; + if (length > MAXMARKNAME) { + length = MAXMARKNAME; + cons_err("Marker name is too long, truncated"); + } + for (i = 0; i < length; i++) { + if (!smf_getc(o, &c)) { + goto err; + } + markerstr[i] = c; + } + /* add missing NUL character at end of string */ + markerstr[i] = '\0'; + c = evmark_getnb(); /* get index */ + evmark_tab[c] = str_new(markerstr); + ev.v0 = c; + goto putev; } else { ignoremeta: for (i = 0; i < length; i++) { @@ -908,6 +954,7 @@ o = song_new(); song_setunit(o, timecode * 4); /* timecode = tics per quarter */ + evmark_init(); /* empty markers list */ for (i = 0; i < ntrks; i++) { snprintf(trackname, MAXTRACKNAME, "trk%02u", i);