struct sys * sys_copy(struct sys *sys) { struct sys *copy; int i; copy = malloc(sizeof(struct sys)); memcpy(copy, sys, sizeof(struct sys)); copy->graph = graph_copy(sys->graph); copy->sel = sel_copy(sys->sel); copy->visible = sel_copy(sys->visible); copy->frames = malloc(copy->nframesalloc * sizeof(struct frame)); for (i = 0; i < sys_get_frame_count(sys); i++) copy->frames[i].atoms = atoms_copy(sys->frames[i].atoms); return (copy); }
/* * sels_copy (sels) * * returns a copy of sels */ GList * sels_copy (GList * sels) { GList * gl, * nsels = NULL; sw_sel * sel, * nsel; for (gl = sels; gl; gl = gl->next) { sel = (sw_sel *)gl->data; nsel = sel_copy (sel); nsels = g_list_insert_sorted(nsels, nsel, (GCompareFunc)sel_cmp); } return nsels; }
/* * sounddata_copyin_selection (sounddata1, sounddata2) * * copies the selection of sounddata1 into sounddata2. If sounddata2 previously * had a selection, the two are merged. */ void sounddata_copyin_selection (sw_sounddata * sounddata1, sw_sounddata * sounddata2) { GList * gl; sw_sel * sel, *sel2; for (gl = sounddata1->sels; gl; gl = gl->next) { sel = (sw_sel *)gl->data; sel2 = sel_copy (sel); sounddata_add_selection (sounddata2, sel2); } sounddata_normalise_selection (sounddata2); }
void sounddata_normalise_selection (sw_sounddata * sounddata) { GList * gl; GList * nsels = NULL; sw_sel * osel = NULL, * sel; sw_framecount_t nr_frames; if (!sounddata_sel_needs_normalising(sounddata)) return; nr_frames = sounddata->nr_frames; /* Seed osel with 'fake' iteration of following loop */ gl = sounddata->sels; sel = (sw_sel *)gl->data; sel->sel_start = CLAMP(sel->sel_start, 0, nr_frames); sel->sel_end = CLAMP(sel->sel_end, 0, nr_frames); osel = sel_copy(sel); gl = gl->next; for (; gl; gl = gl->next) { sel = (sw_sel *)gl->data; sel->sel_start = CLAMP(sel->sel_start, 0, nr_frames); sel->sel_end = CLAMP(sel->sel_end, 0, nr_frames); /* Check for an overlap */ if(osel->sel_end >= sel->sel_start) { /* If sel is completely contained in osel, ignore it. */ if(osel->sel_end > sel->sel_end) { continue; } /* Set: osel = osel INTERSECT sel * we already know osel->sel_start <= sel->sel_start */ osel->sel_end = sel->sel_end; } else { /* No more overlaps with osel; insert it in nsels, and * reset osel. */ if (osel->sel_start == osel->sel_end) { g_free (osel); } else { nsels = g_list_insert_sorted(nsels, osel, (GCompareFunc)sel_cmp); } osel = sel_copy(sel); } } /* Insert the last created osel */ if (osel->sel_start == osel->sel_end) { g_free (osel); } else { nsels = g_list_insert_sorted(nsels, osel, (GCompareFunc)sel_cmp); } /* Clear the old selection */ sounddata_clear_selection (sounddata); /* Set the newly created (normalised) selection */ sounddata->sels = nsels; }