Welcome to mirror list, hosted at ThFree Co, Russian Federation.

clipboard.c « intern « sequencer « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82599a5fb6992ec3ff60650b3c6406e9b6a80fe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Copyright 2001-2002 NaN Holding BV. All rights reserved.
 *           2003-2009 Blender Foundation.
 *           2005-2006 Peter Schlaile <peter [at] schlaile [dot] de>
 */

/** \file
 * \ingroup bke
 */

#include <string.h>

#include "MEM_guardedalloc.h"

#include "DNA_anim_types.h"
#include "DNA_scene_types.h"
#include "DNA_sequence_types.h"
#include "DNA_sound_types.h"

#include "BLI_listbase.h"
#include "BLI_string.h"

#include "BKE_fcurve.h"
#include "BKE_main.h"
#include "BKE_movieclip.h"
#include "BKE_scene.h"
#include "BKE_sound.h"

#include "SEQ_clipboard.h"
#include "SEQ_select.h"

#include "sequencer.h"

#ifdef WITH_AUDASPACE
#  include <AUD_Special.h>
#endif

/* -------------------------------------------------------------------- */
/* Manage pointers in the clipboard.
 * note that these pointers should _never_ be access in the sequencer,
 * they are only for storage while in the clipboard
 * notice 'newid' is used for temp pointer storage here, validate on access (this is safe usage,
 * since those data-blocks are fully out of Main lists).
 */

ListBase seqbase_clipboard;
ListBase fcurves_clipboard;
int seqbase_clipboard_frame;
static char seq_clipboard_active_seq_name[SEQ_NAME_MAXSTR];

void seq_clipboard_pointers_free(struct ListBase *seqbase);

void SEQ_clipboard_free(void)
{
  seq_clipboard_pointers_free(&seqbase_clipboard);

  LISTBASE_FOREACH_MUTABLE (Sequence *, seq, &seqbase_clipboard) {
    seq_free_sequence_recurse(NULL, seq, false);
  }
  BLI_listbase_clear(&seqbase_clipboard);

  LISTBASE_FOREACH_MUTABLE (FCurve *, fcu, &fcurves_clipboard) {
    BKE_fcurve_free(fcu);
  }
  BLI_listbase_clear(&fcurves_clipboard);
}

#define ID_PT (*id_pt)
static void seqclipboard_ptr_free(Main *UNUSED(bmain), ID **id_pt)
{
  if (ID_PT) {
    BLI_assert(ID_PT->newid != NULL);
    MEM_freeN(ID_PT);
    ID_PT = NULL;
  }
}
static void seqclipboard_ptr_store(Main *UNUSED(bmain), ID **id_pt)
{
  if (ID_PT) {
    ID *id_prev = ID_PT;
    ID_PT = MEM_dupallocN(ID_PT);
    ID_PT->newid = id_prev;
  }
}
static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
{
  if (ID_PT) {
    const ListBase *lb = which_libbase(bmain, GS(ID_PT->name));
    void *id_restore;

    BLI_assert(ID_PT->newid != NULL);
    if (BLI_findindex(lb, (ID_PT)->newid) != -1) {
      /* the pointer is still valid */
      id_restore = (ID_PT)->newid;
    }
    else {
      /* The pointer of the same name still exists. */
      id_restore = BLI_findstring(lb, (ID_PT)->name + 2, offsetof(ID, name) + 2);
    }

    if (id_restore == NULL) {
      /* check for a data with the same filename */
      switch (GS(ID_PT->name)) {
        case ID_SO: {
          id_restore = BLI_findstring(lb, ((bSound *)ID_PT)->filepath, offsetof(bSound, filepath));
          if (id_restore == NULL) {
            id_restore = BKE_sound_new_file(bmain, ((bSound *)ID_PT)->filepath);
            (ID_PT)->newid = id_restore; /* reuse next time */
          }
          break;
        }
        case ID_MC: {
          id_restore = BLI_findstring(
              lb, ((MovieClip *)ID_PT)->filepath, offsetof(MovieClip, filepath));
          if (id_restore == NULL) {
            id_restore = BKE_movieclip_file_add(bmain, ((MovieClip *)ID_PT)->filepath);
            (ID_PT)->newid = id_restore; /* reuse next time */
          }
          break;
        }
        default:
          break;
      }
    }

    /* Replace with pointer to actual data-block. */
    seqclipboard_ptr_free(bmain, id_pt);
    ID_PT = id_restore;
  }
}
#undef ID_PT

static void sequence_clipboard_pointers(Main *bmain,
                                        Sequence *seq,
                                        void (*callback)(Main *, ID **))
{
  callback(bmain, (ID **)&seq->scene);
  callback(bmain, (ID **)&seq->scene_camera);
  callback(bmain, (ID **)&seq->clip);
  callback(bmain, (ID **)&seq->mask);
  callback(bmain, (ID **)&seq->sound);

  if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) {
    TextVars *text_data = seq->effectdata;
    callback(bmain, (ID **)&text_data->text_font);
  }
}

/* recursive versions of functions above */
void seq_clipboard_pointers_free(ListBase *seqbase)
{
  Sequence *seq;
  for (seq = seqbase->first; seq; seq = seq->next) {
    sequence_clipboard_pointers(NULL, seq, seqclipboard_ptr_free);
    seq_clipboard_pointers_free(&seq->seqbase);
  }
}
void SEQ_clipboard_pointers_store(Main *bmain, ListBase *seqbase)
{
  Sequence *seq;
  for (seq = seqbase->first; seq; seq = seq->next) {
    sequence_clipboard_pointers(bmain, seq, seqclipboard_ptr_store);
    SEQ_clipboard_pointers_store(bmain, &seq->seqbase);
  }
}
void SEQ_clipboard_pointers_restore(ListBase *seqbase, Main *bmain)
{
  Sequence *seq;
  for (seq = seqbase->first; seq; seq = seq->next) {
    sequence_clipboard_pointers(bmain, seq, seqclipboard_ptr_restore);
    SEQ_clipboard_pointers_restore(&seq->seqbase, bmain);
  }
}

void SEQ_clipboard_active_seq_name_store(Scene *scene)
{
  Sequence *active_seq = SEQ_select_active_get(scene);
  if (active_seq != NULL) {
    STRNCPY(seq_clipboard_active_seq_name, active_seq->name);
  }
  else {
    seq_clipboard_active_seq_name[0] = '\0';
  }
}

bool SEQ_clipboard_pasted_seq_was_active(Sequence *pasted_seq)
{
  return STREQ(pasted_seq->name, seq_clipboard_active_seq_name);
}