/***************************************************************************** * load_patch_list() * * Loads a comma separated list of patches, one for each part. *****************************************************************************/ void load_patch_list(char *patch_list) { PATCH *patch; char filename[PATH_MAX]; char *patch_name; char *tokbuf; char *p; unsigned int part_num = 0; int prog = 0; /* Get a comma separated client:port list from command line, or a '-' (or no -p arg) for open subscription. */ if (patch_list != NULL) { if ((tokbuf = alloca(strlen(patch_list) * 4)) == NULL) { phasex_shutdown("Out of memory!\n"); } p = patch_list; while ((part_num < MAX_PARTS) && ((patch_name = strtok_r(p, ",", &tokbuf)) != NULL)) { p = NULL; patch = get_patch_from_bank(part_num, 0); /* read in patchdump for part num if patch is '-' */ if (strcmp(patch_name, "-") == 0) { read_patch(user_patchdump_file[part_num], patch); } /* if patch is numeric and within range 0-127, treat it as a program number */ else if (((prog = atoi(patch_name)) > 0) && (prog <= PATCH_BANK_SIZE)) { session_bank[visible_sess_num].prog_num[part_num] = (unsigned int)(prog - 1); } /* default to reading in named patch */ else { /* TODO: if user patch exists (in any directory) load it and skip system patch. */ snprintf(filename, sizeof(char) * PATH_MAX, "%s/%s.phx", PATCH_DIR, patch_name); read_patch(filename, patch); snprintf(filename, sizeof(char) * PATH_MAX, "%s/%s.phx", user_patch_dir, patch_name); read_patch(filename, patch); session_bank[visible_sess_num].prog_num[part_num] = (unsigned int) prog - 1; } part_num++; } } }
int lash_pollevent() { if (!lash_enabled(lash_client)) return -1; lash_event_t *event; char *l_path; while (event = lash_get_event(lash_client)) { if (lash_event_get_type(event) == LASH_Save_File) { lash_buffer = (char *)lash_event_get_string(event); l_path = (char *)malloc(strlen(lash_buffer) + 13); sprintf(l_path, "%s/phasex.phx", lash_buffer); save_patch(l_path, 0); sprintf(l_path, "%s/phasex.map", lash_buffer); save_midimap(l_path); lash_send_event(lash_client, lash_event_new_with_type(LASH_Save_File)); free(l_path); break; } else if (lash_event_get_type(event) == LASH_Restore_File) { lash_buffer = (char *)lash_event_get_string(event); l_path = (char *)malloc(strlen(lash_buffer) + 13); sprintf(l_path, "%s/phasex.phx", lash_buffer); read_patch(l_path, 0); sprintf(l_path, "%s/phasex.map", lash_buffer); read_midimap(l_path); lash_send_event(lash_client, lash_event_new_with_type(LASH_Restore_File)); free(l_path); break; } else if (lash_event_get_type(event) == LASH_Quit) { shutdown = 1; break; } lash_event_destroy(event); } return 0; }
/***************************************************************************** * load_patch_bank() *****************************************************************************/ void load_patch_bank(void) { PATCH *patch; FILE *bank_f; char *p; char *filename; char *tmpname; char buffer[256]; int part_num = 0; int prog = 0; unsigned int line = 0; int once = 1; int result; /* open the bank file */ if ((bank_f = fopen(user_bank_file, "rt")) == NULL) { if ((bank_f = fopen(sys_bank_file, "rt")) == NULL) { return; } } /* read bank entries */ while (fgets(buffer, sizeof(buffer), bank_f) != NULL) { line++; /* discard comments and blank lines */ if ((buffer[0] == '\n') || (buffer[0] == '#')) { continue; } /* get part number */ if ((p = get_next_token(buffer)) == NULL) { while (get_next_token(buffer) != NULL); continue; } part_num = atoi(p) - 1; if ((part_num < 0) || (part_num >= MAX_PARTS)) { part_num = 0; } /* make sure there's a comma */ if ((p = get_next_token(buffer)) == NULL) { while (get_next_token(buffer) != NULL); continue; } if (*p != ',') { while (get_next_token(buffer) != NULL); continue; } /* get program number */ if ((p = get_next_token(buffer)) == NULL) { while (get_next_token(buffer) != NULL); continue; } prog = atoi(p) - 1; if ((prog < 0) || (prog >= PATCH_BANK_SIZE)) { prog = 0; } patch = & (patch_bank[part_num][prog]); /* make sure there's an '=' */ if ((p = get_next_token(buffer)) == NULL) { while (get_next_token(buffer) != NULL); continue; } if (*p != '=') { while (get_next_token(buffer) != NULL); continue; } /* get patch name */ if ((tmpname = get_next_token(buffer)) == NULL) { while (get_next_token(buffer) != NULL); continue; } if (*tmpname == ';') { while (get_next_token(buffer) != NULL); continue; } if ((filename = strdup(tmpname)) == NULL) { phasex_shutdown("Out of memory!\n"); } /* make sure there's a ';' */ if ((p = get_next_token(buffer)) == NULL) { while (get_next_token(buffer) != NULL); continue; } if (*p != ';') { while (get_next_token(buffer) != NULL); continue; } /* flush remainder of line */ while (get_next_token(buffer) != NULL); /* load patch into bank */ result = 0; /* handle bare patch names from 0.10.x versions */ if (filename[0] != '/') { snprintf(buffer, sizeof(buffer), "%s/%s.phx", user_patch_dir, filename); result = read_patch(buffer, patch); if (result != 0) { snprintf(buffer, sizeof(buffer), "%s/%s.phx", PATCH_DIR, filename); result = read_patch(buffer, patch); } } /* handle fully qualified filenames */ else { result = read_patch(filename, patch); } /* initialize on failure and set name based on program number */ if (result != 0) { if (read_patch(user_default_patch, patch) != 0) { read_patch(sys_default_patch, patch); } snprintf(buffer, sizeof(buffer), "Untitled-%04d", (prog + 1)); tmpname = patch->name; patch->name = strdup(buffer); if (tmpname != NULL) { free(tmpname); } if (patch->directory != NULL) { free(patch->directory); } patch->directory = strdup(user_patch_dir); } /* free up memory used to piece filename together */ free(filename); /* Lock some global parameters after the first patch is read */ if (once) { get_param_info_by_id(PARAM_MIDI_CHANNEL)->locked = 1; get_param_info_by_id(PARAM_BPM)->locked = 1; once = 0; } } /* done parsing */ fclose(bank_f); /* now fill the empty bank slots with the default patch */ for (prog = 0; prog < PATCH_BANK_SIZE; prog++) { patch = & (patch_bank[part_num][prog]); if (patch->name == NULL) { if (read_patch(user_default_patch, patch) != 0) { read_patch(sys_default_patch, patch); } snprintf(buffer, sizeof(buffer), "Untitled-%04d", (prog + 1)); patch->name = strdup(buffer); patch->directory = strdup(user_patch_dir); } patch->modified = 0; } }
gboolean run_command (TestProfile *tp, int zlevel, int slevel, File* from, File* to, File* out, File *re, gboolean accounting) { int pid, status, outfd; struct stat sbuf; char xdelta_args[16]; char xdelta_args2[16]; char diff_gzargs[16]; char gzip_args[16]; GTimer *timer = g_timer_new (); sprintf (xdelta_args, "-qn%d", zlevel); sprintf (xdelta_args2, "-s%d", slevel); sprintf (diff_gzargs, "wb%d", zlevel); sprintf (gzip_args, "-c%d", zlevel); unlink (out->name); g_timer_start (timer); if ((pid = vfork()) < 0) return FALSE; if (pid == 0) { if (starts_with (tp->name, "xdelta")) { execl (tp->progname, tp->progname, "delta", xdelta_args, xdelta_args2, from->name, to->name, out->name, NULL); } else { outfd = open (out->name, O_CREAT | O_TRUNC | O_WRONLY, 0777); if (outfd < 0) { perror ("open"); fail (); } dup2(outfd, STDOUT_FILENO); if (close (outfd)) { perror ("close"); fail (); } if (starts_with (tp->name, "diff")) execl (tp->progname, tp->progname, "--rcs", "-a", from->name, to->name, NULL); else if (starts_with (tp->name, "gzip")) execl (tp->progname, tp->progname, gzip_args, to->name, NULL); else abort (); } perror ("execl failed"); _exit (127); } if (waitpid (pid, &status, 0) != pid) { perror ("wait failed"); fail (); } // Note: program is expected to return 0, 1 meaning diff or no diff, // > 1 indicates failure if (! WIFEXITED (status) || WEXITSTATUS (status) > 1) { g_warning ("delta command failed\n"); fail (); } if (stat (out->name, & sbuf)) { perror ("stat"); fail (); } // Do zlib compression on behalf of diff if (zlevel > 0 && starts_with (tp->name, "diff")) { Patch *patch = read_patch (out, & sbuf); gzFile *rewrite = gzopen (out->name, diff_gzargs); if (! rewrite) fail (); if (gzwrite (rewrite, patch->data, patch->length) == 0) { perror ("gzwrite"); fail (); } if (gzclose (rewrite) != Z_OK) { perror ("gzclose"); fail (); } if (stat (out->name, & sbuf)) { perror ("stat"); fail (); } } g_timer_stop (timer); if (accounting) { add_tv (timer); } if (__dsize < 0) { __dsize = sbuf.st_size; // Verify only once if (starts_with (tp->name, "xdelta")) { if (! xdelta_verify (tp, zlevel, slevel, from, to, out, re)) { g_warning ("verify failed"); fail (); } } } else { if (__dsize != sbuf.st_size) { g_warning ("%s -%d: delta command produced different size deltas: %d and %d", tp->progname, zlevel, (int)__dsize, (int)sbuf.st_size); fail (); } } g_timer_destroy (timer); return TRUE; }