[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24759] trunk/blender/source/blender: Added a first version of the Sound F-Curve Modifier, not really usable yet , but you can play around with it.

Joerg Mueller nexyon at gmail.com
Sun Nov 22 13:10:46 CET 2009


Revision: 24759
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24759
Author:   nexyon
Date:     2009-11-22 13:10:45 +0100 (Sun, 22 Nov 2009)

Log Message:
-----------
Added a first version of the Sound F-Curve Modifier, not really usable yet, but you can play around with it.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/fmodifier.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/animation/fmodifier_ui.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/space_graph/graph_buttons.c
    trunk/blender/source/blender/editors/space_nla/nla_buttons.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c

Modified: trunk/blender/source/blender/blenkernel/intern/fmodifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fmodifier.c	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/blenkernel/intern/fmodifier.c	2009-11-22 12:10:45 UTC (rev 24759)
@@ -53,6 +53,8 @@
 #include "RNA_access.h"
 #include "RNA_types.h"
 
+#include "AUD_C-API.h"
+
 #ifndef DISABLE_PYTHON
 #include "BPY_extern.h" /* for BPY_pydriver_eval() */
 #endif
@@ -871,6 +873,91 @@
 	fcm_limits_evaluate /* evaluate */
 };
 
+/* Sound F-Curve Modifier  --------------------------- */
+
+static void fcm_sound_new_data (void *mdata)
+{
+	FMod_Sound *data= (FMod_Sound *)mdata;
+
+	/* defaults */
+	data->strength= 1.0f;
+	data->delay = 0.0f;
+	data->modification = FCM_SOUND_MODIF_REPLACE;
+	data->sound = NULL;
+}
+
+static void fcm_sound_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
+{
+	FMod_Sound *data= (FMod_Sound *)fcm->data;
+	float amplitude;
+
+	AUD_Device* device;
+	SoundHandle* handle;
+	AUD_Sound* limiter;
+	AUD_SoundInfo info;
+
+//	evaltime = FRA2TIME(evaltime);
+	evaltime -= data->delay;
+
+	if(evaltime < 0.0f || data->sound == NULL || data->sound->cache == NULL)
+		return;
+
+	info = AUD_getInfo(data->sound->cache);
+	info.specs.channels = 1;
+	info.specs.format = AUD_FORMAT_FLOAT32;
+	device = AUD_openReadDevice(info.specs);
+	limiter = AUD_limitSound(data->sound->cache, evaltime, evaltime + 1);
+	AUD_playDevice(device, limiter);
+	AUD_unload(limiter);
+	AUD_readDevice(device, &amplitude, 1);
+	AUD_closeReadDevice(device);
+
+	/* combine the amplitude with existing motion data */
+	switch (data->modification) {
+		case FCM_SOUND_MODIF_ADD:
+			*cvalue= *cvalue + amplitude * data->strength;
+			break;
+		case FCM_SOUND_MODIF_SUBTRACT:
+			*cvalue= *cvalue - amplitude * data->strength;
+			break;
+		case FCM_SOUND_MODIF_MULTIPLY:
+			*cvalue= *cvalue * amplitude * data->strength;
+			break;
+		case FCM_SOUND_MODIF_REPLACE:
+		default:
+			*cvalue= *cvalue + amplitude * data->strength;
+			break;
+	}
+}
+
+static float fcm_sound_time (FCurve *fcu, FModifier *fcm, float cvalue, float evaltime)
+{
+	FMod_Sound *data= (FMod_Sound *)fcm->data;
+
+	/* check for the time delay */
+//	evaltime = FRA2TIME(evaltime);
+	if(evaltime < data->delay)
+		return data->delay;
+
+	/* modifier doesn't change time */
+	return evaltime;
+}
+
+static FModifierTypeInfo FMI_SOUND = {
+	FMODIFIER_TYPE_SOUND, /* type */
+	sizeof(FMod_Sound), /* size */
+	FMI_TYPE_REPLACE_VALUES, /* action type */
+	0, /* requirements */
+	"Sound", /* name */
+	"FMod_Sound", /* struct name */
+	NULL, /* free data */
+	NULL, /* copy data */
+	fcm_sound_new_data, /* new data */
+	NULL, /* verify */
+	fcm_sound_time, /* evaluate time */
+	fcm_sound_evaluate /* evaluate */
+};
+
 /* F-Curve Modifier API --------------------------- */
 /* All of the F-Curve Modifier api functions use FModifierTypeInfo structs to carry out
  * and operations that involve F-Curve modifier specific code.
@@ -892,6 +979,7 @@
 	fmodifiersTypeInfo[6]=  NULL/*&FMI_FILTER*/;			/* Filter F-Curve Modifier */  // XXX unimplemented
 	fmodifiersTypeInfo[7]=  &FMI_PYTHON;			/* Custom Python F-Curve Modifier */
 	fmodifiersTypeInfo[8]= 	&FMI_LIMITS;			/* Limits F-Curve Modifier */
+	fmodifiersTypeInfo[9]= 	&FMI_SOUND;				/* Sound F-Curve Modifier */
 }
 
 /* This function should be used for getting the appropriate type-info when only

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-11-22 12:10:45 UTC (rev 24759)
@@ -1694,6 +1694,12 @@
 				data->script = newlibadr(fd, id->lib, data->script);
 			}
 				break;
+			case FMODIFIER_TYPE_SOUND:
+			{
+				FMod_Sound *data= (FMod_Sound *)fcm->data;
+				data->sound = newlibadr(fd, id->lib, data->sound);
+			}
+				break;
 		}
 	}
 }
@@ -10440,6 +10446,13 @@
 				expand_doit(fd, mainvar, data->script);
 			}
 				break;
+			case FMODIFIER_TYPE_SOUND:
+			{
+				FMod_Sound *data= (FMod_Sound *)fcm->data;
+
+				expand_doit(fd, mainvar, data->sound);
+			}
+				break;
 		}
 	}
 }

Modified: trunk/blender/source/blender/editors/animation/fmodifier_ui.c
===================================================================
--- trunk/blender/source/blender/editors/animation/fmodifier_ui.c	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/editors/animation/fmodifier_ui.c	2009-11-22 12:10:45 UTC (rev 24759)
@@ -247,7 +247,7 @@
 
 /* --------------- */
 
-/* draw settings for noise modifier */
+/* draw settings for generator modifier */
 static void draw_modifier__fn_generator(uiLayout *layout, ID *id, FModifier *fcm, short width)
 {
 	uiLayout *col;
@@ -327,6 +327,49 @@
 
 /* --------------- */
 
+/* draw settings for sound modifier */
+static void draw_modifier__sound(const bContext *C, uiLayout *layout, ID *id, FModifier *fcm, short width)
+{
+	uiLayout *split, *col;
+	PointerRNA ptr;
+	FMod_Sound *data= (FMod_Sound *)fcm->data;
+
+	/* init the RNA-pointer */
+	RNA_pointer_create(id, &RNA_FModifierSound, fcm, &ptr);
+
+	/* sound */
+	uiTemplateID(layout, C, &ptr, "sound", NULL, "sound.open", NULL);
+
+	if(data->sound)
+	{
+		if(data->sound->cache)
+		{
+			/* blending mode */
+			uiItemR(layout, NULL, 0, &ptr, "modification", 0);
+
+			/* split into 2 columns */
+			split= uiLayoutSplit(layout, 0.5f);
+
+			/* col 1 */
+			col= uiLayoutColumn(split, 0);
+			uiItemR(col, NULL, 0, &ptr, "strength", 0);
+
+			/* col 2 */
+			col= uiLayoutColumn(split, 0);
+			uiItemR(col, NULL, 0, &ptr, "delay", 0);
+		}
+		else
+		{
+			PointerRNA ptr2;
+			RNA_id_pointer_create(data->sound, &ptr2);
+			uiItemL(layout, "Sound must be cached.", ICON_ERROR);
+			uiItemR(layout, NULL, 0, &ptr2, "caching", UI_ITEM_R_TOGGLE);
+		}
+	}
+}
+
+/* --------------- */
+
 #define BINARYSEARCH_FRAMEEQ_THRESH	0.0001
 
 /* Binary search algorithm for finding where to insert Envelope Data Point.
@@ -590,7 +633,7 @@
 /* --------------- */
 
 
-void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
+void ANIM_uiTemplate_fmodifier_draw (const bContext *C, uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
 {
 	FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
 	uiLayout *box, *row, *subrow;
@@ -665,11 +708,15 @@
 			case FMODIFIER_TYPE_LIMITS: /* Limits */
 				draw_modifier__limits(box, id, fcm, width);
 				break;
-			
+
 			case FMODIFIER_TYPE_NOISE: /* Noise */
 				draw_modifier__noise(box, id, fcm, width);
 				break;
-			
+
+			case FMODIFIER_TYPE_SOUND: /* Sound */
+				draw_modifier__sound(C, box, id, fcm, width);
+				break;
+
 			default: /* unknown type */
 				break;
 		}

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h	2009-11-22 12:10:45 UTC (rev 24759)
@@ -418,7 +418,7 @@
 /* F-MODIFIER TOOLS */
 
 /* draw a given F-Modifier for some layout/UI-Block */
-void ANIM_uiTemplate_fmodifier_draw(struct uiLayout *layout, struct ID *id, ListBase *modifiers, struct FModifier *fcm);
+void ANIM_uiTemplate_fmodifier_draw(const struct bContext *C, struct uiLayout *layout, struct ID *id, ListBase *modifiers, struct FModifier *fcm);
 
 /* ************************************************* */
 /* ASSORTED TOOLS */

Modified: trunk/blender/source/blender/editors/space_graph/graph_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_buttons.c	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/editors/space_graph/graph_buttons.c	2009-11-22 12:10:45 UTC (rev 24759)
@@ -450,7 +450,7 @@
 	for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
 		col= uiLayoutColumn(pa->layout, 1);
 		
-		ANIM_uiTemplate_fmodifier_draw(col, ale->id, &fcu->modifiers, fcm);
+		ANIM_uiTemplate_fmodifier_draw(C, col, ale->id, &fcu->modifiers, fcm);
 	}
 
 	MEM_freeN(ale);

Modified: trunk/blender/source/blender/editors/space_nla/nla_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_nla/nla_buttons.c	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/editors/space_nla/nla_buttons.c	2009-11-22 12:10:45 UTC (rev 24759)
@@ -434,7 +434,7 @@
 	for (fcm= strip->modifiers.first; fcm; fcm= fcm->next) {
 		col= uiLayoutColumn(pa->layout, 1);
 		
-		ANIM_uiTemplate_fmodifier_draw(col, strip_ptr.id.data, &strip->modifiers, fcm);
+		ANIM_uiTemplate_fmodifier_draw(C, col, strip_ptr.id.data, &strip->modifiers, fcm);
 	}
 }
 

Modified: trunk/blender/source/blender/makesdna/DNA_anim_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_anim_types.h	2009-11-22 11:33:44 UTC (rev 24758)
+++ trunk/blender/source/blender/makesdna/DNA_anim_types.h	2009-11-22 12:10:45 UTC (rev 24759)
@@ -36,6 +36,7 @@
 #include "DNA_listBase.h"
 #include "DNA_action_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_sound_types.h"
 
 /* ************************************************ */
 /* F-Curve DataTypes */
@@ -73,6 +74,7 @@
 	FMODIFIER_TYPE_FILTER,		/* unimplemented - for applying: fft, high/low pass filters, etc. */
 	FMODIFIER_TYPE_PYTHON,	
 	FMODIFIER_TYPE_LIMITS,
+	FMODIFIER_TYPE_SOUND,
 	
 	/* NOTE: all new modifiers must be added above this line */
 	FMODIFIER_NUM_TYPES
@@ -230,6 +232,25 @@
 	FCM_NOISE_MODIF_MULTIPLY,		/* Multiply the curve by noise */
 } eFMod_Noise_Modifications;
 
+/* sound modifier data */
+typedef struct FMod_Sound {
+	float strength;
+	float delay;
+
+	short modification;
+	short pad[3];
+
+	bSound *sound;
+} FMod_Sound;
+
+/* modification modes */
+typedef enum eFMod_Sound_Modifications {
+	FCM_SOUND_MODIF_REPLACE = 0,	/* Modify existing curve, matching it's shape */
+	FCM_SOUND_MODIF_ADD,			/* Add amplitude to the curve */
+	FCM_SOUND_MODIF_SUBTRACT,		/* Subtract amplitude from the curve */
+	FCM_SOUND_MODIF_MULTIPLY,		/* Multiply the curve by amplitude */
+} eFMod_Sound_Modifications;
+
 /* Drivers -------------------------------------- */
 
 /* Driver Target 


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list