[Bf-blender-cvs] [69ef1a3] master: Py/RNA: support to load and remove sounds

Campbell Barton noreply at git.blender.org
Thu Apr 30 16:59:01 CEST 2015


Commit: 69ef1a3a83f47dbcc25d05c8a87f73fbfcd0667d
Author: Campbell Barton
Date:   Fri May 1 00:57:12 2015 +1000
Branches: master
https://developer.blender.org/rB69ef1a3a83f47dbcc25d05c8a87f73fbfcd0667d

Py/RNA: support to load and remove sounds

===================================================================

M	source/blender/makesrna/intern/rna_main_api.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 59c3bef..168f23c 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -61,6 +61,7 @@
 #include "BKE_image.h"
 #include "BKE_texture.h"
 #include "BKE_scene.h"
+#include "BKE_sound.h"
 #include "BKE_text.h"
 #include "BKE_action.h"
 #include "BKE_group.h"
@@ -87,6 +88,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_speaker_types.h"
+#include "DNA_sound_types.h"
 #include "DNA_text_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_group_types.h"
@@ -548,6 +550,25 @@ static void rna_Main_speakers_remove(Main *bmain, ReportList *reports, PointerRN
 	}
 }
 
+static bSound *rna_Main_sounds_load(Main *bmain, const char *name)
+{
+	bSound *sound = BKE_sound_new_file(bmain, name);
+	id_us_min(&sound->id);
+	return sound;
+}
+static void rna_Main_sounds_remove(Main *bmain, ReportList *reports, PointerRNA *sound_ptr)
+{
+	Speaker *sound = sound_ptr->data;
+	if (ID_REAL_USERS(sound) <= 0) {
+		BKE_libblock_free(bmain, sound);
+		RNA_POINTER_INVALIDATE(sound_ptr);
+	}
+	else {
+		BKE_reportf(reports, RPT_ERROR, "Sound '%s' must have zero users to be removed, found %d",
+		            sound->id.name + 2, ID_REAL_USERS(sound));
+	}
+}
+
 static Text *rna_Main_texts_new(Main *bmain, const char *name)
 {
 	return BKE_text_add(bmain, name);
@@ -1585,7 +1606,21 @@ void RNA_def_main_sounds(BlenderRNA *brna, PropertyRNA *cprop)
 	RNA_def_struct_sdna(srna, "Main");
 	RNA_def_struct_ui_text(srna, "Main Sounds", "Collection of sounds");
 
-	/* TODO, 'load' */
+	/* load func */
+	func = RNA_def_function(srna, "load", "rna_Main_sounds_load");
+	RNA_def_function_ui_description(func, "Add a new sound to the main database from a file");
+	parm = RNA_def_string_file_path(func, "filepath", "Path", FILE_MAX, "", "path for the datablock");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	/* return type */
+	parm = RNA_def_pointer(func, "sound", "Sound", "", "New text datablock");
+	RNA_def_function_return(func, parm);
+
+	func = RNA_def_function(srna, "remove", "rna_Main_sounds_remove");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_function_ui_description(func, "Remove a sound from the current blendfile");
+	parm = RNA_def_pointer(func, "sound", "Sound", "", "Sound to remove");
+	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
+	RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
 
 	func = RNA_def_function(srna, "tag", "rna_Main_sounds_tag");
 	parm = RNA_def_boolean(func, "value", 0, "Value", "");




More information about the Bf-blender-cvs mailing list