Blender
V2.93
source
blender
sequencer
intern
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
56
ListBase
seqbase_clipboard
;
57
int
seqbase_clipboard_frame
;
58
59
void
seq_clipboard_pointers_free
(
struct
ListBase
*seqbase);
60
61
void
SEQ_clipboard_free
(
void
)
62
{
63
Sequence
*seq, *nseq;
64
65
seq_clipboard_pointers_free
(&
seqbase_clipboard
);
66
67
for
(seq =
seqbase_clipboard
.
first
; seq; seq = nseq) {
68
nseq = seq->
next
;
69
seq_free_sequence_recurse
(
NULL
, seq,
false
);
70
}
71
BLI_listbase_clear
(&
seqbase_clipboard
);
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
);
79
MEM_freeN
(
ID_PT
);
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
;
87
ID_PT
=
MEM_dupallocN
(
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
139
static
void
sequence_clipboard_pointers
(
Main
*bmain,
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 */
156
void
seq_clipboard_pointers_free
(
ListBase
*seqbase)
157
{
158
Sequence
*seq;
159
for
(seq = seqbase->
first
; seq; seq = seq->
next
) {
160
sequence_clipboard_pointers
(
NULL
, seq,
seqclipboard_ptr_free
);
161
seq_clipboard_pointers_free
(&seq->
seqbase
);
162
}
163
}
164
void
SEQ_clipboard_pointers_store
(
Main
*bmain,
ListBase
*seqbase)
165
{
166
Sequence
*seq;
167
for
(seq = seqbase->
first
; seq; seq = seq->
next
) {
168
sequence_clipboard_pointers
(bmain, seq,
seqclipboard_ptr_store
);
169
SEQ_clipboard_pointers_store
(bmain, &seq->
seqbase
);
170
}
171
}
172
void
SEQ_clipboard_pointers_restore
(
ListBase
*seqbase,
Main
*bmain)
173
{
174
Sequence
*seq;
175
for
(seq = seqbase->
first
; seq; seq = seq->
next
) {
176
sequence_clipboard_pointers
(bmain, seq,
seqclipboard_ptr_restore
);
177
SEQ_clipboard_pointers_restore
(&seq->
seqbase
, bmain);
178
}
179
}
BKE_main.h
which_libbase
struct ListBase * which_libbase(struct Main *bmain, short type)
Definition:
main.c:447
BKE_movieclip.h
BKE_movieclip_file_add
struct MovieClip * BKE_movieclip_file_add(struct Main *bmain, const char *name)
Definition:
movieclip.c:987
BKE_scene.h
BKE_sound.h
BKE_sound_new_file
struct bSound * BKE_sound_new_file(struct Main *main, const char *filepath)
Definition:
blenkernel/intern/sound.c:258
BLI_assert
#define BLI_assert(a)
Definition:
BLI_assert.h:58
BLI_listbase.h
BLI_listbase_clear
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition:
BLI_listbase.h:128
BLI_findstring
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
BLI_findindex
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
UNUSED
#define UNUSED(x)
Definition:
BLI_utildefines.h:683
ID_MC
@ ID_MC
Definition:
DNA_ID_enums.h:85
ID_SO
@ ID_SO
Definition:
DNA_ID_enums.h:76
DNA_scene_types.h
DNA_sequence_types.h
SEQ_TYPE_TEXT
@ SEQ_TYPE_TEXT
Definition:
DNA_sequence_types.h:600
DNA_sound_types.h
MEM_guardedalloc.h
Read Guarded memory(de)allocation.
SEQ_clipboard.h
NULL
return NULL
Definition:
bmesh_operator_api_inline.h:224
seqclipboard_ptr_restore
static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
Definition:
clipboard.c:91
seqbase_clipboard
ListBase seqbase_clipboard
Definition:
clipboard.c:56
seqclipboard_ptr_store
static void seqclipboard_ptr_store(Main *UNUSED(bmain), ID **id_pt)
Definition:
clipboard.c:83
SEQ_clipboard_pointers_restore
void SEQ_clipboard_pointers_restore(ListBase *seqbase, Main *bmain)
Definition:
clipboard.c:172
sequence_clipboard_pointers
static void sequence_clipboard_pointers(Main *bmain, Sequence *seq, void(*callback)(Main *, ID **))
Definition:
clipboard.c:139
ID_PT
#define ID_PT
Definition:
clipboard.c:74
seqclipboard_ptr_free
static void seqclipboard_ptr_free(Main *UNUSED(bmain), ID **id_pt)
Definition:
clipboard.c:75
seq_clipboard_pointers_free
void seq_clipboard_pointers_free(struct ListBase *seqbase)
Definition:
clipboard.c:156
seqbase_clipboard_frame
int seqbase_clipboard_frame
Definition:
clipboard.c:57
SEQ_clipboard_pointers_store
void SEQ_clipboard_pointers_store(Main *bmain, ListBase *seqbase)
Definition:
clipboard.c:164
SEQ_clipboard_free
void SEQ_clipboard_free(void)
Definition:
clipboard.c:61
callback
DEGForeachIDComponentCallback callback
Definition:
depsgraph_query_foreach.cc:125
GS
#define GS(x)
Definition:
iris.c:241
MEM_freeN
void(* MEM_freeN)(void *vmemh)
Definition:
mallocn.c:41
MEM_dupallocN
void *(* MEM_dupallocN)(const void *vmemh)
Definition:
mallocn.c:42
seq_free_sequence_recurse
void seq_free_sequence_recurse(Scene *scene, Sequence *seq, const bool do_id_user)
Definition:
sequencer.c:220
sequencer.h
ID
Definition:
DNA_ID.h:273
ListBase
Definition:
DNA_listBase.h:46
ListBase::first
void * first
Definition:
DNA_listBase.h:47
Main
Definition:
BKE_main.h:116
MovieClip
Definition:
DNA_movieclip_types.h:74
Sequence
Definition:
DNA_sequence_types.h:140
Sequence::clip
struct MovieClip * clip
Definition:
DNA_sequence_types.h:194
Sequence::scene
struct Scene * scene
Definition:
DNA_sequence_types.h:190
Sequence::effectdata
void * effectdata
Definition:
DNA_sequence_types.h:219
Sequence::scene_camera
struct Object * scene_camera
Definition:
DNA_sequence_types.h:192
Sequence::mask
struct Mask * mask
Definition:
DNA_sequence_types.h:196
Sequence::type
int type
Definition:
DNA_sequence_types.h:150
Sequence::seqbase
ListBase seqbase
Definition:
DNA_sequence_types.h:207
Sequence::sound
struct bSound * sound
Definition:
DNA_sequence_types.h:210
Sequence::next
struct Sequence * next
Definition:
DNA_sequence_types.h:141
TextVars
Definition:
DNA_sequence_types.h:340
TextVars::text_font
struct VFont * text_font
Definition:
DNA_sequence_types.h:342
bSound
Definition:
DNA_sound_types.h:35
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1