I'm making an audio visualizer. It uses shape keys to move individual bars and I'm using bake sound to fcurves function to animate each bar. This is how a channel of a shape key looks like after I bake the sound into it:
Now the thing is, shape keys accept only values in (0,1) interval. Baking can produce values anywhere above 0. So if the baked sound exceeds value of 1 on the Y axis, I need to multiply the entire channels Y axis by a value like 0.8 or 0.5 so it fits the shape key. Similarly, if the baked sound is too low, like the provided screenshot, I might want to multiply the channels Y axis by 2 to increase it's strength.
I could eyeball those values and do it myself ... or maybe you guys could help me write a script that normalizes each channel so it fits an interval (0,1) perfectly.
for j in range(0,len(ranges)-1): #goes through each shape key (channel) 1 by 1
bpy.ops.anim.channels_select_all(action='DESELECT') #deselects channels
bpy.ops.anim.channels_find(query='(Key '+str(j+1)+')') #queries for a single channel
bpy.ops.anim.channels_select_all(action='SELECT') #selects the channel
bpy.ops.graph.sound_bake(filepath=file,low = ranges[j], high = ranges[j+1]) #bakes sound into the channel
bpy.ops.graph.unbake() #unbakes the channel so its editable
bpy.ops.graph.select_all(action='SELECT') #selects unbaked values
bpy.context.space_data.pivot_point = 'CURSOR' #sets transform pivot to 0,0
bpy.ops.transform.resize(value=(1, 2, 1)) #multiplies given channel on the Y axis by a value of 2
So the last line of code is the issue. I need my script to determine the Y axis multiplier on it's own. I'm thinking if I can access an array that holds all values of a channel, I could find the highest value and do some math to figure out how to multiply it.