int w32g_add_playlist(int nfiles, char **files, int expand_flag, int uniq, int refine) { char **new_files1; char **new_files2; int i, n; extern int SeachDirRecursive; extern char **FilesExpandDir(int *, char **); if(nfiles == 0) return 0; if(SeachDirRecursive) { new_files1 = FilesExpandDir(&nfiles, files); if(new_files1 == NULL) return 0; expand_flag = 1; } else new_files1 = files; if(!expand_flag) new_files2 = new_files1; else { new_files2 = expand_file_archives(new_files1, &nfiles); if(new_files2 == NULL) { if(new_files1 != files) { free(new_files1[0]); free(new_files1); } return 0; } } n = 0; for(i = 0; i < nfiles; i++) n += w32g_add_playlist1(new_files2[i], uniq, refine); if(new_files2 != new_files1) { free(new_files2[0]); free(new_files2); } if(new_files1 != files) { free(new_files1[0]); free(new_files1); } if(n > 0) w32g_update_playlist(); return n; }
int w32g_random_playlist(int skip_invalid_file) { int old_selected_index = playlist.selected; int select; int err = 0; for(;;) { if ( playlist.nfiles == 1) { select = old_selected_index; } else { if ( playlist.nfiles <= 1 ) select = 0; else if ( playlist.nfiles == 2 ) select = 1; else select = int_rand(playlist.nfiles - 1); select += old_selected_index; if ( select >= playlist.nfiles ) select -= playlist.nfiles; if ( select < 0 ) select = 0; } playlist.selected = select; if(!skip_invalid_file || playlist.list[playlist.selected].info->file_type != IS_ERROR_FILE) { w32g_update_playlist(); return 1; } if ( playlist.nfiles == 2 ) { playlist.selected = old_selected_index; if(!skip_invalid_file || playlist.list[playlist.selected].info->file_type != IS_ERROR_FILE) { w32g_update_playlist(); return 1; } } // for safety. if (playlist.selected == old_selected_index) break; err++; if (err > playlist.nfiles + 10) break; } return 0; }
static int ctl_delete_playlist(int offset) { int selected, nfiles, cur, pos; w32g_get_playlist_index(&selected, &nfiles, &cur); pos = cur + offset; if(pos < 0 || pos >= nfiles) return RC_NONE; if(w32g_delete_playlist(pos)) { w32g_update_playlist(); ctl_panel_refresh(); if(w32g_play_active && selected == pos) { w32g_update_playlist(); return RC_LOAD_FILE; } } return RC_NONE; }
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; }
static int w32g_ext_control(int rc, int32 value) { switch(rc) { case RC_EXT_DROP: return ctl_drop_file((HDROP)value); case RC_EXT_LOAD_FILE: return ctl_load_file((char *)value); case RC_EXT_LOAD_FILES_AND_PLAY: return ctl_load_files_and_play((argc_argv_t *)value, 1); case RC_EXT_LOAD_PLAYLIST: return ctl_load_playlist((char *)value); case RC_EXT_SAVE_PLAYLIST: return ctl_save_playlist((char *)value); case RC_EXT_MODE_CHANGE: CanvasChange(value); break; case RC_EXT_APPLY_SETTING: if(w32g_play_active) { mark_apply_setting = 1; return RC_STOP; } PrefSettingApplyReally(); mark_apply_setting = 0; break; case RC_EXT_DELETE_PLAYLIST: return ctl_delete_playlist(value); case RC_EXT_UPDATE_PLAYLIST: w32g_update_playlist(); break; case RC_EXT_UNIQ_PLAYLIST: return ctl_uniq_playlist(); case RC_EXT_REFINE_PLAYLIST: return ctl_refine_playlist(); case RC_EXT_JUMP_FILE: if(w32g_goto_playlist(value, !(ctl.flags & CTLF_NOT_CONTINUE))) return RC_LOAD_FILE; case RC_EXT_ROTATE_PLAYLIST: w32g_rotate_playlist(value); ctl_panel_refresh(); break; case RC_EXT_CLEAR_PLAYLIST: w32g_clear_playlist(); ctl_panel_refresh(); return RC_STOP; case RC_EXT_OPEN_DOC: w32g_setup_doc(value); w32g_open_doc(0); break; } return RC_NONE; }
void w32g_first_playlist(int skip_invalid_file) { playlist.selected = 0; if(skip_invalid_file) { while(playlist.selected < playlist.nfiles && playlist.list[playlist.selected].info->file_type == IS_ERROR_FILE) playlist.selected++; if(playlist.selected == playlist.nfiles) playlist.selected = 0; } w32g_update_playlist(); }
int w32g_prev_playlist(int skip_invalid_file) { while(playlist.selected > 0) { playlist.selected--; if(!skip_invalid_file || playlist.list[playlist.selected].info->file_type != IS_ERROR_FILE) { w32g_update_playlist(); return 1; } } return 0; }
int w32g_next_playlist(int skip_invalid_file) { while(playlist.selected + 1 < playlist.nfiles) { playlist.selected++; if(!skip_invalid_file || playlist.list[playlist.selected].info->file_type != IS_ERROR_FILE) { w32g_update_playlist(); return 1; } } return 0; }
int w32g_goto_playlist(int num, int skip_invalid_file) { if(0 <= num && num < playlist.nfiles) { playlist.selected = num; if(skip_invalid_file) { while(playlist.selected < playlist.nfiles && playlist.list[playlist.selected].info->file_type == IS_ERROR_FILE) playlist.selected++; if(playlist.selected == playlist.nfiles) playlist.selected = num; } w32g_update_playlist(); return 1; } return 0; }
int w32g_shuffle_playlist_next(int skip_invalid_file) { if ( !playlist_shuffle_init ) { if ( !w32g_shuffle_playlist_reset(0) ) return 0; } for ( playlist_shuffle.cur ++ ; playlist_shuffle.cur < playlist_shuffle.max; playlist_shuffle.cur ++ ) { int n = int_rand(playlist_shuffle.max - playlist_shuffle.cur) + playlist_shuffle.cur; int temp = playlist_shuffle.list[playlist_shuffle.cur]; if ( n > playlist_shuffle.max ) n = playlist_shuffle.max; playlist_shuffle.list[playlist_shuffle.cur] = playlist_shuffle.list[n]; playlist_shuffle.list[n] = temp; if ( playlist_shuffle.list[playlist_shuffle.cur] < playlist.nfiles ) { playlist.selected = playlist_shuffle.list[playlist_shuffle.cur]; if(!skip_invalid_file || playlist.list[playlist.selected].info->file_type != IS_ERROR_FILE) { w32g_update_playlist(); return 1; } } } return 0; }
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; }
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) strcpy(Panel->filename,p); } 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; }