- nnewvec = nvec;
- newvec = xcalloc(nnewvec, sizeof (char *));
- int i = 0;
- /* For each destination slot decide what will go there */
- for(int n = 0; n < nnewvec; ++n) {
- fprintf(stderr, "n=%d i=%d\n", n, i);
- if(n >= ins && n < ins + mod->ntracks) {
- fprintf(stderr, "inside insertion range\n");
- newvec[n] = mod->tracks[n - ins];
- } else {
- /* Pick the next track from vec[] that is not mentioned in mod->ids[] */
- while(playlist_drop_is_moved(mod, i)) {
- ++i;
- --ins;
- fprintf(stderr, "now: i=%d ins=%d\n", i, ins);
- }
- newvec[n] = vec[i++];
+ /* We have:
+ * - vec[], the current layout
+ * - ins, pointing into vec
+ * - mod->tracks[], a subset of vec[] which is to be moved
+ *
+ * ins is the insertion point BUT it is in terms of the whole
+ * array, i.e. before mod->tracks[] have been removed. The first
+ * step then is to remove everything in mod->tracks[] and adjust
+ * ins downwards as necessary.
+ */
+ /* First zero out anything that's moved */
+ int before_ins = 0;
+ for(int n = 0; n < nvec; ++n) {
+ if(playlist_drop_is_moved(mod, n)) {
+ vec[n] = NULL;
+ if(n < ins)
+ ++before_ins;