current_temper_freq_table += val; current_temper_freq_table -= floor(current_temper_freq_table / 12.0) * 12; 
static int apply_controls(void){    int rc, i, jump_flag = 0;    int32 val, cur;    FLOAT_T r;    ChannelBitMask tmp_chbitmask;    /* ASCII renditions of CD player pictograms indicate approximate effect */    do    {	switch(rc=ctl->read(&val))	{	  case RC_STOP:	  case RC_QUIT:		/* [] */	  case RC_LOAD_FILE:	  case RC_NEXT:		/* >>| */	  case RC_REALLY_PREVIOUS: /* |<< */	  case RC_TUNE_END:	/* skip */	    aq_flush(1);	    return rc;	  case RC_CHANGE_VOLUME:	    if (val>0 || amplification > -val)		amplification += val;	    else		amplification=0;	    if (amplification > MAX_AMPLIFICATION)		amplification=MAX_AMPLIFICATION;	    adjust_amplification();	    for (i=0; i<upper_voices; i++)		if (voice[i].status != VOICE_FREE)		{		    recompute_amp(i);		    apply_envelope_to_amp(i);		}	    ctl_mode_event(CTLE_MASTER_VOLUME, 0, amplification, 0);	    continue;	  case RC_CHANGE_REV_EFFB:	  case RC_CHANGE_REV_TIME:	    reverb_rc_event(rc, val);	    sync_restart(0);	    continue;	  case RC_PREVIOUS:	/* |<< */	    aq_flush(1);	    if (current_sample < 2*play_mode->rate)		return RC_REALLY_PREVIOUS;	    return RC_RESTART;	  case RC_RESTART:	/* |<< */	    if(play_pause_flag)	    {		midi_restart_time = 0;		ctl_pause_event(1, 0);		continue;	    }	    aq_flush(1);	    skip_to(0);	    ctl_updatetime(0);	    jump_flag = 1;		midi_restart_time = 0;	    continue;	  case RC_JUMP:	    if(play_pause_flag)	    {		midi_restart_time = val;		ctl_pause_event(1, val);		continue;	    }	    aq_flush(1);	    if (val >= sample_count)		return RC_TUNE_END;	    skip_to(val);	    ctl_updatetime(val);	    return rc;	  case RC_FORWARD:	/* >> */	    if(play_pause_flag)	    {		midi_restart_time += val;		if(midi_restart_time > sample_count)		    midi_restart_time = sample_count;		ctl_pause_event(1, midi_restart_time);		continue;	    }	    cur = current_trace_samples();	    aq_flush(1);	    if(cur == -1)		cur = current_sample;	    if(val + cur >= sample_count)		return RC_TUNE_END;	    skip_to(val + cur);	    ctl_updatetime(val + cur);	    return RC_JUMP;	  case RC_BACK:		/* << */	    if(play_pause_flag)	    {		midi_restart_time -= val;		if(midi_restart_time < 0)		    midi_restart_time = 0;		ctl_pause_event(1, midi_restart_time);		continue;	    }	    cur = current_trace_samples();	    aq_flush(1);	    if(cur == -1)		cur = current_sample;	    if(cur > val)	    {		skip_to(cur - val);		ctl_updatetime(cur - val);	    }	    else	    {		skip_to(0);		ctl_updatetime(0);		midi_restart_time = 0;	    }	    return RC_JUMP;	  case RC_TOGGLE_PAUSE:	    if(play_pause_flag)	    {		play_pause_flag = 0;		skip_to(midi_restart_time);	    }	    else	    {		midi_restart_time = current_trace_samples();		if(midi_restart_time == -1)		    midi_restart_time = current_sample;		aq_flush(1);		play_pause_flag = 1;	    }	    ctl_pause_event(play_pause_flag, midi_restart_time);	    jump_flag = 1;	    continue;	  case RC_KEYUP:	  case RC_KEYDOWN:	    note_key_offset += val;	    current_freq_table += val;	    current_freq_table -= floor(current_freq_table / 12.0) * 12;	    if(sync_restart(1) != -1)		jump_flag = 1;	    ctl_mode_event(CTLE_KEY_OFFSET, 0, note_key_offset, 0);	    continue;	  case RC_SPEEDUP:	    r = 1.0;	    for(i = 0; i < val; i++)		r *= SPEED_CHANGE_RATE;	    sync_restart(0);	    midi_time_ratio /= r;	    current_sample = (int32)(current_sample / r + 0.5);	    trace_offset(current_sample);	    jump_flag = 1;	    ctl_mode_event(CTLE_TIME_RATIO, 0, 100 / midi_time_ratio + 0.5, 0);	    continue;	  case RC_SPEEDDOWN:	    r = 1.0;	    for(i = 0; i < val; i++)		r *= SPEED_CHANGE_RATE;	    sync_restart(0);	    midi_time_ratio *= r;	    current_sample = (int32)(current_sample * r + 0.5);	    trace_offset(current_sample);	    jump_flag = 1;	    ctl_mode_event(CTLE_TIME_RATIO, 0, 100 / midi_time_ratio + 0.5, 0);	    continue;	  case RC_VOICEINCR:	    restore_voices(0);	    voice_increment(val);	    if(sync_restart(1) != -1)		jump_flag = 1;	    restore_voices(1);	    continue;	  case RC_VOICEDECR:	    restore_voices(0);	    if(sync_restart(1) != -1)	    {		voices -= val;		if(voices < 0)		    voices = 0;		jump_flag = 1;	    }	    else		voice_decrement(val);	    restore_voices(1);	    continue;	  case RC_TOGGLE_DRUMCHAN:	    midi_restart_time = current_trace_samples();	    if(midi_restart_time == -1)		midi_restart_time = current_sample;	    SET_CHANNELMASK(drumchannel_mask, val);	    SET_CHANNELMASK(current_file_info->drumchannel_mask, val);	    if(IS_SET_CHANNELMASK(drumchannels, val))	    {		UNSET_CHANNELMASK(drumchannels, val);		UNSET_CHANNELMASK(current_file_info->drumchannels, val);	    }	    else	    {		SET_CHANNELMASK(drumchannels, val);		SET_CHANNELMASK(current_file_info->drumchannels, val);	    }	    aq_flush(1);	    return RC_RELOAD;	  case RC_TOGGLE_SNDSPEC:#ifdef SUPPORT_SOUNDSPEC	    if(view_soundspec_flag)		close_soundspec();	    else		open_soundspec();	    if(view_soundspec_flag || ctl_speana_flag)	    {		sync_restart(0);		soundspec_update_wave(NULL, -1);	    }#endif /* SUPPORT_SOUNDSPEC */	    continue;	  case RC_TOGGLE_CTL_SPEANA:#ifdef SUPPORT_SOUNDSPEC	    ctl_speana_flag = !ctl_speana_flag;	    if(view_soundspec_flag || ctl_speana_flag)	    {		sync_restart(0);		soundspec_update_wave(NULL, -1);	    }#endif /* SUPPORT_SOUNDSPEC */	    continue;	  case RC_SYNC_RESTART:	    sync_restart(val);	    jump_flag = 1;	    continue;	  case RC_RELOAD:	    midi_restart_time = current_trace_samples();	    if(midi_restart_time == -1)		midi_restart_time = current_sample;	    aq_flush(1);	    return RC_RELOAD;	  case RC_CHANGE_RATE:	    if(playmidi_change_rate(val, 1))		return RC_NONE;	    return RC_RELOAD;	  case RC_OUTPUT_CHANGED:	    playmidi_output_changed(0);	    return RC_RELOAD;	case RC_TOGGLE_MUTE:		TOGGLE_CHANNELMASK(channel_mute, val);		sync_restart(0);		jump_flag = 1;		ctl_mode_event(CTLE_MUTE, 0,				val, (IS_SET_CHANNELMASK(channel_mute, val)) ? 1 : 0);		continue;	case RC_SOLO_PLAY:		COPY_CHANNELMASK(tmp_chbitmask, channel_mute);		FILL_CHANNELMASK(channel_mute);		UNSET_CHANNELMASK(channel_mute, val);		if (! COMPARE_CHANNELMASK(tmp_chbitmask, channel_mute)) {			sync_restart(0);			jump_flag = 1;			for (i = 0; i < MAX_CHANNELS; i++)				ctl_mode_event(CTLE_MUTE, 0, i, 1);			ctl_mode_event(CTLE_MUTE, 0, val, 0);		}		continue;	case RC_MUTE_CLEAR:		COPY_CHANNELMASK(tmp_chbitmask, channel_mute);		CLEAR_CHANNELMASK(channel_mute);		if (! COMPARE_CHANNELMASK(tmp_chbitmask, channel_mute)) {			sync_restart(0);			jump_flag = 1;			for (i = 0; i < MAX_CHANNELS; i++)				ctl_mode_event(CTLE_MUTE, 0, i, 0);		}		continue;	}	if(intr)	    return RC_QUIT;	if(play_pause_flag)	    usleep(300000);    } while (rc != RC_NONE || play_pause_flag);    return jump_flag ? RC_JUMP : RC_NONE;}
4357	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4357/be2587e8bb89ff84d682bb5ecc8e1e15873bf349/playmidi.c/buggy/timidity/playmidi.c