tempo= meep->event.channel + meep->event.b * 256 + meep->event.a * 65536; compute_sample_increment(tempo, divisions); 
static MidiEvent *groom_list(int32 divisions,int32 *eventsp,int32 *samplesp){  MidiEvent *groomed_list, *lp;  MidiEventList *meep;  int32 i, our_event_count, tempo, skip_this_event, new_value;  int32 sample_cum, samples_to_do, at, st, dt, counting_time;  int current_bank[16], current_set[16], current_program[16];   /* Or should each bank have its own current program? */  for (i=0; i<16; i++)    {      current_bank[i]=0;      current_set[i]=0;      current_program[i]=default_program;    }  tempo=500000;  compute_sample_increment(tempo, divisions);  /* This may allocate a bit more than we need */  groomed_list=lp=safe_malloc(sizeof(MidiEvent) * (event_count+1));  meep=evlist;  our_event_count=0;  st=at=sample_cum=0;  counting_time=2; /* We strip any silence before the first NOTE ON. */  for (i=0; i<event_count; i++)    {      skip_this_event=0;      ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,		"%6d: ch %2d: event %d (%d,%d)",		meep->event.time, meep->event.channel + 1,		meep->event.type, meep->event.a, meep->event.b);      if (meep->event.type==ME_TEMPO)	{	  tempo=	    meep->event.channel + meep->event.b * 256 + meep->event.a * 65536;	  compute_sample_increment(tempo, divisions);	  skip_this_event=1;	}      else if ((quietchannels & (1<<meep->event.channel)))	skip_this_event=1;      else switch (meep->event.type)	{	case ME_PROGRAM:	  if (ISDRUMCHANNEL(meep->event.channel))	    {	      if (drumset[meep->event.a]) /* Is this a defined drumset? */		new_value=meep->event.a;	      else		{		  ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,		       "Drum set %d is undefined", meep->event.a);		  new_value=meep->event.a=0;		}	      if (current_set[meep->event.channel] != new_value)		current_set[meep->event.channel]=new_value;	      else 		skip_this_event=1;	    }	  else	    {	      new_value=meep->event.a;	      if ((current_program[meep->event.channel] != SPECIAL_PROGRAM)		  && (current_program[meep->event.channel] != new_value))		current_program[meep->event.channel] = new_value;	      else		skip_this_event=1;	    }	  break;	case ME_NOTEON:	  if (counting_time)	    counting_time=1;	  if (ISDRUMCHANNEL(meep->event.channel))	    {	      /* Mark this instrument to be loaded */	      if (!(drumset[current_set[meep->event.channel]]		    ->tone[meep->event.a].instrument))		drumset[current_set[meep->event.channel]]		  ->tone[meep->event.a].instrument=		    MAGIC_LOAD_INSTRUMENT;	    }	  else	    {	      if (current_program[meep->event.channel]==SPECIAL_PROGRAM)		break;	      /* Mark this instrument to be loaded */	      if (!(tonebank[current_bank[meep->event.channel]]		    ->tone[current_program[meep->event.channel]].instrument))		tonebank[current_bank[meep->event.channel]]		  ->tone[current_program[meep->event.channel]].instrument=		    MAGIC_LOAD_INSTRUMENT;	    }	  break;	case ME_TONE_BANK:	  if (ISDRUMCHANNEL(meep->event.channel))	    {	      skip_this_event=1;	      break;	    }	  if (tonebank[meep->event.a]) /* Is this a defined tone bank? */	    new_value=meep->event.a;	  else 	    {	      ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,		   "Tone bank %d is undefined", meep->event.a);	      new_value=meep->event.a=0;	    }	  if (current_bank[meep->event.channel]!=new_value)	    current_bank[meep->event.channel]=new_value;	  else	    skip_this_event=1;	  break;	}      /* Recompute time in samples*/      if ((dt=meep->event.time - at) && !counting_time)	{	  samples_to_do=sample_increment * dt;	  sample_cum += sample_correction * dt;	  if (sample_cum & 0xFFFF0000)	    {	      samples_to_do += ((sample_cum >> 16) & 0xFFFF);	      sample_cum &= 0x0000FFFF;	    }	  st += samples_to_do;	}      else if (counting_time==1) counting_time=0;      if (!skip_this_event)	{	  /* Add the event to the list */	  *lp=meep->event;	  lp->time=st;	  lp++;	  our_event_count++;	}      at=meep->event.time;      meep=meep->next;    }  /* Add an End-of-Track event */  lp->time=st;  lp->type=ME_EOT;  our_event_count++;  free_midi_list();    *eventsp=our_event_count;  *samplesp=st;  return groomed_list;}
4357	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4357/cb293c4705e0c7b93d3269c59bcf9bbcab7f6278/readmidi.c/buggy/readmidi.c