header cleanup (no functional changes)
[blender.git] / source / blender / blenkernel / intern / speaker.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): Jörg Müller.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/blenkernel/intern/speaker.c
31  *  \ingroup bke
32  */
33
34 #include "DNA_object_types.h"
35 #include "DNA_sound_types.h"
36 #include "DNA_speaker_types.h"
37
38 #include "BLI_math.h"
39
40 #include "BKE_animsys.h"
41 #include "BKE_global.h"
42 #include "BKE_library.h"
43 #include "BKE_main.h"
44 #include "BKE_speaker.h"
45
46 void *add_speaker(const char *name)
47 {
48         Speaker *spk;
49
50         spk=  alloc_libblock(&G.main->speaker, ID_SPK, name);
51
52         spk->attenuation = 1.0f;
53         spk->cone_angle_inner = 360.0f;
54         spk->cone_angle_outer = 360.0f;
55         spk->cone_volume_outer = 1.0f;
56         spk->distance_max = FLT_MAX;
57         spk->distance_reference = 1.0f;
58         spk->flag = 0;
59         spk->pitch = 1.0f;
60         spk->sound = NULL;
61         spk->volume = 1.0f;
62         spk->volume_max = 1.0f;
63         spk->volume_min = 0.0f;
64
65         return spk;
66 }
67
68 Speaker *copy_speaker(Speaker *spk)
69 {
70         Speaker *spkn;
71
72         spkn= copy_libblock(spk);
73         if(spkn->sound)
74                 spkn->sound->id.us++;
75
76         return spkn;
77 }
78
79 void make_local_speaker(Speaker *spk)
80 {
81         Main *bmain= G.main;
82         Object *ob;
83         int local=0, lib=0;
84
85         /* - only lib users: do nothing
86                 * - only local users: set flag
87                 * - mixed: make copy
88                 */
89
90         if(spk->id.lib==NULL) return;
91         if(spk->id.us==1) {
92                 spk->id.lib= NULL;
93                 spk->id.flag= LIB_LOCAL;
94                 new_id(&bmain->speaker, (ID *)spk, NULL);
95                 return;
96         }
97
98         ob= bmain->object.first;
99         while(ob) {
100                 if(ob->data==spk) {
101                         if(ob->id.lib) lib= 1;
102                         else local= 1;
103                 }
104                 ob= ob->id.next;
105         }
106
107         if(local && lib==0) {
108                 spk->id.lib= NULL;
109                 spk->id.flag= LIB_LOCAL;
110                 new_id(&bmain->speaker, (ID *)spk, NULL);
111         }
112         else if(local && lib) {
113                 Speaker *spkn= copy_speaker(spk);
114                 spkn->id.us= 0;
115
116                 ob= bmain->object.first;
117                 while(ob) {
118                         if(ob->data==spk) {
119
120                                 if(ob->id.lib==NULL) {
121                                         ob->data= spkn;
122                                         spkn->id.us++;
123                                         spk->id.us--;
124                                 }
125                         }
126                         ob= ob->id.next;
127                 }
128         }
129 }
130
131 void free_speaker(Speaker *spk)
132 {
133         if(spk->sound)
134                 spk->sound->id.us--;
135
136         BKE_free_animdata((ID *)spk);
137 }