Blender  V3.3
clipboard.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved.
3  * 2003-2009 Blender Foundation.
4  * 2005-2006 Peter Schlaile <peter [at] schlaile [dot] de> */
5 
10 #include <string.h>
11 
12 #include "MEM_guardedalloc.h"
13 
14 #include "DNA_anim_types.h"
15 #include "DNA_scene_types.h"
16 #include "DNA_sequence_types.h"
17 #include "DNA_sound_types.h"
18 
19 #include "BLI_listbase.h"
20 #include "BLI_string.h"
21 
22 #include "BKE_fcurve.h"
23 #include "BKE_main.h"
24 #include "BKE_movieclip.h"
25 #include "BKE_scene.h"
26 #include "BKE_sound.h"
27 
28 #include "SEQ_clipboard.h"
29 #include "SEQ_select.h"
30 
31 #include "sequencer.h"
32 
33 #ifdef WITH_AUDASPACE
34 # include <AUD_Special.h>
35 #endif
36 
37 /* -------------------------------------------------------------------- */
38 /* Manage pointers in the clipboard.
39  * note that these pointers should _never_ be access in the sequencer,
40  * they are only for storage while in the clipboard
41  * notice 'newid' is used for temp pointer storage here, validate on access (this is safe usage,
42  * since those data-blocks are fully out of Main lists).
43  */
44 
49 
50 void seq_clipboard_pointers_free(struct ListBase *seqbase);
51 
53 {
55 
57  seq_free_sequence_recurse(NULL, seq, false);
58  }
60 
62  BKE_fcurve_free(fcu);
63  }
65 }
66 
67 #define ID_PT (*id_pt)
68 static void seqclipboard_ptr_free(Main *UNUSED(bmain), ID **id_pt)
69 {
70  if (ID_PT) {
71  BLI_assert(ID_PT->newid != NULL);
73  ID_PT = NULL;
74  }
75 }
76 static void seqclipboard_ptr_store(Main *UNUSED(bmain), ID **id_pt)
77 {
78  if (ID_PT) {
79  ID *id_prev = ID_PT;
81  ID_PT->newid = id_prev;
82  }
83 }
84 static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
85 {
86  if (ID_PT) {
87  const ListBase *lb = which_libbase(bmain, GS(ID_PT->name));
88  void *id_restore;
89 
90  BLI_assert(ID_PT->newid != NULL);
91  if (BLI_findindex(lb, (ID_PT)->newid) != -1) {
92  /* the pointer is still valid */
93  id_restore = (ID_PT)->newid;
94  }
95  else {
96  /* The pointer of the same name still exists. */
97  id_restore = BLI_findstring(lb, (ID_PT)->name + 2, offsetof(ID, name) + 2);
98  }
99 
100  if (id_restore == NULL) {
101  /* check for a data with the same filename */
102  switch (GS(ID_PT->name)) {
103  case ID_SO: {
104  id_restore = BLI_findstring(lb, ((bSound *)ID_PT)->filepath, offsetof(bSound, filepath));
105  if (id_restore == NULL) {
106  id_restore = BKE_sound_new_file(bmain, ((bSound *)ID_PT)->filepath);
107  (ID_PT)->newid = id_restore; /* reuse next time */
108  }
109  break;
110  }
111  case ID_MC: {
112  id_restore = BLI_findstring(
113  lb, ((MovieClip *)ID_PT)->filepath, offsetof(MovieClip, filepath));
114  if (id_restore == NULL) {
115  id_restore = BKE_movieclip_file_add(bmain, ((MovieClip *)ID_PT)->filepath);
116  (ID_PT)->newid = id_restore; /* reuse next time */
117  }
118  break;
119  }
120  default:
121  break;
122  }
123  }
124 
125  /* Replace with pointer to actual data-block. */
126  seqclipboard_ptr_free(bmain, id_pt);
127  ID_PT = id_restore;
128  }
129 }
130 #undef ID_PT
131 
133  Sequence *seq,
134  void (*callback)(Main *, ID **))
135 {
136  callback(bmain, (ID **)&seq->scene);
137  callback(bmain, (ID **)&seq->scene_camera);
138  callback(bmain, (ID **)&seq->clip);
139  callback(bmain, (ID **)&seq->mask);
140  callback(bmain, (ID **)&seq->sound);
141 
142  if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) {
143  TextVars *text_data = seq->effectdata;
144  callback(bmain, (ID **)&text_data->text_font);
145  }
146 }
147 
148 /* recursive versions of functions above */
150 {
151  Sequence *seq;
152  for (seq = seqbase->first; seq; seq = seq->next) {
155  }
156 }
158 {
159  Sequence *seq;
160  for (seq = seqbase->first; seq; seq = seq->next) {
163  }
164 }
166 {
167  Sequence *seq;
168  for (seq = seqbase->first; seq; seq = seq->next) {
171  }
172 }
173 
175 {
176  Sequence *active_seq = SEQ_select_active_get(scene);
177  if (active_seq != NULL) {
179  }
180  else {
182  }
183 }
184 
186 {
187  return STREQ(pasted_seq->name, seq_clipboard_active_seq_name);
188 }
void BKE_fcurve_free(struct FCurve *fcu)
Definition: fcurve.c:65
struct ListBase * which_libbase(struct Main *bmain, short type)
Definition: main.c:567
struct MovieClip * BKE_movieclip_file_add(struct Main *bmain, const char *name)
Definition: movieclip.c:967
struct bSound * BKE_sound_new_file(struct Main *main, const char *filepath)
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:354
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:273
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
#define UNUSED(x)
#define STREQ(a, b)
@ ID_MC
Definition: DNA_ID_enums.h:73
@ ID_SO
Definition: DNA_ID_enums.h:64
@ SEQ_TYPE_TEXT
#define SEQ_NAME_MAXSTR
Read Guarded memory(de)allocation.
static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
Definition: clipboard.c:84
ListBase seqbase_clipboard
Definition: clipboard.c:45
static void seqclipboard_ptr_store(Main *UNUSED(bmain), ID **id_pt)
Definition: clipboard.c:76
void SEQ_clipboard_pointers_restore(ListBase *seqbase, Main *bmain)
Definition: clipboard.c:165
static char seq_clipboard_active_seq_name[SEQ_NAME_MAXSTR]
Definition: clipboard.c:48
static void sequence_clipboard_pointers(Main *bmain, Sequence *seq, void(*callback)(Main *, ID **))
Definition: clipboard.c:132
void SEQ_clipboard_active_seq_name_store(Scene *scene)
Definition: clipboard.c:174
#define ID_PT
Definition: clipboard.c:67
bool SEQ_clipboard_pasted_seq_was_active(Sequence *pasted_seq)
Definition: clipboard.c:185
static void seqclipboard_ptr_free(Main *UNUSED(bmain), ID **id_pt)
Definition: clipboard.c:68
void seq_clipboard_pointers_free(struct ListBase *seqbase)
Definition: clipboard.c:149
int seqbase_clipboard_frame
Definition: clipboard.c:47
ListBase fcurves_clipboard
Definition: clipboard.c:46
void SEQ_clipboard_pointers_store(Main *bmain, ListBase *seqbase)
Definition: clipboard.c:157
void SEQ_clipboard_free(void)
Definition: clipboard.c:52
Scene scene
DEGForeachIDComponentCallback callback
#define GS(x)
Definition: iris.c:225
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void seq_free_sequence_recurse(Scene *scene, Sequence *seq, const bool do_id_user)
Definition: sequencer.c:229
Sequence * SEQ_select_active_get(Scene *scene)
Definition: strip_select.c:18
Definition: DNA_ID.h:368
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
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