Blender  V2.93
clipboard.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  *
19  * - Blender Foundation, 2003-2009
20  * - Peter Schlaile <peter [at] schlaile [dot] de> 2005/2006
21  */
22 
27 #include "MEM_guardedalloc.h"
28 
29 #include "DNA_scene_types.h"
30 #include "DNA_sequence_types.h"
31 #include "DNA_sound_types.h"
32 
33 #include "BLI_listbase.h"
34 
35 #include "BKE_main.h"
36 #include "BKE_movieclip.h"
37 #include "BKE_scene.h"
38 #include "BKE_sound.h"
39 
40 #include "SEQ_clipboard.h"
41 
42 #include "sequencer.h"
43 
44 #ifdef WITH_AUDASPACE
45 # include <AUD_Special.h>
46 #endif
47 
48 /* -------------------------------------------------------------------- */
49 /* Manage pointers in the clipboard.
50  * note that these pointers should _never_ be access in the sequencer,
51  * they are only for storage while in the clipboard
52  * notice 'newid' is used for temp pointer storage here, validate on access (this is safe usage,
53  * since those data-blocks are fully out of Main lists).
54  */
55 
58 
59 void seq_clipboard_pointers_free(struct ListBase *seqbase);
60 
62 {
63  Sequence *seq, *nseq;
64 
66 
67  for (seq = seqbase_clipboard.first; seq; seq = nseq) {
68  nseq = seq->next;
69  seq_free_sequence_recurse(NULL, seq, false);
70  }
72 }
73 
74 #define ID_PT (*id_pt)
75 static void seqclipboard_ptr_free(Main *UNUSED(bmain), ID **id_pt)
76 {
77  if (ID_PT) {
78  BLI_assert(ID_PT->newid != NULL);
80  ID_PT = NULL;
81  }
82 }
83 static void seqclipboard_ptr_store(Main *UNUSED(bmain), ID **id_pt)
84 {
85  if (ID_PT) {
86  ID *id_prev = ID_PT;
88  ID_PT->newid = id_prev;
89  }
90 }
91 static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
92 {
93  if (ID_PT) {
94  const ListBase *lb = which_libbase(bmain, GS(ID_PT->name));
95  void *id_restore;
96 
97  BLI_assert(ID_PT->newid != NULL);
98  if (BLI_findindex(lb, (ID_PT)->newid) != -1) {
99  /* the pointer is still valid */
100  id_restore = (ID_PT)->newid;
101  }
102  else {
103  /* the pointer of the same name still exists */
104  id_restore = BLI_findstring(lb, (ID_PT)->name + 2, offsetof(ID, name) + 2);
105  }
106 
107  if (id_restore == NULL) {
108  /* check for a data with the same filename */
109  switch (GS(ID_PT->name)) {
110  case ID_SO: {
111  id_restore = BLI_findstring(lb, ((bSound *)ID_PT)->filepath, offsetof(bSound, filepath));
112  if (id_restore == NULL) {
113  id_restore = BKE_sound_new_file(bmain, ((bSound *)ID_PT)->filepath);
114  (ID_PT)->newid = id_restore; /* reuse next time */
115  }
116  break;
117  }
118  case ID_MC: {
119  id_restore = BLI_findstring(
120  lb, ((MovieClip *)ID_PT)->filepath, offsetof(MovieClip, filepath));
121  if (id_restore == NULL) {
122  id_restore = BKE_movieclip_file_add(bmain, ((MovieClip *)ID_PT)->filepath);
123  (ID_PT)->newid = id_restore; /* reuse next time */
124  }
125  break;
126  }
127  default:
128  break;
129  }
130  }
131 
132  /* Replace with pointer to actual data-block. */
133  seqclipboard_ptr_free(bmain, id_pt);
134  ID_PT = id_restore;
135  }
136 }
137 #undef ID_PT
138 
140  Sequence *seq,
141  void (*callback)(Main *, ID **))
142 {
143  callback(bmain, (ID **)&seq->scene);
144  callback(bmain, (ID **)&seq->scene_camera);
145  callback(bmain, (ID **)&seq->clip);
146  callback(bmain, (ID **)&seq->mask);
147  callback(bmain, (ID **)&seq->sound);
148 
149  if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) {
150  TextVars *text_data = seq->effectdata;
151  callback(bmain, (ID **)&text_data->text_font);
152  }
153 }
154 
155 /* recursive versions of functions above */
157 {
158  Sequence *seq;
159  for (seq = seqbase->first; seq; seq = seq->next) {
162  }
163 }
165 {
166  Sequence *seq;
167  for (seq = seqbase->first; seq; seq = seq->next) {
170  }
171 }
173 {
174  Sequence *seq;
175  for (seq = seqbase->first; seq; seq = seq->next) {
178  }
179 }
struct ListBase * which_libbase(struct Main *bmain, short type)
Definition: main.c:447
struct MovieClip * BKE_movieclip_file_add(struct Main *bmain, const char *name)
Definition: movieclip.c:987
struct bSound * BKE_sound_new_file(struct Main *main, const char *filepath)
#define BLI_assert(a)
Definition: BLI_assert.h:58
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNUSED(x)
@ ID_MC
Definition: DNA_ID_enums.h:85
@ ID_SO
Definition: DNA_ID_enums.h:76
@ SEQ_TYPE_TEXT
Read Guarded memory(de)allocation.
static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
Definition: clipboard.c:91
ListBase seqbase_clipboard
Definition: clipboard.c:56
static void seqclipboard_ptr_store(Main *UNUSED(bmain), ID **id_pt)
Definition: clipboard.c:83
void SEQ_clipboard_pointers_restore(ListBase *seqbase, Main *bmain)
Definition: clipboard.c:172
static void sequence_clipboard_pointers(Main *bmain, Sequence *seq, void(*callback)(Main *, ID **))
Definition: clipboard.c:139
#define ID_PT
Definition: clipboard.c:74
static void seqclipboard_ptr_free(Main *UNUSED(bmain), ID **id_pt)
Definition: clipboard.c:75
void seq_clipboard_pointers_free(struct ListBase *seqbase)
Definition: clipboard.c:156
int seqbase_clipboard_frame
Definition: clipboard.c:57
void SEQ_clipboard_pointers_store(Main *bmain, ListBase *seqbase)
Definition: clipboard.c:164
void SEQ_clipboard_free(void)
Definition: clipboard.c:61
DEGForeachIDComponentCallback callback
#define GS(x)
Definition: iris.c:241
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void seq_free_sequence_recurse(Scene *scene, Sequence *seq, const bool do_id_user)
Definition: sequencer.c:220
Definition: DNA_ID.h:273
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct MovieClip * clip
struct Scene * scene
struct Object * scene_camera
struct Mask * mask
ListBase seqbase
struct bSound * sound
struct Sequence * next
struct VFont * text_font