2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2011-08-04 07:12:03 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Jörg Müller.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/blenkernel/intern/speaker.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_sound_types.h"
|
|
|
|
|
#include "DNA_speaker_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
2011-10-27 05:34:39 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-08-04 07:12:03 +00:00
|
|
|
|
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_speaker.h"
|
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_speaker_init(Speaker *spk)
|
2011-08-04 07:12:03 +00:00
|
|
|
{
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(spk, id));
|
2011-08-04 07:12:03 +00:00
|
|
|
|
|
|
|
|
spk->attenuation = 1.0f;
|
|
|
|
|
spk->cone_angle_inner = 360.0f;
|
|
|
|
|
spk->cone_angle_outer = 360.0f;
|
|
|
|
|
spk->cone_volume_outer = 1.0f;
|
|
|
|
|
spk->distance_max = FLT_MAX;
|
|
|
|
|
spk->distance_reference = 1.0f;
|
|
|
|
|
spk->flag = 0;
|
|
|
|
|
spk->pitch = 1.0f;
|
|
|
|
|
spk->sound = NULL;
|
|
|
|
|
spk->volume = 1.0f;
|
|
|
|
|
spk->volume_max = 1.0f;
|
|
|
|
|
spk->volume_min = 0.0f;
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *BKE_speaker_add(Main *bmain, const char *name)
|
|
|
|
|
{
|
|
|
|
|
Speaker *spk;
|
|
|
|
|
|
|
|
|
|
spk = BKE_libblock_alloc(bmain, ID_SPK, name);
|
|
|
|
|
|
|
|
|
|
BKE_speaker_init(spk);
|
2011-08-04 07:12:03 +00:00
|
|
|
|
|
|
|
|
return spk;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
Speaker *BKE_speaker_copy(Speaker *spk)
|
2011-08-04 07:12:03 +00:00
|
|
|
{
|
|
|
|
|
Speaker *spkn;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
spkn = BKE_libblock_copy(&spk->id);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (spkn->sound)
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&spkn->sound->id);
|
2011-08-04 07:12:03 +00:00
|
|
|
|
2015-01-09 09:52:51 +01:00
|
|
|
if (spk->id.lib) {
|
|
|
|
|
BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-04 07:12:03 +00:00
|
|
|
return spkn;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 16:03:57 +00:00
|
|
|
void BKE_speaker_make_local(Speaker *spk)
|
2011-08-04 07:12:03 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Main *bmain = G.main;
|
2011-08-04 07:12:03 +00:00
|
|
|
Object *ob;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool is_local = false, is_lib = false;
|
2011-08-04 07:12:03 +00:00
|
|
|
|
|
|
|
|
/* - only lib users: do nothing
|
2012-03-03 20:19:11 +00:00
|
|
|
* - only local users: set flag
|
|
|
|
|
* - mixed: make copy
|
|
|
|
|
*/
|
2011-08-04 07:12:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (spk->id.lib == NULL) return;
|
|
|
|
|
if (spk->id.us == 1) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &spk->id);
|
2011-08-04 07:12:03 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = bmain->object.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (ob) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->data == spk) {
|
2014-04-01 11:34:00 +11:00
|
|
|
if (ob->id.lib) is_lib = true;
|
|
|
|
|
else is_local = true;
|
2011-08-04 07:12:03 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = ob->id.next;
|
2011-08-04 07:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
if (is_local && is_lib == false) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &spk->id);
|
2011-08-04 07:12:03 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (is_local && is_lib) {
|
2012-05-06 15:15:33 +00:00
|
|
|
Speaker *spk_new = BKE_speaker_copy(spk);
|
|
|
|
|
spk_new->id.us = 0;
|
2011-08-04 07:12:03 +00:00
|
|
|
|
2011-10-27 05:34:39 +00:00
|
|
|
/* Remap paths of new ID using old library as base. */
|
2011-11-30 00:32:13 +00:00
|
|
|
BKE_id_lib_local_paths(bmain, spk->id.lib, &spk_new->id);
|
2011-10-27 05:34:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = bmain->object.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (ob) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->data == spk) {
|
2011-08-04 07:12:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->id.lib == NULL) {
|
|
|
|
|
ob->data = spk_new;
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&spk_new->id);
|
|
|
|
|
id_us_min(&spk->id);
|
2011-08-04 07:12:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = ob->id.next;
|
2011-08-04 07:12:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_speaker_free(Speaker *spk)
|
2011-08-04 07:12:03 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (spk->sound)
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&spk->sound->id);
|
2011-08-04 07:12:03 +00:00
|
|
|
|
2015-04-04 15:13:56 +11:00
|
|
|
BKE_animdata_free((ID *)spk);
|
2011-08-04 07:12:03 +00:00
|
|
|
}
|