Cleanup: improve comment about shape keys, correct spelling
[blender.git] / source / blender / blenkernel / intern / speaker.c
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
17 /** \file
18  * \ingroup bke
19  */
20
21 #include "DNA_defaults.h"
22 #include "DNA_object_types.h"
23 #include "DNA_sound_types.h"
24 #include "DNA_speaker_types.h"
25
26 #include "BLI_math.h"
27 #include "BLI_utildefines.h"
28
29 #include "BLT_translation.h"
30
31 #include "BKE_anim_data.h"
32 #include "BKE_idtype.h"
33 #include "BKE_lib_id.h"
34 #include "BKE_lib_query.h"
35 #include "BKE_main.h"
36 #include "BKE_speaker.h"
37
38 #include "BLO_read_write.h"
39
40 static void speaker_init_data(ID *id)
41 {
42   Speaker *speaker = (Speaker *)id;
43
44   BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(speaker, id));
45
46   MEMCPY_STRUCT_AFTER(speaker, DNA_struct_default_get(Speaker), id);
47 }
48
49 static void speaker_foreach_id(ID *id, LibraryForeachIDData *data)
50 {
51   Speaker *speaker = (Speaker *)id;
52
53   BKE_LIB_FOREACHID_PROCESS(data, speaker->sound, IDWALK_CB_USER);
54 }
55
56 static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address)
57 {
58   Speaker *spk = (Speaker *)id;
59   if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
60     /* write LibData */
61     BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
62     BKE_id_blend_write(writer, &spk->id);
63
64     if (spk->adt) {
65       BKE_animdata_blend_write(writer, spk->adt);
66     }
67   }
68 }
69
70 static void speaker_blend_read_data(BlendDataReader *reader, ID *id)
71 {
72   Speaker *spk = (Speaker *)id;
73   BLO_read_data_address(reader, &spk->adt);
74   BKE_animdata_blend_read_data(reader, spk->adt);
75
76 #if 0
77   spk->sound = newdataadr(fd, spk->sound);
78   direct_link_sound(fd, spk->sound);
79 #endif
80 }
81
82 static void speaker_blend_read_lib(BlendLibReader *reader, ID *id)
83 {
84   Speaker *spk = (Speaker *)id;
85   BLO_read_id_address(reader, spk->id.lib, &spk->sound);
86 }
87
88 static void speaker_blend_read_expand(BlendExpander *expander, ID *id)
89 {
90   Speaker *spk = (Speaker *)id;
91   BLO_expand(expander, spk->sound);
92 }
93
94 IDTypeInfo IDType_ID_SPK = {
95     .id_code = ID_SPK,
96     .id_filter = FILTER_ID_SPK,
97     .main_listbase_index = INDEX_ID_SPK,
98     .struct_size = sizeof(Speaker),
99     .name = "Speaker",
100     .name_plural = "speakers",
101     .translation_context = BLT_I18NCONTEXT_ID_SPEAKER,
102     .flags = 0,
103
104     .init_data = speaker_init_data,
105     .copy_data = NULL,
106     .free_data = NULL,
107     .make_local = NULL,
108     .foreach_id = speaker_foreach_id,
109     .foreach_cache = NULL,
110
111     .blend_write = speaker_blend_write,
112     .blend_read_data = speaker_blend_read_data,
113     .blend_read_lib = speaker_blend_read_lib,
114     .blend_read_expand = speaker_blend_read_expand,
115 };
116
117 void *BKE_speaker_add(Main *bmain, const char *name)
118 {
119   Speaker *spk;
120
121   spk = BKE_id_new(bmain, ID_SPK, name);
122
123   return spk;
124 }