MIDIEVENT_LAYER(smf_at_time, ME_KEYPRESSURE, lastchan, a, b); 
MIDIEVENT(smf_at_time, ME_KEYPRESSURE, lastchan, a, b); 
static int read_smf_track(struct timidity_file *tf, int trackno, int rewindp){    int32 len, next_pos, pos;    char tmp[4];    int lastchan, laststatus;    int me, type, a, b, c;    int i;    int32 smf_at_time;    smf_at_time = readmidi_set_track(trackno, rewindp);    /* Check the formalities */    if((tf_read(tmp, 1, 4, tf) != 4) || (tf_read(&len, 4, 1, tf) != 1))    {	ctl->cmsg(CMSG_ERROR, VERB_NORMAL,		  "%s: Can't read track header.", current_filename);	return -1;    }    len = BE_LONG(len);    next_pos = tf_tell(tf) + len;    if(strncmp(tmp, "MTrk", 4))    {	ctl->cmsg(CMSG_ERROR, VERB_NORMAL,		  "%s: Corrupt MIDI file.", current_filename);	return -2;    }    lastchan = laststatus = 0;    for(;;)    {	if(readmidi_error_flag)	    return -1;	if((len = getvl(tf)) < 0)	    return -1;	smf_at_time += len;	errno = 0;	if((i = tf_getc(tf)) == EOF)	{	    if(errno)		ctl->cmsg(CMSG_ERROR, VERB_NORMAL,			  "%s: read_midi_event: %s",			  current_filename, strerror(errno));	    else		ctl->cmsg(CMSG_ERROR, VERB_NORMAL,			  "Warning: %s: Too shorten midi file.",			  current_filename);	    return -1;	}	me = (uint8)i;	if(me == 0xF0 || me == 0xF7) /* SysEx event */	{	    if((len = getvl(tf)) < 0)		return -1;	    if((i = read_sysex_event(smf_at_time, me, len, tf)) != 0)		return i;	}	else if(me == 0xFF) /* Meta event */	{	    type = tf_getc(tf);	    if((len = getvl(tf)) < 0)		return -1;	    if(type > 0 && type < 16)	    {		static char *label[] =		{		    "Text event: ", "Text: ", "Copyright: ", "Track name: ",		    "Instrument: ", "Lyric: ", "Marker: ", "Cue point: "		};		if(type == 5 || /* Lyric */		   (type == 1 && (opt_trace_text_meta_event ||				  karaoke_format == 2 ||				  chorus_status.status == CHORUS_ST_OK)) ||		   (type == 6 &&  (current_file_info->format == 0 ||				   (current_file_info->format == 1 &&				    current_read_track == 0))))		{		    char *str, *text;		    MidiEvent ev;		    str = (char *)new_segment(&tmpbuffer, len + 3);		    if(type != 6)		    {			i = tf_read(str, 1, len, tf);			str[len] = '\0';		    }		    else		    {			i = tf_read(str + 1, 1, len, tf);			str[0] = MARKER_START_CHAR;			str[len + 1] = MARKER_END_CHAR;			str[len + 2] = '\0';		    }		    if(i != len)		    {			ctl->cmsg(CMSG_ERROR, VERB_NORMAL,				  "Warning: %s: Too shorten midi file.",				  current_filename);			reuse_mblock(&tmpbuffer);			return -1;		    }		    if((text = readmidi_make_string_event(1, str, &ev, 1))		       == NULL)		    {			reuse_mblock(&tmpbuffer);			continue;		    }		    ev.time = smf_at_time;		    if(type == 6)		    {			if(strlen(fix_string(text + 1)) == 2)			{			    reuse_mblock(&tmpbuffer);			    continue; /* Empty Marker */			}		    }		    switch(type)		    {		      case 1:			if(karaoke_format == 2)			{			    *text = ME_KARAOKE_LYRIC;			    if(karaoke_title_flag == 0 &&			       strncmp(str, "@T", 2) == 0)				current_file_info->karaoke_title =				    add_karaoke_title(current_file_info->						      karaoke_title, str + 2);			    ev.type = ME_KARAOKE_LYRIC;			    readmidi_add_event(&ev);			    continue;			}			if(chorus_status.status == CHORUS_ST_OK)			{			    *text = ME_CHORUS_TEXT;			    ev.type = ME_CHORUS_TEXT;			    readmidi_add_event(&ev);			    continue;			}			*text = ME_TEXT;			ev.type = ME_TEXT;			readmidi_add_event(&ev);			continue;		      case 5:			*text = ME_LYRIC;			ev.type = ME_LYRIC;			readmidi_add_event(&ev);			continue;		      case 6:			*text = ME_MARKER;			ev.type = ME_MARKER;			readmidi_add_event(&ev);			continue;		    }		}		if(type == 3 && /* Sequence or Track Name */		   (current_file_info->format == 0 ||		    (current_file_info->format == 1 &&		     current_read_track == 0)))		{		  if(current_file_info->seq_name == NULL) {		    char *name = dumpstring(3, len, "Sequence: ", 1, tf);		    current_file_info->seq_name = safe_strdup(fix_string(name));		    free(name);		  }		    else			dumpstring(3, len, "Sequence: ", 0, tf);		}		else if(type == 1 &&			current_file_info->first_text == NULL &&			(current_file_info->format == 0 ||			 (current_file_info->format == 1 &&			  current_read_track == 0))) {		  char *name = dumpstring(1, len, "Text: ", 1, tf);		  current_file_info->first_text = safe_strdup(fix_string(name));		  free(name);		}		else		    dumpstring(type, len, label[(type>7) ? 0 : type], 0, tf);	    }	    else	    {		switch(type)		{		  case 0x00:		    if(len == 2)		    {			a = tf_getc(tf);			b = tf_getc(tf);			ctl->cmsg(CMSG_INFO, VERB_DEBUG,				  "(Sequence Number %02x %02x)", a, b);		    }		    else			ctl->cmsg(CMSG_INFO, VERB_DEBUG,				  "(Sequence Number len=%d)", len);		    break;		  case 0x2F: /* End of Track */		    pos = tf_tell(tf);		    if(pos < next_pos)			tf_seek(tf, next_pos - pos, SEEK_CUR);		    return 0;		  case 0x51: /* Tempo */		    a = tf_getc(tf);		    b = tf_getc(tf);		    c = tf_getc(tf);		    MIDIEVENT(smf_at_time, ME_TEMPO, c, a, b);		    break;		  case 0x54:		    /* SMPTE Offset (hr mn se fr ff)		     * hr: hours&type		     *     0     1     2     3    4    5    6    7   bits		     *     0  |<--type -->|<---- hours [0..23]---->|		     * type: 00: 24 frames/second		     *       01: 25 frames/second		     *       10: 30 frames/second (drop frame)		     *       11: 30 frames/second (non-drop frame)		     * mn: minis [0..59]		     * se: seconds [0..59]		     * fr: frames [0..29]		     * ff: fractional frames [0..99]		     */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(SMPTE Offset meta event)");		    skip(tf, len);		    break;		  case 0x58: /* Time Signature */		    smf_time_signature(smf_at_time, tf, len);		    break;		  case 0x59: /* Key Signature */		    smf_key_signature(smf_at_time, tf, len);		    break;		  case 0x7f: /* Sequencer-Specific Meta-Event */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sequencer-Specific meta event, length %ld)",			      len);		    skip(tf, len);		    break;		  case 0x20: /* MIDI channel prefix (SMF v1.0) */		    if(len == 1)		    {			int midi_channel_prefix = tf_getc(tf);			ctl->cmsg(CMSG_INFO, VERB_DEBUG,				  "(MIDI channel prefix %d)",				  midi_channel_prefix);		    }		    else			skip(tf, len);		    break;		  case 0x21: /* MIDI port number */		    if(len == 1)		    {			if((midi_port_number = tf_getc(tf))			   == EOF)			{			    ctl->cmsg(CMSG_ERROR, VERB_NORMAL,				      "Warning: %s: Too shorten midi file.",				      current_filename);			    return -1;			}			midi_port_number &= 0xF;			ctl->cmsg(CMSG_INFO, VERB_DEBUG,				  "(MIDI port number %d)", midi_port_number);		    }		    else			skip(tf, len);		    break;		  default:		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Meta event type 0x%02x, length %ld)",			      type, len);		    skip(tf, len);		    break;		}	    }	}	else /* MIDI event */	{	    a = me;	    if(a & 0x80) /* status byte */	    {		lastchan = MERGE_CHANNEL_PORT(a & 0x0F);		laststatus = (a >> 4) & 0x07;		if(laststatus != 7)		    a = tf_getc(tf) & 0x7F;	    }	    switch(laststatus)	    {	      case 0: /* Note off */		b = tf_getc(tf) & 0x7F;		MIDIEVENT_LAYER(smf_at_time, ME_NOTEOFF, lastchan, a,b);		break;	      case 1: /* Note on */		b = tf_getc(tf) & 0x7F;		if(b)		{		    MIDIEVENT_LAYER(smf_at_time, ME_NOTEON, lastchan, a,b);		}		else /* b == 0 means Note Off */		{		    MIDIEVENT_LAYER(smf_at_time, ME_NOTEOFF, lastchan, a, 0);		}		break;	      case 2: /* Key Pressure */		b = tf_getc(tf) & 0x7F;		MIDIEVENT_LAYER(smf_at_time, ME_KEYPRESSURE, lastchan, a, b);		break;	      case 3: /* Control change */		b = tf_getc(tf);		readmidi_add_ctl_event_layer(smf_at_time, lastchan, a, b);		break;	      case 4: /* Program change */		MIDIEVENT_LAYER(smf_at_time, ME_PROGRAM, lastchan, a, 0);		break;	      case 5: /* Channel pressure */		MIDIEVENT_LAYER(smf_at_time, ME_CHANNEL_PRESSURE, lastchan, a, 0);		break;	      case 6: /* Pitch wheel */		b = tf_getc(tf) & 0x7F;		MIDIEVENT_LAYER(smf_at_time, ME_PITCHWHEEL, lastchan, a, b);		break;	      default: /* case 7: */		/* Ignore this event */		switch(lastchan & 0xF)		{		  case 2: /* Sys Com Song Position Pntr */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys Com Song Position Pntr)");		    tf_getc(tf);		    tf_getc(tf);		    break;		  case 3: /* Sys Com Song Select(Song #) */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys Com Song Select(Song #))");		    tf_getc(tf);		    break;		  case 6: /* Sys Com tune request */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys Com tune request)");		    break;		  case 8: /* Sys real time timing clock */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys real time timing clock)");		    break;		  case 10: /* Sys real time start */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys real time start)");		    break;		  case 11: /* Sys real time continue */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys real time continue)");		    break;		  case 12: /* Sys real time stop */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys real time stop)");		    break;		  case 14: /* Sys real time active sensing */		    ctl->cmsg(CMSG_INFO, VERB_DEBUG,			      "(Sys real time active sensing)");		    break;#if 0		  case 15: /* Meta */		  case 0: /* SysEx */		  case 7: /* SysEx */#endif		  default: /* 1, 4, 5, 9, 13 */		    ctl->cmsg(CMSG_ERROR, VERB_NORMAL,			      "*** Can't happen: status 0x%02X channel 0x%02X",			      laststatus, lastchan & 0xF);		    break;		}		}	}    }    /*NOTREACHED*/}
4357	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4357/a8bbef53d53be7361bcc8743932fd7879d07f0af/readmidi.c/buggy/timidity/readmidi.c