Reverted the addition of the f-curve sound modifier (was added in revision 24759) due to unusability and performance issues. The ability to use a sound as animation source will be added as an import operator later that renders a sound to an f-curve which brings the advantage that you can edit the generated curve later and the disadvantage it is not automatically updated when the sound changes.

This commit is contained in:
Joerg Mueller 2009-12-24 14:01:22 +00:00
parent bb452f29d6
commit a2b0020e11
9 changed files with 6 additions and 222 deletions

@ -53,8 +53,6 @@
#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
@ -873,96 +871,6 @@ static FModifierTypeInfo FMI_LIMITS = {
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;
AUD_Sound *limiter;
AUD_SoundInfo info;
// XXX fixme - need to get in terms of time instead of frames to be really useful
// evaltime = FRA2TIME(evaltime);
evaltime -= data->delay;
/* sound-system cannot cope with negative times/frames */
if (evaltime < 0.0f)
return;
/* must have a sound with a cache so that this can be used */
if (ELEM(NULL, data->sound, data->sound->cache))
return;
/* examine this snippet of the wave, and extract the amplitude from it */
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, (sample_t*)&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.
@ -984,7 +892,6 @@ static void fmods_init_typeinfo ()
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

@ -1695,12 +1695,6 @@ static void lib_link_fmodifiers(FileData *fd, ID *id, ListBase *list)
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;
}
}
}
@ -10663,13 +10657,6 @@ static void expand_fmodifiers(FileData *fd, Main *mainvar, ListBase *list)
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;
}
}
}

@ -321,45 +321,6 @@ static void draw_modifier__noise(uiLayout *layout, ID *id, FModifier *fcm, short
/* --------------- */
/* draw settings for sound modifier */
static void draw_modifier__sound(const bContext *C, uiLayout *layout, ID *id, FModifier *fcm, short width)
{
FMod_Sound *data= (FMod_Sound *)fcm->data;
PointerRNA ptr;
/* init the RNA-pointer */
RNA_pointer_create(id, &RNA_FModifierSound, fcm, &ptr);
/* sound */
uiTemplateID(layout, (bContext*)C, &ptr, "sound", NULL, "sound.open", NULL);
if (data->sound)
{
/* only sounds that are cached can be used, so display error if not cached */
if (data->sound->cache)
{
/* blending mode */
uiItemR(layout, NULL, 0, &ptr, "modification", 0);
/* settings */
uiItemR(layout, NULL, 0, &ptr, "strength", 0);
uiItemR(layout, NULL, 0, &ptr, "delay", 0);
}
else
{
PointerRNA id_ptr;
RNA_id_pointer_create((ID *)data->sound, &id_ptr);
/* error message with a button underneath allowing users to rectify the issue */
uiItemL(layout, "Sound must be cached.", ICON_ERROR);
uiItemR(layout, NULL, 0, &id_ptr, "caching", UI_ITEM_R_TOGGLE);
}
}
}
/* --------------- */
#define BINARYSEARCH_FRAMEEQ_THRESH 0.0001
/* Binary search algorithm for finding where to insert Envelope Data Point.
@ -623,7 +584,7 @@ static void draw_modifier__limits(uiLayout *layout, ID *id, FModifier *fcm, shor
/* --------------- */
void ANIM_uiTemplate_fmodifier_draw (const bContext *C, uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
{
FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
uiLayout *box, *row, *subrow;
@ -704,15 +665,11 @@ void ANIM_uiTemplate_fmodifier_draw (const bContext *C, uiLayout *layout, ID *id
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;
}

@ -428,7 +428,7 @@ void ANIM_draw_previewrange(const struct bContext *C, struct View2D *v2d);
/* F-MODIFIER TOOLS */
/* draw a given F-Modifier for some layout/UI-Block */
void ANIM_uiTemplate_fmodifier_draw(const struct bContext *C, struct uiLayout *layout, struct ID *id, ListBase *modifiers, struct FModifier *fcm);
void ANIM_uiTemplate_fmodifier_draw(struct uiLayout *layout, struct ID *id, ListBase *modifiers, struct FModifier *fcm);
/* ************************************************* */
/* ASSORTED TOOLS */

@ -452,7 +452,7 @@ static void graph_panel_modifiers(const bContext *C, Panel *pa)
for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
col= uiLayoutColumn(pa->layout, 1);
ANIM_uiTemplate_fmodifier_draw(C, col, ale->id, &fcu->modifiers, fcm);
ANIM_uiTemplate_fmodifier_draw(col, ale->id, &fcu->modifiers, fcm);
}
MEM_freeN(ale);

@ -434,7 +434,7 @@ static void nla_panel_modifiers(const bContext *C, Panel *pa)
for (fcm= strip->modifiers.first; fcm; fcm= fcm->next) {
col= uiLayoutColumn(pa->layout, 1);
ANIM_uiTemplate_fmodifier_draw(C, col, strip_ptr.id.data, &strip->modifiers, fcm);
ANIM_uiTemplate_fmodifier_draw(col, strip_ptr.id.data, &strip->modifiers, fcm);
}
}

@ -36,7 +36,6 @@ extern "C" {
#include "DNA_listBase.h"
#include "DNA_action_types.h"
#include "DNA_curve_types.h"
#include "DNA_sound_types.h"
/* ************************************************ */
/* F-Curve DataTypes */
@ -74,7 +73,6 @@ typedef enum eFModifier_Types {
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
@ -232,25 +230,6 @@ typedef enum eFMod_Noise_Modifications {
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

@ -211,7 +211,6 @@ extern StructRNA RNA_FModifierGenerator;
extern StructRNA RNA_FModifierLimits;
extern StructRNA RNA_FModifierNoise;
extern StructRNA RNA_FModifierPython;
extern StructRNA RNA_FModifierSound;
extern StructRNA RNA_FollowPathConstraint;
extern StructRNA RNA_Function;
extern StructRNA RNA_GameBooleanProperty;

@ -34,7 +34,6 @@
#include "DNA_anim_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_sound_types.h"
#include "MEM_guardedalloc.h"
@ -50,7 +49,6 @@ EnumPropertyItem fmodifier_type_items[] = {
{FMODIFIER_TYPE_FILTER, "FILTER", 0, "Filter", ""},
{FMODIFIER_TYPE_PYTHON, "PYTHON", 0, "Python", ""},
{FMODIFIER_TYPE_LIMITS, "LIMITS", 0, "Limits", ""},
{FMODIFIER_TYPE_SOUND, "SOUND", 0, "Sound", ""},
{0, NULL, 0, NULL, NULL}};
#ifdef RNA_RUNTIME
@ -78,8 +76,6 @@ static StructRNA *rna_FModifierType_refine(struct PointerRNA *ptr)
return &RNA_FModifierPython;
case FMODIFIER_TYPE_LIMITS:
return &RNA_FModifierLimits;
case FMODIFIER_TYPE_SOUND:
return &RNA_FModifierSound;
default:
return &RNA_UnknownType;
}
@ -620,46 +616,6 @@ static void rna_def_fmodifier_noise(BlenderRNA *brna)
}
/* --------- */
static void rna_def_fmodifier_sound(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem prop_modification_items[] = {
{FCM_SOUND_MODIF_REPLACE, "REPLACE", 0, "Replace", ""},
{FCM_SOUND_MODIF_ADD, "ADD", 0, "Add", ""},
{FCM_SOUND_MODIF_SUBTRACT, "SUBTRACT", 0, "Subtract", ""},
{FCM_SOUND_MODIF_MULTIPLY, "MULTIPLY", 0, "Multiply", ""},
{0, NULL, 0, NULL, NULL}};
srna= RNA_def_struct(brna, "FModifierSound", "FModifier");
RNA_def_struct_ui_text(srna, "Sound F-Modifier", "Modifies an F-Curve based on the amplitudes in a sound.");
RNA_def_struct_sdna_from(srna, "FMod_Sound", "data");
prop= RNA_def_property(srna, "modification", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_modification_items);
RNA_def_property_ui_text(prop, "Modification", "Method of modifying the existing F-Curve.");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "strength");
RNA_def_property_ui_text(prop, "Strength", "Amplitude of the sound - the amount that it modifies the underlying curve");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
prop= RNA_def_property(srna, "delay", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "delay");
RNA_def_property_ui_text(prop, "delay", "The delay before the sound curve modification should start");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
prop= RNA_def_property(srna, "sound", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Sound");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Sound", "Sound datablock used by this modifier.");
}
/* --------- */
static void rna_def_fmodifier(BlenderRNA *brna)
@ -989,7 +945,6 @@ void RNA_def_fcurve(BlenderRNA *brna)
rna_def_fmodifier_python(brna);
rna_def_fmodifier_limits(brna);
rna_def_fmodifier_noise(brna);
rna_def_fmodifier_sound(brna);
}