Blender V2.61 - r43446

speaker.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): Jörg Müller.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #include "DNA_object_types.h"
00033 #include "DNA_sound_types.h"
00034 #include "DNA_speaker_types.h"
00035 
00036 #include "BLI_math.h"
00037 #include "BLI_utildefines.h"
00038 #include "BLI_bpath.h"
00039 
00040 #include "BKE_animsys.h"
00041 #include "BKE_global.h"
00042 #include "BKE_library.h"
00043 #include "BKE_main.h"
00044 #include "BKE_speaker.h"
00045 
00046 void *add_speaker(const char *name)
00047 {
00048     Speaker *spk;
00049 
00050     spk=  alloc_libblock(&G.main->speaker, ID_SPK, name);
00051 
00052     spk->attenuation = 1.0f;
00053     spk->cone_angle_inner = 360.0f;
00054     spk->cone_angle_outer = 360.0f;
00055     spk->cone_volume_outer = 1.0f;
00056     spk->distance_max = FLT_MAX;
00057     spk->distance_reference = 1.0f;
00058     spk->flag = 0;
00059     spk->pitch = 1.0f;
00060     spk->sound = NULL;
00061     spk->volume = 1.0f;
00062     spk->volume_max = 1.0f;
00063     spk->volume_min = 0.0f;
00064 
00065     return spk;
00066 }
00067 
00068 Speaker *copy_speaker(Speaker *spk)
00069 {
00070     Speaker *spkn;
00071 
00072     spkn= copy_libblock(&spk->id);
00073     if(spkn->sound)
00074         spkn->sound->id.us++;
00075 
00076     return spkn;
00077 }
00078 
00079 void make_local_speaker(Speaker *spk)
00080 {
00081     Main *bmain= G.main;
00082     Object *ob;
00083     int is_local= FALSE, is_lib= FALSE;
00084 
00085     /* - only lib users: do nothing
00086         * - only local users: set flag
00087         * - mixed: make copy
00088         */
00089 
00090     if(spk->id.lib==NULL) return;
00091     if(spk->id.us==1) {
00092         id_clear_lib_data(bmain, &spk->id);
00093         return;
00094     }
00095 
00096     ob= bmain->object.first;
00097     while(ob) {
00098         if(ob->data==spk) {
00099             if(ob->id.lib) is_lib= TRUE;
00100             else is_local= TRUE;
00101         }
00102         ob= ob->id.next;
00103     }
00104 
00105     if(is_local && is_lib == FALSE) {
00106         id_clear_lib_data(bmain, &spk->id);
00107     }
00108     else if(is_local && is_lib) {
00109         Speaker *spk_new= copy_speaker(spk);
00110         spk_new->id.us= 0;
00111 
00112         /* Remap paths of new ID using old library as base. */
00113         BKE_id_lib_local_paths(bmain, spk->id.lib, &spk_new->id);
00114 
00115         ob= bmain->object.first;
00116         while(ob) {
00117             if(ob->data==spk) {
00118 
00119                 if(ob->id.lib==NULL) {
00120                     ob->data= spk_new;
00121                     spk_new->id.us++;
00122                     spk->id.us--;
00123                 }
00124             }
00125             ob= ob->id.next;
00126         }
00127     }
00128 }
00129 
00130 void free_speaker(Speaker *spk)
00131 {
00132     if(spk->sound)
00133         spk->sound->id.us--;
00134 
00135     BKE_free_animdata((ID *)spk);
00136 }