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

📄 w32g_playlist.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 2 页
字号:
	int maxlen, item2_len;	int notitle = 0;	filename = playlist.list[i].filename;	title = playlist.list[i].title;	if(title == NULL || title[0] == '\0')	{	    if(playlist.list[i].info->file_type == IS_ERROR_FILE)		title = " --SKIP-- ";		else		{//		title = " -------- ";		title = playlist.list[i].filename;		notitle = 1;		}	}	maxlen = strlen(filename) + strlen(title) + 32 + 80;	item1 = (char *)new_segment(&tmpbuffer, maxlen);	if(!notitle)	{	if(i == playlist.selected)	    snprintf(item1, maxlen, "==>%-80s   ==>(%s)", title, filename);	else	    snprintf(item1, maxlen, "   %-80s      (%s)", title, filename);	} else	{	if(i == playlist.selected)	    snprintf(item1, maxlen, "==>%-80s   ==>(%s)", title, filename);	else	    snprintf(item1, maxlen, "   %-80s      (%s)", title, filename);	}	item2_len = ListBox_GetTextLen(hListBox, i);	item2 = (char *)new_segment(&tmpbuffer, item2_len + 1);	ListBox_GetText(hListBox, i, item2);	if(strcmp(item1, item2) != 0)	{	    ListBox_DeleteString(hListBox, i);	    ListBox_InsertString(hListBox, i, item1);	    modified = 1;	}	reuse_mblock(&tmpbuffer);    }    if(modified && cur==pos)    {	if(cur < 0)	    cur = playlist.selected;	else if(cur >= playlist.nfiles - 1)	    cur = playlist.nfiles - 1;	ListBox_SetCurSel(hListBox, cur);	SetNumListWnd(cur,playlist.nfiles);    }}void w32g_update_playlist(void){#if 0    int i, cur, modified;    HWND hListBox;    if(!(hListBox = playlist_box()))	return;    cur = ListBox_GetCurSel(hListBox);    modified = 0;    for(i = 0; i < playlist.nfiles; i++)    {	char *filename, *title, *item1, *item2;	int maxlen, item2_len;	filename = playlist.list[i].filename;	title = playlist.list[i].title;	if(title == NULL || title[0] == '\0')	{	    if(playlist.list[i].info->file_type == IS_ERROR_FILE)		title = " --SKIP-- ";	    else		title = " -------- ";	}	maxlen = strlen(filename) + strlen(title) + 32;	item1 = (char *)new_segment(&tmpbuffer, maxlen);	if(i == playlist.selected)	    snprintf(item1, maxlen, "==>%04d %s (%s)", i + 1, title, filename);	else	    snprintf(item1, maxlen, "   %04d %s (%s)", i + 1, title, filename);	item2_len = ListBox_GetTextLen(hListBox, i);	item2 = (char *)new_segment(&tmpbuffer, item2_len + 1);	ListBox_GetText(hListBox, i, item2);	if(strcmp(item1, item2) != 0)	{	    ListBox_DeleteString(hListBox, i);	    ListBox_InsertString(hListBox, i, item1);	    modified = 1;	}	reuse_mblock(&tmpbuffer);    }    if(modified)    {	if(cur < 0)	    cur = playlist.selected;	else if(cur >= playlist.nfiles - 1)	    cur = playlist.nfiles - 1;	ListBox_SetCurSel(hListBox, cur);	SetNumListWnd(cur,playlist.nfiles);    }#else    int i, cur, modified;    HWND hListBox;    if(!(hListBox = playlist_box()))	return;    cur = ListBox_GetCurSel(hListBox);    modified = 0;    for(i = 0; i < playlist.nfiles; i++)    {		w32g_update_playlist_pos(i);    }    if(modified)    {	if(cur < 0)	    cur = playlist.selected;	else if(cur >= playlist.nfiles - 1)	    cur = playlist.nfiles - 1;	ListBox_SetCurSel(hListBox, cur);	SetNumListWnd(cur,playlist.nfiles);    }#endif}void w32g_get_playlist_index(int *selected, int *nfiles, int *cursel){    if(selected != NULL)	*selected = playlist.selected;    if(nfiles != NULL)	*nfiles = playlist.nfiles;    if(cursel != NULL)    {	HWND hListBox;	hListBox = playlist_box();	if(hListBox)	    *cursel = ListBox_GetCurSel(hListBox);	else	    *cursel = 0;    }}int w32g_delete_playlist(int pos){    int i;    HWND hListBox;    if(!(hListBox = playlist_box()))	return 0;    if(pos >= playlist.nfiles)	return 0;#ifdef W32G_RANDOM_IS_SHUFFLE	w32g_shuffle_playlist_delete(pos);#endif    ListBox_DeleteString(hListBox, pos);    free(playlist.list[pos].filename);    playlist.nfiles--;    for(i = pos; i < playlist.nfiles; i++)		playlist.list[i] = playlist.list[i + 1];    if(pos < playlist.selected || pos == playlist.nfiles)    {	playlist.selected--;	if(playlist.selected < 0){	    playlist.selected = 0;		SetNumListWnd(playlist.selected,playlist.nfiles);	} else		w32g_update_playlist_pos(playlist.selected);    }    if(playlist.nfiles > 0)    {	if(pos == playlist.nfiles)	    pos--;	ListBox_SetCurSel(hListBox, pos);	SetNumListWnd(pos,playlist.nfiles);    }    return 1;}int w32g_ismidi_playlist(int n){    if(n < 0 || n >= playlist.nfiles)	return 0;    return playlist.list[n].info->format >= 0;}int w32g_nvalid_playlist(void){    int i, n;    n = 0;    for(i = 0; i < playlist.nfiles; i++)	if(w32g_ismidi_playlist(i))	    n++;    return n;}void w32g_setcur_playlist(void){    HWND hListBox;    if(!(hListBox = playlist_box()))	return;    ListBox_SetCurSel(hListBox, playlist.selected);	SetNumListWnd(playlist.selected,playlist.nfiles);}int w32g_uniq_playlist(int *is_selected_removed){    int nremoved;    int i, n, j1, j2, cursel;    HWND hListBox;    hListBox = playlist_box();    if(hListBox)	cursel = ListBox_GetCurSel(hListBox);    else	cursel = -1;    if(is_selected_removed != NULL)	*is_selected_removed = 0;    nremoved = 0;    n = playlist.nfiles;    for(i = 0; i < n - 1; i++)    {	int save_n;	/* remove list[i] from list[i+1 .. n-1] */	j1 = j2 = i + 1;	save_n = n;	while(j2 < save_n) /* j1 <= j2 */	{	    if(pathcmp(playlist.list[i].filename,		       playlist.list[j2].filename, 0) == 0)	    {		nremoved++;		n--;		free(playlist.list[j2].filename);		if(j2 == playlist.selected &&		   is_selected_removed != NULL &&		   !*is_selected_removed)		{		    *is_selected_removed = 1;		    playlist.selected = j1;		}		if(j2 < playlist.selected)		    playlist.selected--;		if(j2 < cursel)		    cursel--;	    }	    else	    {		playlist.list[j1] = playlist.list[j2];		j1++;	    }	    j2++;	}    }    if(nremoved)    {	for(i = 0; i < nremoved; i++)	    ListBox_DeleteString(hListBox, --playlist.nfiles);	if(cursel >= 0){	    ListBox_SetCurSel(hListBox, cursel);		SetNumListWnd(cursel,playlist.nfiles);	}	w32g_update_playlist();    }    return nremoved;}int w32g_refine_playlist(int *is_selected_removed){    int nremoved;    int i, j1, j2, cursel;    HWND hListBox;    hListBox = playlist_box();    if(hListBox)	cursel = ListBox_GetCurSel(hListBox);    else	cursel = -1;    if(is_selected_removed != NULL)	*is_selected_removed = 0;    nremoved = 0;    j1 = j2 = 0;    while(j2 < playlist.nfiles) /* j1 <= j2 */    {	if(playlist.list[j2].info->format < 0)	{	    nremoved++;	    free(playlist.list[j2].filename);		if(j2 == playlist.selected &&		   is_selected_removed != NULL &&		   !*is_selected_removed)		{		    *is_selected_removed = 1;		    playlist.selected = j1;		}		if(j2 < playlist.selected)		    playlist.selected--;		if(j2 < cursel)		    cursel--;	}	else	{	    playlist.list[j1] = playlist.list[j2];	    j1++;	}	j2++;    }    if(nremoved)    {	for(i = 0; i < nremoved; i++)	    ListBox_DeleteString(hListBox, --playlist.nfiles);	if(cursel >= playlist.nfiles)	    cursel = playlist.nfiles - 1;	if(cursel >= 0){	    ListBox_SetCurSel(hListBox, cursel);		SetNumListWnd(cursel,playlist.nfiles);	}	w32g_update_playlist();    }    return nremoved;}void w32g_clear_playlist(void){    HWND hListBox;    hListBox = playlist_box();    while(playlist.nfiles > 0)    {	playlist.nfiles--;	free(playlist.list[playlist.nfiles].filename);#if 0	if(hListBox)	    ListBox_DeleteString(hListBox, playlist.nfiles);#endif    }//	LB_RESETCONTENT	if(hListBox)	    ListBox_ResetContent(hListBox);	playlist.selected = 0;	SetNumListWnd(0,0);}void w32g_rotate_playlist(int dest){    int i, i1, i2;    HWND hListBox;    PlayListEntry save;	char temp[1024];    if(playlist.nfiles == 0)	return;    if(!(hListBox = playlist_box()))	return;    i1 = ListBox_GetCurSel(hListBox);    i2 = playlist.nfiles - 1;    if(i1 >= i2)	return;#ifdef W32G_RANDOM_IS_SHUFFLE	w32g_shuffle_playlist_rotate(dest,i1,i2);#endif    if(dest > 0)    {	save = playlist.list[i2];	for(i = i2; i > i1; i--) /* i: i2 -> i1 */	    playlist.list[i] = playlist.list[i - 1];	playlist.list[i] = save;	ListBox_GetText(hListBox,i2,temp);    ListBox_DeleteString(hListBox,i2);    ListBox_InsertString(hListBox,i1,temp);	ListBox_SetCurSel(hListBox,i1);	if(playlist.selected == i2){	    playlist.selected = i1;		w32g_update_playlist_pos(playlist.selected);	} else if(i1 <= playlist.selected && playlist.selected < i2){	    playlist.selected++;		w32g_update_playlist_pos(playlist.selected);	}    }    else    {	save = playlist.list[i1];	for(i = i1; i < i2; i++) /* i: i1 -> i2 */	    playlist.list[i] = playlist.list[i + 1];	playlist.list[i] = save;	ListBox_GetText(hListBox,i1,temp);    ListBox_DeleteString(hListBox,i1);    ListBox_InsertString(hListBox,-1,temp);	ListBox_SetCurSel(hListBox,i1);	if(playlist.selected == i1){	    playlist.selected = i2;		w32g_update_playlist_pos(playlist.selected);	} else if(i1 < playlist.selected && playlist.selected <= i2){	    playlist.selected--;    		w32g_update_playlist_pos(playlist.selected);	}    }}char *w32g_get_playlist(int idx){    if(idx < 0 || idx >= playlist.nfiles)	return NULL;    return playlist.list[idx].filename;}

⌨️ 快捷键说明

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