?? wildmidi_lib.c
字號:
while (patch[i] != NULL) { if (patch[i]->filename != NULL) { if (patch[i]->first_sample != NULL) { while (patch[i]->first_sample != NULL) { tmp_sample = patch[i]->first_sample->next; if (patch[i]->first_sample->data != NULL) free (patch[i]->first_sample->data); free (patch[i]->first_sample); patch[i]->first_sample = tmp_sample; } } free (patch[i]->filename); } tmp_patch = patch[i]->next; free(patch[i]); patch[i] = tmp_patch; } } } WM_Unlock(&patch_lock);}intWM_LoadConfig (const char *config_file) { unsigned long int config_size = 0; unsigned char *config_buffer = NULL; char * dir_end = NULL; char * config_dir = NULL; unsigned long int config_ptr = 0; unsigned long int line_start_ptr = 0; char * line_buffer = NULL; unsigned long int line_ptr = 0; char * chr_ptr = NULL; unsigned short int patchid = 0; char * new_config = NULL; struct _patch * tmp_patch; if ((config_buffer = WM_BufferFile(config_file, &config_size)) == NULL) { return -1; } if (config_buffer == NULL) { WM_FreePatches(); return -1; } dir_end = strrchr(config_file,'/'); if (dir_end != NULL) { config_dir = malloc((dir_end - config_file + 2)); if (config_dir == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free (config_buffer); return -1; } strncpy(config_dir, config_file, (dir_end - config_file + 1)); config_dir[dir_end - config_file + 1] = '\0'; } config_ptr = 0; line_start_ptr = 0; while (config_ptr < config_size) { // find end of line if (config_buffer[config_ptr] != '\n') { // remove unwanted crud if (config_buffer[config_ptr] == '\t') { config_buffer[config_ptr] = ' '; } else if (config_buffer[config_ptr] == '\r') { config_buffer[config_ptr] = ' '; } if ((config_buffer[config_ptr] == ' ') && (config_ptr == line_start_ptr)) { line_start_ptr++; } config_ptr++; continue; } config_buffer[config_ptr] = '\0'; if (config_ptr == line_start_ptr) { config_ptr++; line_start_ptr++; continue; } if (config_buffer[line_start_ptr] == '#') { config_ptr++; line_start_ptr = config_ptr; continue; } // copy line into a workable buffer line_buffer = realloc(line_buffer, (config_ptr - line_start_ptr + 1)); if (line_buffer == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); if (config_dir != NULL) free(config_dir); free (config_buffer); return -1; } strcpy(line_buffer, &config_buffer[line_start_ptr]); config_ptr++; line_start_ptr = config_ptr; // remove unwnted crud from line for easier parsing if ((chr_ptr = strstr(line_buffer," ")) != NULL) { while ((chr_ptr = strstr(line_buffer," ")) != NULL) { memmove(chr_ptr, &chr_ptr[1], strlen(chr_ptr)); } } if ((chr_ptr = strchr(line_buffer, '#')) != NULL) { *chr_ptr = '\0'; } if (line_buffer[strlen(line_buffer) -1] == ' ') { while (line_buffer[strlen(line_buffer) -1] == ' ') { line_buffer[strlen(line_buffer) -1] = '\0'; } } // now parse line if (strncasecmp(line_buffer, "dir ", 4) == 0) { if (line_buffer[strlen(line_buffer) - 1] == '/') { config_dir = realloc(config_dir, strlen(&line_buffer[4]) + 1); if (config_dir == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free (line_buffer); free (config_buffer); return -1; } strcpy(config_dir, &line_buffer[4]); } else { config_dir = realloc(config_dir, strlen(&line_buffer[4]) + 2); if (config_dir == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free (line_buffer); free (config_buffer); return -1; } strcpy(config_dir, &line_buffer[4]); strcat(config_dir,"/"); } continue; } else if (strncasecmp(line_buffer, "source ", 7) == 0) { if (config_dir != NULL) { new_config = malloc(strlen(config_dir) + strlen(&line_buffer[7]) + 1); if (new_config == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free (config_dir); free (line_buffer); free (config_buffer); return -1; } strcpy(new_config,config_dir); strcpy(&new_config[strlen(config_dir)], &line_buffer[7]); } else { new_config = malloc(strlen(&line_buffer[7]) + 1); if (new_config == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free (line_buffer); free (config_buffer); return -1; } strcpy(new_config, &line_buffer[7]); } if (WM_LoadConfig(new_config) == -1) { free (new_config); free (line_buffer); free (config_buffer); if (config_dir != NULL) free (config_dir); return -1; } free (new_config); continue; } else if (strncasecmp(line_buffer, "bank ", 5) == 0) { if (!isdigit(line_buffer[5])) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, "(syntax error in bank line)", 0); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); if (config_dir != NULL) free (config_dir); free (line_buffer); free (config_buffer); return -1; } patchid = (atoi(&line_buffer[5]) & 0xFF ) << 8; continue; } else if (strncasecmp(line_buffer, "drumset ", 8) == 0) { if (!isdigit(line_buffer[8])) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, "(syntax error in drumset line)", 0); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); if (config_dir != NULL) free (config_dir); free (line_buffer); free (config_buffer); return -1; } patchid = ((atoi(&line_buffer[8]) & 0xFF ) << 8) | 0x80; continue; } else if (isdigit(line_buffer[0])) { patchid = (patchid & 0xFF80) | (atoi(line_buffer) & 0x7F); if (patch[(patchid & 0x7F)] == NULL) { patch[(patchid & 0x7F)] = malloc (sizeof(struct _patch)); if (patch[(patchid & 0x7F)] == NULL) { WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); if (config_dir != NULL) free (config_dir); free (line_buffer); free (config_buffer); return -1; } tmp_patch = patch[(patchid & 0x7F)]; tmp_patch->patchid = patchid; tmp_patch->filename = NULL; tmp_patch->amp = 1024; tmp_patch->note = 0; tmp_patch->next = NULL; tmp_patch->first_sample = NULL; tmp_patch->loaded = 0; tmp_patch->inuse_count = 0; } else { tmp_patch = patch[(patchid & 0x7F)]; if (tmp_patch->patchid == patchid) { free (tmp_patch->filename); tmp_patch->filename = NULL;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -