int ch; 
int ch, k, orig_ch, layered; 
int play_event(MidiEvent *ev){    int ch;    int32 i, j, cet;    if(play_mode->flag & PF_MIDI_EVENT)	return play_mode->acntl(PM_REQ_MIDI, ev);    if(!(play_mode->flag & PF_PCM_STREAM))	return RC_NONE;    current_event = ev;    cet = MIDI_EVENT_TIME(ev);    if(ctl->verbosity >= VERB_DEBUG_SILLY)	ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,		  "Midi Event %d: %s %d %d %d", cet,		  event_name(ev->type), ev->channel, ev->a, ev->b);    if(cet > current_sample)    {	int rc;    if(midi_streaming!=0){    	if ( (cet - current_sample) * 1000 / play_mode->rate > stream_max_compute ) {			kill_all_voices();//			reset_voices();//			ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY, "play_event: discard %d samples", cet - current_sample);			current_sample = cet;		}    }	rc = compute_data(cet - current_sample);	ctl_mode_event(CTLE_REFRESH, 0, 0, 0);    if(rc == RC_JUMP)	{		ctl_timestamp();		return RC_NONE;	}	if(rc != RC_NONE)	    return rc;	} 	ch = ev->channel;    switch(ev->type)    {	/* MIDI Events */      case ME_NOTEOFF:	note_off(ev);	break;      case ME_NOTEON:	note_on(ev);	break;      case ME_KEYPRESSURE:	adjust_pressure(ev);	break;      case ME_PROGRAM:	midi_program_change(ch, ev->a);	ctl_prog_event(ch);	break;      case ME_CHANNEL_PRESSURE:	adjust_channel_pressure(ev);	break;      case ME_PITCHWHEEL:	channel[ch].pitchbend = ev->a + ev->b * 128;	channel[ch].pitchfactor = 0;	/* Adjust pitch for notes already playing */	adjust_pitch(ch);	ctl_mode_event(CTLE_PITCH_BEND, 1, ch, channel[ch].pitchbend);	break;	/* Controls */      case ME_TONE_BANK_MSB:	channel[ch].bank_msb = ev->a;	break;      case ME_TONE_BANK_LSB:	channel[ch].bank_lsb = ev->a;	break;      case ME_MODULATION_WHEEL:	channel[ch].modulation_wheel =	    midi_cnv_vib_depth(ev->a);	update_modulation_wheel(ch, channel[ch].modulation_wheel);	ctl_mode_event(CTLE_MOD_WHEEL, 1, ch, channel[ch].modulation_wheel);	break;      case ME_MAINVOLUME:	channel[ch].volume = ev->a;	adjust_volume(ch);	ctl_mode_event(CTLE_VOLUME, 1, ch, ev->a);	break;      case ME_PAN:	channel[ch].panning = ev->a;	channel[ch].pan_random = 0;	if(adjust_panning_immediately && !channel[ch].pan_random)	    adjust_panning(ch);	ctl_mode_event(CTLE_PANNING, 1, ch, ev->a);	break;      case ME_EXPRESSION:	channel[ch].expression = ev->a;	adjust_volume(ch);	ctl_mode_event(CTLE_EXPRESSION, 1, ch, ev->a);	break;      case ME_SUSTAIN:	channel[ch].sustain = (ev->a >= 64);	if(!ev->a)	    drop_sustain(ch);	ctl_mode_event(CTLE_SUSTAIN, 1, ch, ev->a >= 64);	break;      case ME_SOSTENUTO:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Sostenuto - this function is not supported.");	break;      case ME_LEGATO_FOOTSWITCH:    channel[ch].legato = (ev->a >= 64);	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Legato Footswitch (CH:%d VAL:%d)",ch,channel[ch].legato);	break;      case ME_HOLD2:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Hold2 - this function is not supported.");	break;      case ME_BREATH:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Breath - this function is not supported.");	break;      case ME_FOOT:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Foot - this function is not supported.");	break;      case ME_BALANCE:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Balance - this function is not supported.");	break;      case ME_PORTAMENTO_TIME_MSB:	channel[ch].portamento_time_msb = ev->a;	update_portamento_time(ch);	break;      case ME_PORTAMENTO_TIME_LSB:	channel[ch].portamento_time_lsb = ev->a;	update_portamento_time(ch);	break;      case ME_PORTAMENTO:	channel[ch].portamento = (ev->a >= 64);	if(!channel[ch].portamento)	    drop_portamento(ch);	break;	  case ME_SOFT_PEDAL:		  if(opt_lpf_def) {			  channel[ch].soft_pedal = ev->a;			  ctl->cmsg(CMSG_INFO,VERB_NOISY,"Soft Pedal (CH:%d VAL:%d)",ch,channel[ch].soft_pedal);		  }		  break;	  case ME_HARMONIC_CONTENT:		  if(opt_lpf_def) {			  channel[ch].param_resonance = ev->a - 64;			  ctl->cmsg(CMSG_INFO,VERB_NOISY,"Harmonic Content (CH:%d VAL:%d)",ch,channel[ch].param_resonance);		  }		  break;	  case ME_BRIGHTNESS:		  if(opt_lpf_def) {			  channel[ch].param_cutoff_freq = ev->a - 64;			  ctl->cmsg(CMSG_INFO,VERB_NOISY,"Brightness (CH:%d VAL:%d)",ch,channel[ch].param_cutoff_freq);		  }		  break;      case ME_DATA_ENTRY_MSB:	if(channel[ch].rpn_7f7f_flag) /* disable */	    break;	if((i = last_rpn_addr(ch)) >= 0)	{	    channel[ch].rpnmap[i] = ev->a;	    update_rpn_map(ch, i, 1);	}	break;      case ME_DATA_ENTRY_LSB:	if(channel[ch].rpn_7f7f_flag) /* disable */	    break;	/* Ignore */	channel[ch].nrpn = -1;	break;      case ME_REVERB_EFFECT:	if(opt_reverb_control)	{	    set_reverb_level(ch, ev->a);	    ctl_mode_event(CTLE_REVERB_EFFECT, 1, ch, get_reverb_level(ch));	}	break;      case ME_CHORUS_EFFECT:	if(opt_chorus_control)	{	    if(opt_chorus_control == 1)		channel[ch].chorus_level = ev->a;	    else		channel[ch].chorus_level = -opt_chorus_control;	    ctl_mode_event(CTLE_CHORUS_EFFECT, 1, ch, get_chorus_level(ch));		if(ev->a) {			ctl->cmsg(CMSG_INFO,VERB_NOISY,"Chorus Send (CH:%d LEVEL:%d)",ch,ev->a);		}	}	break;      case ME_TREMOLO_EFFECT:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Tremolo Send (CH:%d LEVEL:%d)",ch,ev->a);	break;      case ME_CELESTE_EFFECT:	if(opt_delay_control) {		channel[ch].delay_level = ev->a;		ctl->cmsg(CMSG_INFO,VERB_NOISY,"Delay Send (CH:%d LEVEL:%d)",ch,ev->a);	}	break;	  case ME_ATTACK_TIME:  	if(!opt_tva_attack) { break; }	set_envelope_time(ch,ev->a,0);	break;	  case ME_RELEASE_TIME:  	if(!opt_tva_release) { break; }	set_envelope_time(ch,ev->a,3);	break;      case ME_PHASER_EFFECT:	ctl->cmsg(CMSG_INFO,VERB_NOISY,"Phaser Send (CH:%d LEVEL:%d)",ch,ev->a);	break;      case ME_RPN_INC:	if(channel[ch].rpn_7f7f_flag) /* disable */	    break;	if((i = last_rpn_addr(ch)) >= 0)	{	    if(channel[ch].rpnmap[i] < 127)		channel[ch].rpnmap[i]++;	    update_rpn_map(ch, i, 1);	}	break;      case ME_RPN_DEC:	if(channel[ch].rpn_7f7f_flag) /* disable */	    break;	if((i = last_rpn_addr(ch)) >= 0)	{	    if(channel[ch].rpnmap[i] > 0)		channel[ch].rpnmap[i]--;	    update_rpn_map(ch, i, 1);	}	break;      case ME_NRPN_LSB:	channel[ch].lastlrpn = ev->a;	channel[ch].nrpn = 1;	break;      case ME_NRPN_MSB:	channel[ch].lastmrpn = ev->a;	channel[ch].nrpn = 1;	break;      case ME_RPN_LSB:	channel[ch].lastlrpn = ev->a;	channel[ch].nrpn = 0;	break;      case ME_RPN_MSB:	channel[ch].lastmrpn = ev->a;	channel[ch].nrpn = 0;	break;      case ME_ALL_SOUNDS_OFF:	all_sounds_off(ch);	break;      case ME_RESET_CONTROLLERS:	reset_controllers(ch);	redraw_controllers(ch);	break;      case ME_ALL_NOTES_OFF:	all_notes_off(ch);	break;      case ME_MONO:	channel[ch].mono = 1;	all_notes_off(ch);	break;      case ME_POLY:	channel[ch].mono = 0;	all_notes_off(ch);	break;	/* TiMidity Extensionals */      case ME_RANDOM_PAN:	channel[ch].panning = int_rand(128);	channel[ch].pan_random = 1;	if(adjust_panning_immediately && !channel[ch].pan_random)	    adjust_panning(ch);	break;      case ME_SET_PATCH:	i = channel[ch].special_sample = current_event->a;	if(special_patch[i] != NULL)	    special_patch[i]->sample_offset = 0;	ctl_prog_event(ch);	break;      case ME_TEMPO:	current_play_tempo = ch + ev->b * 256 + ev->a * 65536;	ctl_mode_event(CTLE_TEMPO, 1, current_play_tempo, 0);	break;      case ME_CHORUS_TEXT:      case ME_LYRIC:      case ME_MARKER:      case ME_INSERT_TEXT:      case ME_TEXT:      case ME_KARAOKE_LYRIC:	i = ev->a | ((int)ev->b << 8);	ctl_mode_event(CTLE_LYRIC, 1, i, 0);	break;      case ME_GSLCD:	i = ev->a | ((int)ev->b << 8);	ctl_mode_event(CTLE_GSLCD, 1, i, 0);	break;      case ME_MASTER_VOLUME:	master_volume_ratio = (int32)ev->a + 256 * (int32)ev->b;	adjust_master_volume();	break;      case ME_RESET:	change_system_mode(ev->a);	reset_midi(1);	break;      case ME_PATCH_OFFS:	i = channel[ch].special_sample;	if(special_patch[i] != NULL)	    special_patch[i]->sample_offset =		(current_event->a | 256 * current_event->b);	break;      case ME_WRD:	push_midi_trace2(wrd_midi_event,			 ch, current_event->a | (current_event->b << 8));	break;      case ME_SHERRY:	push_midi_trace1(wrd_sherry_event,			 ch | (current_event->a<<8) | (current_event->b<<16));	break;      case ME_DRUMPART:	if(midi_drumpart_change(ch, current_event->a))	{	    /* Update bank information */	    midi_program_change(ch, channel[ch].program);	    ctl_mode_event(CTLE_DRUMPART, 1, ch, ISDRUMCHANNEL(ch));	    ctl_prog_event(ch);	}	break;      case ME_KEYSHIFT:	i = (int)current_event->a - 0x40;	if(i != channel[ch].key_shift)	{	    all_sounds_off(ch);	    channel[ch].key_shift = (int8)i;	}	break;	case ME_KEYSIG:		current_keysig = current_event->a + current_event->b * 16;		ctl_mode_event(CTLE_KEYSIG, 1, current_keysig, 0);		current_temper_keysig = current_keysig;		ctl_mode_event(CTLE_TEMPER_KEYSIG, 1, current_temper_keysig, 0);		if (opt_force_keysig != 8) {			i = current_keysig + ((current_keysig < 8) ? 7 : -6);			note_key_offset -= floor(note_key_offset / 12.0) * 12;			for (j = 0; j < note_key_offset; j++)				i += (i > 10) ? -5 : 7;			j = opt_force_keysig + ((current_keysig < 8) ? 7 : 10);			while (i != j && i != j + 12) {				if (++note_key_offset > 6)					note_key_offset -= 12;				i += (i > 10) ? -5 : 7;			}			kill_all_voices();			ctl_mode_event(CTLE_KEY_OFFSET, 1, note_key_offset, 0);		}		i = current_keysig + ((current_keysig < 8) ? 7 : -9), j = 0;		while (i != 7 && i != 19)			i += (i < 7) ? 5 : -7, j++;		j += note_key_offset, j -= floor(j / 12.0) * 12;		current_freq_table = j;		break;	case ME_SCALE_TUNING:		resamp_cache_refer_alloff(ch, current_event->time);		channel[ch].scale_tuning[current_event->a] = current_event->b;		adjust_pitch(ch);		break;	case ME_TEMPER_KEYSIG:		current_temper_keysig = current_event->a;		ctl_mode_event(CTLE_TEMPER_KEYSIG, 1, current_temper_keysig, 0);		i = current_temper_keysig + ((current_temper_keysig < 8) ? 7 : -9);		j = 0;		while (i != 7 && i != 19)			i += (i < 7) ? 5 : -7, j++;		j += note_key_offset, j -= floor(j / 12.0) * 12;		current_freq_table = j;		if (current_event->b)			for (i = 0; i < upper_voices; i++)				if (voice[i].status != VOICE_FREE) {					voice[i].temper_instant = 1;					recompute_freq(i);				}		break;	case ME_TEMPER_TYPE:		channel[ch].temper_type = current_event->a;		ctl_mode_event(CTLE_TEMPER_TYPE, 1, ch, channel[ch].temper_type);		if (temper_type_mute) {			if (temper_type_mute & 1 << current_event->a) {				SET_CHANNELMASK(channel_mute, ch);				ctl_mode_event(CTLE_MUTE, 1, ch, 1);			} else {				UNSET_CHANNELMASK(channel_mute, ch);				ctl_mode_event(CTLE_MUTE, 1, ch, 0);			}		}		if (current_event->b)			for (i = 0; i < upper_voices; i++)				if (voice[i].status != VOICE_FREE) {					voice[i].temper_instant = 1;					recompute_freq(i);				}		break;	case ME_MASTER_TEMPER_TYPE:		for (i = 0; i < MAX_CHANNELS; i++) {			channel[i].temper_type = current_event->a;			ctl_mode_event(CTLE_TEMPER_TYPE, 1, i, channel[i].temper_type);		}		if (temper_type_mute) {			if (temper_type_mute & 1 << current_event->a) {				FILL_CHANNELMASK(channel_mute);				for (i = 0; i < MAX_CHANNELS; i++)					ctl_mode_event(CTLE_MUTE, 1, i, 1);			} else {				CLEAR_CHANNELMASK(channel_mute);				for (i = 0; i < MAX_CHANNELS; i++)					ctl_mode_event(CTLE_MUTE, 1, i, 0);			}		}		if (current_event->b)			for (i = 0; i < upper_voices; i++)				if (voice[i].status != VOICE_FREE) {					voice[i].temper_instant = 1;					recompute_freq(i);				}		break;	case ME_SYSEX_LSB:		process_sysex_event(ME_SYSEX_LSB,ch,current_event->a,current_event->b);	    break;	case ME_SYSEX_MSB:		process_sysex_event(ME_SYSEX_MSB,ch,current_event->a,current_event->b);	    break;	case ME_SYSEX_GS_LSB:		process_sysex_event(ME_SYSEX_GS_LSB,ch,current_event->a,current_event->b);	    break;	case ME_SYSEX_GS_MSB:		process_sysex_event(ME_SYSEX_GS_MSB,ch,current_event->a,current_event->b);	    break;	case ME_SYSEX_XG_LSB:		process_sysex_event(ME_SYSEX_XG_LSB,ch,current_event->a,current_event->b);	    break;	case ME_SYSEX_XG_MSB:		process_sysex_event(ME_SYSEX_XG_MSB,ch,current_event->a,current_event->b);	    break;	case ME_NOTE_STEP:		i = ev->a + ((ev->b & 0x0f) << 8);		j = ev->b >> 4;		ctl_mode_event(CTLE_METRONOME, 1, i, j);		if (readmidi_wrd_mode)			wrdt->update_events();		break;      case ME_EOT:	return midi_play_end();    }    return RC_NONE;}
4357	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4357/a8bbef53d53be7361bcc8743932fd7879d07f0af/playmidi.c/clean/timidity/playmidi.c