⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w32g_c.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 2 页
字号:
	Panel->key_offset = ko;	Panel->changed = 1;	ctl_panel_refresh();}static void ctl_tempo(int t, int tr){	static int lasttempo = CTL_STATUS_UPDATE;	static int lastratio = CTL_STATUS_UPDATE;		if (t == CTL_STATUS_UPDATE)		t = lasttempo;	else		lasttempo = t;	if (tr == CTL_STATUS_UPDATE)		tr = lastratio;	else		lastratio = tr;	t = (int) (500000 / (double) t * 120 * (double) tr / 100 + 0.5);	Panel->tempo = t;	Panel->tempo_ratio = tr;	Panel->changed = 1;	ctl_panel_refresh();}extern BOOL SetWrdWndActive(void);static void ctl_pass_playing_list(int number_of_files, char *list_of_files[]){	static int init_flag = 1;    int rc;    int32 value;    extern void timidity_init_aq_buff(void);    int errcnt;    w32g_add_playlist(number_of_files, list_of_files, 0,		      ctl.flags & CTLF_AUTOUNIQ,		      ctl.flags & CTLF_AUTOREFINE);    w32g_play_active = 0;    errcnt = 0;    if(init_flag && w32g_nvalid_playlist() && (ctl.flags & CTLF_AUTOSTART))//    if(play_mode->fd != -1 &&//       w32g_nvalid_playlist() && (ctl.flags & CTLF_AUTOSTART))	rc = RC_LOAD_FILE;    else	rc = RC_NONE;	init_flag = 0;#ifdef W32G_RANDOM_IS_SHUFFLE	w32g_shuffle_playlist_reset(0);#endif    while(1)    {	if(rc == RC_NONE)	{	    if(play_mode->fd != -1)	    {		aq_flush(1);		play_mode->close_output();	    }	    rc = w32g_get_rc(&value, 1);	}      redo:	switch(rc)	{	  case RC_NONE:	    Sleep(1000);	    break;	  case RC_LOAD_FILE: /* Play playlist.selected */	    if(w32g_nvalid_playlist())	    {		int selected;		w32g_get_playlist_index(&selected, NULL, NULL);		w32g_play_active = 1;		if(play_mode->fd == -1)		{		    if(play_mode->open_output() == -1)		    {			ctl.cmsg(CMSG_FATAL, VERB_NORMAL,				 "Couldn't open %s (`%c') %s",				 play_mode->id_name,				 play_mode->id_character,				 play_mode->name ? play_mode->name : "");			break;		    }		    aq_setup();		    timidity_init_aq_buff();		}		if(play_mode->id_character == 'l')		    w32g_show_console();		if(!DocWndIndependent){			w32g_setup_doc(selected);			if(DocWndAutoPopup)				w32g_open_doc(1);			else				w32g_open_doc(2);		}		{			char *p = w32g_get_playlist(selected);			if(Panel!=NULL && p!=NULL)                            strncpy(Panel->filename,p,sizeof(Panel->filename));		}		SetWrdWndActive();		rc = play_midi_file(w32g_get_playlist(selected));		if(ctl.flags & CTLF_NOT_CONTINUE)		    w32g_update_playlist(); /* Update mark of error */		if(rc == RC_ERROR)		{		    int nfiles;		    errcnt++;		    w32g_get_playlist_index(NULL, &nfiles, NULL);		    if(errcnt >= nfiles)			w32g_msg_box("No MIDI file to play",				     "TiMidity Warning", MB_OK);		}		else		    errcnt = 0;		w32g_play_active = 0;		goto redo;	    }	    break;	  case RC_ERROR:	  case RC_TUNE_END:#if 0	    if(play_mode->id_character != 'd' ||			(ctl.flags & CTLF_NOT_CONTINUE)) {#else		if(ctl.flags & CTLF_NOT_CONTINUE) {#endif			break;		}	    /* FALLTHROUGH */	  case RC_NEXT:	    if(!w32g_nvalid_playlist())	    {		if(ctl.flags & CTLF_AUTOEXIT) {		    if(play_mode->fd != -1)			aq_flush(0);		    return;		}		break;	    }			if(ctl.flags & CTLF_LIST_RANDOM) {#ifdef W32G_RANDOM_IS_SHUFFLE				if(w32g_shuffle_playlist_next(!(ctl.flags & CTLF_NOT_CONTINUE))) {#else				if(w32g_random_playlist(!(ctl.flags & CTLF_NOT_CONTINUE))) {#endif					rc = RC_LOAD_FILE;					goto redo;				}			} else {				if(w32g_next_playlist(!(ctl.flags & CTLF_NOT_CONTINUE))) {					rc = RC_LOAD_FILE;					goto redo;				}			}	    {		/* end of list */		if(ctl.flags & CTLF_AUTOEXIT){		    if(play_mode->fd != -1)			aq_flush(0);		    return;		}		if((ctl.flags & CTLF_LIST_LOOP) && w32g_nvalid_playlist())		{#ifdef W32G_RANDOM_IS_SHUFFLE			if(ctl.flags & CTLF_LIST_RANDOM) {				w32g_shuffle_playlist_reset(0);				w32g_shuffle_playlist_next(!(ctl.flags & CTLF_NOT_CONTINUE));			} else {#endif				w32g_first_playlist(!(ctl.flags & CTLF_NOT_CONTINUE));#ifdef W32G_RANDOM_IS_SHUFFLE			}#endif		    rc = RC_LOAD_FILE;		    goto redo;		}		if((ctl.flags & CTLF_LIST_RANDOM) && w32g_nvalid_playlist())			w32g_shuffle_playlist_reset(0);	    }	    break;	  case RC_REALLY_PREVIOUS:#ifdef W32G_RANDOM_IS_SHUFFLE		w32g_shuffle_playlist_reset(0);#endif	    if(w32g_prev_playlist(!(ctl.flags & CTLF_NOT_CONTINUE)))	    {		rc = RC_LOAD_FILE;		goto redo;	    }	    break;	  case RC_QUIT:	    if(play_mode->fd != -1)		aq_flush(1);	    return;	  case RC_CHANGE_VOLUME:	    amplification += value;	    ctl_master_volume(amplification);	    break;	  case RC_TOGGLE_PAUSE:	    play_pause_flag = !play_pause_flag;	    break;	  default:		if(rc == RC_STOP)#ifdef W32G_RANDOM_IS_SHUFFLE			w32g_shuffle_playlist_reset(0);#endif	    if(rc >= RC_EXT_BASE)	    {		rc = w32g_ext_control(rc, value);		if(rc != RC_NONE)		    goto redo;	    }	    break;	}	if(mark_apply_setting)	    PrefSettingApplyReally();	rc = RC_NONE;    }}static void ctl_lcd_mark(int flag, int x, int y){	Panel->GSLCD[x][y] = flag;}static void ctl_gslcd(int id){    char *lcd;    int i, j, k, data, mask;    char tmp[3];    if((lcd = event2string(id)) == NULL)	return;    if(lcd[0] != ME_GSLCD)	return;    lcd++;    for(i = 0; i < 16; i++)    {	for(j = 0; j < 4; j++)	{	    tmp[0]= lcd[2 * (j * 16 + i)];	    tmp[1]= lcd[2 * (j * 16 + i) + 1];	    if(sscanf(tmp, "%02X", &data) != 1)	    {		/* Invalid format */		return;	    }	    mask = 0x10;	    for(k = 0; k < 5; k++)	    {		if(data & mask)	{ctl_lcd_mark(1, j * 5 + k, i);}		else {ctl_lcd_mark(0, j * 5 + k, i);}		mask >>= 1;	    }	}    }	Panel->gslcd_displayed_flag = 1;	Panel->gslcd_last_display_time = get_current_calender_time();	Panel->changed = 1;}static void ctl_channel_note(int ch, int note, int vel){    if (vel == 0) {	if (note == Panel->cnote[ch])	    Panel->v_flags[ch] = FLAG_NOTE_OFF;   	Panel->cvel[ch] = 0;    } else if (vel > Panel->cvel[ch]) {	Panel->cvel[ch] = vel;	Panel->cnote[ch] = note;	Panel->ctotal[ch] = ( vel * Panel->channel[ch].volume *			     Panel->channel[ch].expression ) >> 14;//	   	Panel->channel[ch].expression / (127*127);	Panel->v_flags[ch] = FLAG_NOTE_ON;    }    Panel->changed = 1;}static void ctl_note(int status, int ch, int note, int vel){    int32 i, n;    if(!ctl.trace_playing)	return;    if(ch < 0 || ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(status != VOICE_ON)	vel = 0;    switch(status) {      case VOICE_SUSTAINED:      case VOICE_DIE:      case VOICE_FREE:      case VOICE_OFF:	n = note;	i = 0;	if(n<0) n = 0;	if(n>127) n = 127;	while(n >= 32){	    n -= 32;	    i++;	}	Panel->xnote[ch][i] &= ~(((int32)1) << n);	break;      case VOICE_ON:	n = note;	i = 0;	if(n<0) n = 0;	if(n>127) n = 127;	while(n >= 32){	    n -= 32;	    i++;	}	Panel->xnote[ch][i] |= ((int32)1) << n;	break;    }    ctl_channel_note(ch, note, vel);}static void ctl_volume(int ch, int val){    if(ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(!ctl.trace_playing)	return;    Panel->channel[ch].volume = val;    ctl_channel_note(ch, Panel->cnote[ch], Panel->cvel[ch]);}static void ctl_expression(int ch, int val){    if(ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(!ctl.trace_playing)	return;    Panel->channel[ch].expression = val;    ctl_channel_note(ch, Panel->cnote[ch], Panel->cvel[ch]);}static void ctl_current_time(int secs, int nvoices){    int32 centisecs = secs * 100;    Panel->cur_time = centisecs;    Panel->cur_time_h = centisecs/100/60/60;    centisecs %= 100*60*60;    Panel->cur_time_m = centisecs/100/60;    centisecs %= 100*60;    Panel->cur_time_s = centisecs/100;    centisecs %= 100;    Panel->cur_time_ss = centisecs;    Panel->cur_voices = nvoices;    Panel->changed = 1;}static void display_aq_ratio(void){    static int last_rate = -1;    int rate, devsiz;    if((devsiz = aq_get_dev_queuesize()) == 0)	return;    rate = (int)(((double)(aq_filled() + aq_soft_filled()) / devsiz)		 * 100 + 0.5);    if(rate > 999)	rate = 1000;    Panel->aq_ratio = rate;    if(last_rate != rate) {   	last_rate = Panel->aq_ratio = rate;	Panel->changed = 1;    }}static void ctl_total_time(int tt){    int32 centisecs = tt/(play_mode->rate/100);    Panel->total_time = centisecs;    Panel->total_time_h = centisecs/100/60/60;    centisecs %= 100*60*60;    Panel->total_time_m = centisecs/100/60;    centisecs %= 100*60;    Panel->total_time_s = centisecs/100;    centisecs %= 100;    Panel->total_time_ss = centisecs;    Panel->changed = 1;    ctl_current_time(0, 0);}static void ctl_program(int ch, int val){    if(ch < 0 || ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(!ctl.trace_playing)	return;    if(!IS_CURRENT_MOD_FILE)	val += progbase;    Panel->channel[ch].program = val;    Panel->c_flags[ch] |= FLAG_PROG;    Panel->changed = 1;}static void ctl_panning(int ch, int val){    if(ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(!ctl.trace_playing)	return;    Panel->channel[ch].panning = val;    Panel->c_flags[ch] |= FLAG_PAN;    Panel->changed = 1;}static void ctl_sustain(int ch, int val){    if(ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(!ctl.trace_playing)	return;    Panel->channel[ch].sustain = val;    Panel->c_flags[ch] |= FLAG_SUST;    Panel->changed = 1;}static void ctl_pitch_bend(int ch, int val){    if(ch >= MAX_W32G_MIDI_CHANNELS)	return;    if(!ctl.trace_playing)	return;    Panel->channel[ch].pitchbend = val;//    Panel->c_flags[ch] |= FLAG_BENDT;    Panel->changed = 1;}static void ctl_reset(void){    int i;    if(!ctl.trace_playing)	return;    PanelReset();    CanvasReadPanelInfo(0);    CanvasUpdate(0);    CanvasPaint();    for(i = 0; i < MAX_W32G_MIDI_CHANNELS; i++)    {	if(ISDRUMCHANNEL(i))	    ctl_program(i, channel[i].bank);	else	    ctl_program(i, channel[i].program);	ctl_volume(i, channel[i].volume);	ctl_expression(i, channel[i].expression);	ctl_panning(i, channel[i].panning);	ctl_sustain(i, channel[i].sustain);	if(channel[i].pitchbend == 0x2000 &&	   channel[i].mod.val > 0)	    ctl_pitch_bend(i, -1);	else	    ctl_pitch_bend(i, channel[i].pitchbend);	ctl_channel_note(i, Panel->cnote[i], 0);    }    Panel->changed = 1;}static void ctl_maxvoices(int v){    Panel->voices = v;    Panel->changed = 1;}extern void w32_wrd_ctl_event(CtlEvent *e);extern void w32_tracer_ctl_event(CtlEvent *e);static void ctl_event(CtlEvent *e){	w32_wrd_ctl_event(e);	w32_tracer_ctl_event(e);    switch(e->type)    {      case CTLE_NOW_LOADING:	PanelReset();	CanvasReset();	CanvasClear();	CanvasReadPanelInfo(1);	CanvasUpdate(1);	CanvasPaintAll();	MPanelReset();	MPanelReadPanelInfo(1);	MPanelUpdateAll();	MPanelPaintAll();	MPanelStartLoad((char *)e->v1);	break;      case CTLE_LOADING_DONE:	break;      case CTLE_PLAY_START:	w32g_ctle_play_start((int)e->v1 / play_mode->rate);	break;      case CTLE_PLAY_END:	MainWndScrollbarProgressUpdate(-1);	break;      case CTLE_CURRENT_TIME: {	  int sec;	  if(midi_trace.flush_flag)	      return;	  if(ctl.trace_playing)	      sec = (int)e->v1;	  else	  {	      sec = current_trace_samples();	      if(sec < 0)		  sec = (int)e->v1;	      else		  sec = sec / play_mode->rate;	  }	  ctl_current_time(sec, (int)e->v2);	  display_aq_ratio();	  MainWndScrollbarProgressUpdate(sec);	  ctl_panel_refresh();	}	break;      case CTLE_NOTE:	ctl_note((int)e->v1, (int)e->v2, (int)e->v3, (int)e->v4);	break;      case CTLE_GSLCD:	ctl_gslcd((int)e->v1);	CanvasReadPanelInfo(0);	CanvasUpdate(0);	CanvasPaint();	break;      case CTLE_MASTER_VOLUME:	ctl_master_volume((int)e->v1);	break;	case CTLE_METRONOME:		ctl_metronome((int) e->v1, (int) e->v2);		break;	case CTLE_KEYSIG:		ctl_keysig((int8) e->v1, CTL_STATUS_UPDATE);		break;	case CTLE_KEY_OFFSET:		ctl_keysig(CTL_STATUS_UPDATE, (int) e->v1);		break;	case CTLE_TEMPO:		ctl_tempo((int) e->v1, CTL_STATUS_UPDATE);		break;	case CTLE_TIME_RATIO:		ctl_tempo(CTL_STATUS_UPDATE, (int) e->v1);		break;      case CTLE_PROGRAM://	ctl_program((int)e->v1, (int)e->v2, (char *)e->v3);	ctl_program((int)e->v1, (int)e->v2);	break;      case CTLE_VOLUME:	ctl_volume((int)e->v1, (int)e->v2);	break;      case CTLE_EXPRESSION:	ctl_expression((int)e->v1, (int)e->v2);	break;      case CTLE_PANNING:	ctl_panning((int)e->v1, (int)e->v2);	break;      case CTLE_SUSTAIN:	ctl_sustain((int)e->v1, (int)e->v2);	break;      case CTLE_PITCH_BEND:	ctl_pitch_bend((int)e->v1, (int)e->v2);	break;      case CTLE_MOD_WHEEL:	ctl_pitch_bend((int)e->v1, e->v2 ? -2 : 0x2000);	break;      case CTLE_CHORUS_EFFECT:	break;      case CTLE_REVERB_EFFECT:	break;#if 1      case CTLE_LYRIC:		  {			char *lyric;		    lyric = event2string((uint16)e->v1);			if(lyric != NULL){				MPanelMessageClearAll();				MPanelMessageAdd(lyric+1,20000,1);			}		  }#else	default_ctl_lyric((uint16)e->v1);#endif	break;	case CTLE_REFRESH:		if (CanvasGetMode() == CANVAS_MODE_KBD_A				|| CanvasGetMode() == CANVAS_MODE_KBD_B) {			CanvasReadPanelInfo(0);			CanvasUpdate(0);			CanvasPaint();		}		break;      case CTLE_RESET:	ctl_reset();	break;      case CTLE_SPEANA:	break;      case CTLE_PAUSE:	if(w32g_play_active)	{	    MainWndScrollbarProgressUpdate((int)e->v2);	    if(!(int)e->v1)		ctl_reset();	    ctl_current_time((int)e->v2, 0);	    ctl_panel_refresh();	}	break;      case CTLE_MAXVOICES:	ctl_maxvoices((int)e->v1);	break;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -