2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-08-28 11:13:45 +00:00
|
|
|
* 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
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2009-08-28 11:13:45 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-08-28 11:13:45 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2007 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup edsnd
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-01-26 14:18:16 +00:00
|
|
|
#include <stddef.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2009-08-28 11:13:45 +00:00
|
|
|
|
2010-05-29 21:31:57 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2009-08-28 11:13:45 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2009-08-28 21:47:05 +00:00
|
|
|
#include "DNA_sequence_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_sound_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_space_types.h"
|
2010-05-29 21:31:57 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2009-08-28 11:13:45 +00:00
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
|
|
|
#include "BKE_fcurve.h"
|
2009-08-28 21:47:05 +00:00
|
|
|
#include "BKE_global.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_main.h"
|
2009-08-28 21:47:05 +00:00
|
|
|
#include "BKE_packedFile.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_report.h"
|
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
|
|
|
#include "BKE_scene.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_sound.h"
|
2009-08-28 11:13:45 +00:00
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
2009-08-28 21:47:05 +00:00
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
|
2020-12-19 06:44:57 +01:00
|
|
|
#include "SEQ_iterator.h"
|
2020-11-01 21:03:31 +01:00
|
|
|
|
2009-08-28 21:47:05 +00:00
|
|
|
#include "UI_interface.h"
|
2009-08-28 11:13:45 +00:00
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2011-06-23 09:27:56 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2017-08-18 08:24:12 +02:00
|
|
|
# include <AUD_Special.h>
|
2011-06-23 09:27:56 +00:00
|
|
|
#endif
|
2009-08-28 11:13:45 +00:00
|
|
|
|
2019-06-04 16:52:48 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
#include "ED_sound.h"
|
2011-01-26 14:18:16 +00:00
|
|
|
#include "ED_util.h"
|
|
|
|
|
|
2009-08-28 11:13:45 +00:00
|
|
|
/******************** open sound operator ********************/
|
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void sound_open_cancel(bContext *UNUSED(C), wmOperator *op)
|
2011-08-11 11:41:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
op->customdata = NULL;
|
2011-08-11 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-28 03:02:09 +00:00
|
|
|
static void sound_open_init(bContext *C, wmOperator *op)
|
2010-05-29 21:31:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyPointerRNA *pprop;
|
2011-08-06 17:57:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
|
|
|
|
|
UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
|
2010-05-29 21:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-23 09:27:56 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2011-10-28 03:02:09 +00:00
|
|
|
static int sound_open_exec(bContext *C, wmOperator *op)
|
2009-08-28 11:13:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char path[FILE_MAX];
|
|
|
|
|
bSound *sound;
|
|
|
|
|
PropertyPointerRNA *pprop;
|
|
|
|
|
PointerRNA idptr;
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "filepath", path);
|
|
|
|
|
sound = BKE_sound_new_file(bmain, path);
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!op->customdata) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sound_open_init(C, op);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "mono")) {
|
|
|
|
|
sound->flags |= SOUND_FLAGS_MONO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "cache")) {
|
2019-07-08 15:57:33 +02:00
|
|
|
sound->flags |= SOUND_FLAGS_CACHING;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* hook into UI */
|
|
|
|
|
pprop = op->customdata;
|
|
|
|
|
|
|
|
|
|
if (pprop->prop) {
|
|
|
|
|
/* when creating new ID blocks, use is already 1, but RNA
|
|
|
|
|
* pointer use also increases user, so this compensates it */
|
|
|
|
|
id_us_min(&sound->id);
|
|
|
|
|
|
|
|
|
|
RNA_id_pointer_create(&sound->id, &idptr);
|
2019-05-20 18:06:09 +10:00
|
|
|
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_property_update(C, &pprop->ptr, pprop->prop);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 16:52:48 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-08-28 11:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-10 18:19:55 +11:00
|
|
|
#else /* WITH_AUDASPACE */
|
2011-06-23 09:27:56 +00:00
|
|
|
|
2011-10-28 03:02:09 +00:00
|
|
|
static int sound_open_exec(bContext *UNUSED(C), wmOperator *op)
|
2011-06-23 09:27:56 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Compiled without sound support");
|
2011-06-23 09:27:56 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2011-06-23 09:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sound_open_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-08-28 11:13:45 +00:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return sound_open_exec(C, op);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-08-06 17:57:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sound_open_init(C, op);
|
2011-08-06 17:57:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return WM_operator_filesel(C, op, event);
|
2009-08-28 11:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 08:20:21 +00:00
|
|
|
static void SOUND_OT_open(wmOperatorType *ot)
|
2009-08-28 11:13:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Open Sound";
|
|
|
|
|
ot->description = "Load a sound file";
|
|
|
|
|
ot->idname = "SOUND_OT_open";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_open_exec;
|
|
|
|
|
ot->invoke = sound_open_invoke;
|
|
|
|
|
ot->cancel = sound_open_cancel;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_SOUND | FILE_TYPE_MOVIE,
|
|
|
|
|
FILE_SPECIAL,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
|
|
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_def_boolean(ot->srna, "cache", false, "Cache", "Cache the sound in memory");
|
|
|
|
|
RNA_def_boolean(ot->srna, "mono", false, "Mono", "Merge all the sound's channels into one");
|
2011-08-11 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 08:20:21 +00:00
|
|
|
static void SOUND_OT_open_mono(wmOperatorType *ot)
|
2011-08-11 11:41:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Open Sound Mono";
|
|
|
|
|
ot->description = "Load a sound file as mono";
|
|
|
|
|
ot->idname = "SOUND_OT_open_mono";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_open_exec;
|
|
|
|
|
ot->invoke = sound_open_invoke;
|
|
|
|
|
ot->cancel = sound_open_cancel;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_SOUND | FILE_TYPE_MOVIE,
|
|
|
|
|
FILE_SPECIAL,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
|
|
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_def_boolean(ot->srna, "cache", false, "Cache", "Cache the sound in memory");
|
|
|
|
|
RNA_def_boolean(ot->srna, "mono", true, "Mono", "Mixdown the sound to mono");
|
2009-08-28 11:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-17 00:22:15 +00:00
|
|
|
/* ******************************************************* */
|
|
|
|
|
|
2016-09-06 14:07:07 +02:00
|
|
|
static void sound_update_animation_flags(Scene *scene);
|
|
|
|
|
|
2020-04-05 23:39:20 +02:00
|
|
|
static int sound_update_animation_flags_fn(Sequence *seq, void *user_data)
|
2016-09-06 14:07:07 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct FCurve *fcu;
|
|
|
|
|
Scene *scene = (Scene *)user_data;
|
|
|
|
|
bool driven;
|
|
|
|
|
|
|
|
|
|
fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "volume", 0, &driven);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu || driven) {
|
2019-04-17 06:17:24 +02:00
|
|
|
seq->flag |= SEQ_AUDIO_VOLUME_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
seq->flag &= ~SEQ_AUDIO_VOLUME_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "pitch", 0, &driven);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu || driven) {
|
2019-04-17 06:17:24 +02:00
|
|
|
seq->flag |= SEQ_AUDIO_PITCH_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
seq->flag &= ~SEQ_AUDIO_PITCH_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "pan", 0, &driven);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu || driven) {
|
2019-04-17 06:17:24 +02:00
|
|
|
seq->flag |= SEQ_AUDIO_PAN_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
seq->flag &= ~SEQ_AUDIO_PAN_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (seq->type == SEQ_TYPE_SCENE) {
|
|
|
|
|
/* TODO(sergey): For now we do manual recursion into the scene strips,
|
|
|
|
|
* but perhaps it should be covered by recursive_apply?
|
|
|
|
|
*/
|
|
|
|
|
sound_update_animation_flags(seq->scene);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2016-09-06 14:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sound_update_animation_flags(Scene *scene)
|
2011-12-17 00:22:15 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct FCurve *fcu;
|
|
|
|
|
bool driven;
|
|
|
|
|
Sequence *seq;
|
|
|
|
|
|
|
|
|
|
if (scene->id.tag & LIB_TAG_DOIT) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
scene->id.tag |= LIB_TAG_DOIT;
|
|
|
|
|
|
2020-08-21 18:55:27 +02:00
|
|
|
SEQ_ALL_BEGIN (scene->ed, seq) {
|
2020-12-19 05:57:27 +01:00
|
|
|
SEQ_iterator_recursive_apply(seq, sound_update_animation_flags_fn, scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-08-21 18:55:27 +02:00
|
|
|
SEQ_ALL_END;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
fcu = id_data_find_fcurve(&scene->id, scene, &RNA_Scene, "audio_volume", 0, &driven);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu || driven) {
|
2019-04-17 06:17:24 +02:00
|
|
|
scene->audio.flag |= AUDIO_VOLUME_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
scene->audio.flag &= ~AUDIO_VOLUME_ANIMATED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-09-06 14:07:07 +02:00
|
|
|
}
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2016-09-06 14:07:07 +02:00
|
|
|
static int sound_update_animation_flags_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
|
{
|
2019-10-08 12:58:45 -07:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_main_id_tag_idcode(CTX_data_main(C), ID_SCE, LIB_TAG_DOIT, false);
|
|
|
|
|
sound_update_animation_flags(CTX_data_scene(C));
|
2019-10-08 12:58:45 -07:00
|
|
|
DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2011-12-17 00:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SOUND_OT_update_animation_flags(wmOperatorType *ot)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/*
|
|
|
|
|
* This operator is needed to set a correct state of the sound animation
|
|
|
|
|
* System. Unfortunately there's no really correct place to call the exec
|
|
|
|
|
* function, that's why I made it an operator that's only visible in the
|
|
|
|
|
* search menu. Apart from that the bake animation operator calls it too.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Update Animation";
|
|
|
|
|
ot->description = "Update animation flags";
|
|
|
|
|
ot->idname = "SOUND_OT_update_animation_flags";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_update_animation_flags_exec;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER;
|
2011-12-17 00:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******************************************************* */
|
|
|
|
|
|
|
|
|
|
static int sound_bake_animation_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2019-08-02 12:00:07 +10:00
|
|
|
/* NOTE: We will be forcefully evaluating dependency graph at every frame, so no need to ensure
|
2019-07-25 16:36:22 +02:00
|
|
|
* current scene state is evaluated as it will be lost anyway. */
|
|
|
|
|
struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
int oldfra = scene->r.cfra;
|
|
|
|
|
int cfra;
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sound_update_animation_flags_exec(C, NULL);
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (cfra = (scene->r.sfra > 0) ? (scene->r.sfra - 1) : 0; cfra <= scene->r.efra + 1; cfra++) {
|
|
|
|
|
scene->r.cfra = cfra;
|
2020-08-18 15:45:58 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scene->r.cfra = oldfra;
|
2020-08-18 15:45:58 +02:00
|
|
|
BKE_scene_graph_update_for_newframe(depsgraph);
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2011-12-17 00:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SOUND_OT_bake_animation(wmOperatorType *ot)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Update Animation Cache";
|
|
|
|
|
ot->description = "Update the audio animation cache";
|
|
|
|
|
ot->idname = "SOUND_OT_bake_animation";
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_bake_animation_exec;
|
2011-12-17 00:22:15 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER;
|
2011-12-17 00:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-06 17:57:20 +00:00
|
|
|
/******************** mixdown operator ********************/
|
|
|
|
|
|
2011-10-28 03:02:09 +00:00
|
|
|
static int sound_mixdown_exec(bContext *C, wmOperator *op)
|
2011-08-06 17:57:20 +00:00
|
|
|
{
|
2011-09-01 09:46:07 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2019-04-17 06:17:24 +02:00
|
|
|
char path[FILE_MAX];
|
|
|
|
|
char filename[FILE_MAX];
|
2019-07-25 16:36:22 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2019-06-04 16:52:48 +02:00
|
|
|
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
int split;
|
|
|
|
|
|
|
|
|
|
int bitrate, accuracy;
|
|
|
|
|
AUD_DeviceSpecs specs;
|
|
|
|
|
AUD_Container container;
|
|
|
|
|
AUD_Codec codec;
|
|
|
|
|
const char *result;
|
|
|
|
|
|
|
|
|
|
sound_bake_animation_exec(C, op);
|
|
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "filepath", path);
|
|
|
|
|
bitrate = RNA_int_get(op->ptr, "bitrate") * 1000;
|
|
|
|
|
accuracy = RNA_int_get(op->ptr, "accuracy");
|
|
|
|
|
specs.format = RNA_enum_get(op->ptr, "format");
|
|
|
|
|
container = RNA_enum_get(op->ptr, "container");
|
|
|
|
|
codec = RNA_enum_get(op->ptr, "codec");
|
|
|
|
|
split = RNA_boolean_get(op->ptr, "split_channels");
|
2019-06-04 16:52:48 +02:00
|
|
|
specs.channels = scene_eval->r.ffcodecdata.audio_channels;
|
|
|
|
|
specs.rate = scene_eval->r.ffcodecdata.audio_mixrate;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
BLI_strncpy(filename, path, sizeof(filename));
|
|
|
|
|
BLI_path_abs(filename, BKE_main_blendfile_path(bmain));
|
|
|
|
|
|
2019-06-04 16:52:48 +02:00
|
|
|
const double fps = (((double)scene_eval->r.frs_sec) / (double)scene_eval->r.frs_sec_base);
|
|
|
|
|
const int start_frame = scene_eval->r.sfra;
|
|
|
|
|
const int end_frame = scene_eval->r.efra;
|
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (split) {
|
2019-06-04 16:52:48 +02:00
|
|
|
result = AUD_mixdown_per_channel(scene_eval->sound_scene,
|
|
|
|
|
start_frame * specs.rate / fps,
|
|
|
|
|
(end_frame - start_frame + 1) * specs.rate / fps,
|
2019-04-17 06:17:24 +02:00
|
|
|
accuracy,
|
|
|
|
|
filename,
|
|
|
|
|
specs,
|
|
|
|
|
container,
|
|
|
|
|
codec,
|
2020-09-07 18:11:56 +02:00
|
|
|
bitrate,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-06-04 16:52:48 +02:00
|
|
|
result = AUD_mixdown(scene_eval->sound_scene,
|
|
|
|
|
start_frame * specs.rate / fps,
|
|
|
|
|
(end_frame - start_frame + 1) * specs.rate / fps,
|
2019-04-17 06:17:24 +02:00
|
|
|
accuracy,
|
|
|
|
|
filename,
|
|
|
|
|
specs,
|
|
|
|
|
container,
|
|
|
|
|
codec,
|
2020-09-07 18:11:56 +02:00
|
|
|
bitrate,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-04 16:52:48 +02:00
|
|
|
BKE_sound_reset_scene_specs(scene_eval);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, result);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2020-10-10 18:19:55 +11:00
|
|
|
#else /* WITH_AUDASPACE */
|
2019-04-17 06:17:24 +02:00
|
|
|
(void)C;
|
|
|
|
|
(void)op;
|
2020-10-10 18:19:55 +11:00
|
|
|
#endif /* WITH_AUDASPACE */
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2011-08-06 17:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-24 10:15:38 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem container_items[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
# ifdef WITH_FFMPEG
|
|
|
|
|
{AUD_CONTAINER_AC3, "AC3", 0, "ac3", "Dolby Digital ATRAC 3"},
|
|
|
|
|
# endif
|
|
|
|
|
{AUD_CONTAINER_FLAC, "FLAC", 0, "flac", "Free Lossless Audio Codec"},
|
|
|
|
|
# ifdef WITH_FFMPEG
|
|
|
|
|
{AUD_CONTAINER_MATROSKA, "MATROSKA", 0, "mkv", "Matroska"},
|
|
|
|
|
{AUD_CONTAINER_MP2, "MP2", 0, "mp2", "MPEG-1 Audio Layer II"},
|
|
|
|
|
{AUD_CONTAINER_MP3, "MP3", 0, "mp3", "MPEG-2 Audio Layer III"},
|
|
|
|
|
# endif
|
|
|
|
|
{AUD_CONTAINER_OGG, "OGG", 0, "ogg", "Xiph.Org Ogg Container"},
|
|
|
|
|
{AUD_CONTAINER_WAV, "WAV", 0, "wav", "Waveform Audio File Format"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
2012-05-24 10:15:38 +00:00
|
|
|
};
|
2012-05-23 19:55:00 +00:00
|
|
|
|
|
|
|
|
static const char *snd_ext_sound[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
".ac3",
|
|
|
|
|
".flac",
|
|
|
|
|
".mkv",
|
|
|
|
|
".mp2",
|
|
|
|
|
".mp3",
|
|
|
|
|
".ogg",
|
|
|
|
|
".wav",
|
|
|
|
|
NULL,
|
2012-05-23 19:55:00 +00:00
|
|
|
};
|
|
|
|
|
|
2013-06-19 08:40:18 +00:00
|
|
|
static bool sound_mixdown_check(bContext *UNUSED(C), wmOperator *op)
|
2012-05-23 19:55:00 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
AUD_Container container = RNA_enum_get(op->ptr, "container");
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *extension = NULL;
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
const EnumPropertyItem *item = container_items;
|
|
|
|
|
while (item->identifier != NULL) {
|
|
|
|
|
if (item->value == container) {
|
|
|
|
|
const char **ext = snd_ext_sound;
|
|
|
|
|
while (*ext != NULL) {
|
|
|
|
|
if (STREQ(*ext + 1, item->name)) {
|
|
|
|
|
extension = *ext;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ext++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
item++;
|
|
|
|
|
}
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (extension) {
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
char filepath[FILE_MAX];
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int check;
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
prop = RNA_struct_find_property(op->ptr, "filepath");
|
|
|
|
|
RNA_property_string_get(op->ptr, prop, filepath);
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (BLI_path_extension_check_array(filepath, snd_ext_sound)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
check = BLI_path_extension_replace(filepath, FILE_MAX, extension);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
check = BLI_path_extension_ensure(filepath, FILE_MAX, extension);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!check) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return check;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_property_string_set(op->ptr, prop, filepath);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-05-23 19:55:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2012-05-23 19:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-10 18:19:55 +11:00
|
|
|
#endif /* WITH_AUDASPACE */
|
2012-05-24 10:15:38 +00:00
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sound_mixdown_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2011-08-06 17:57:20 +00:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return sound_mixdown_exec(C, op);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-08-06 17:57:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return WM_operator_filesel(C, op, event);
|
2011-08-06 17:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:18:04 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool sound_mixdown_draw_check_prop(PointerRNA *UNUSED(ptr),
|
|
|
|
|
PropertyRNA *prop,
|
|
|
|
|
void *UNUSED(user_data))
|
2011-08-06 17:57:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *prop_id = RNA_property_identifier(prop);
|
2020-11-06 15:29:25 +11:00
|
|
|
return !(STR_ELEM(prop_id, "filepath", "directory", "filename"));
|
2011-08-06 17:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-28 03:02:09 +00:00
|
|
|
static void sound_mixdown_draw(bContext *C, wmOperator *op)
|
2011-08-06 17:57:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
static const EnumPropertyItem pcm_format_items[] = {
|
2020-12-07 14:51:06 -08:00
|
|
|
{AUD_FORMAT_U8, "U8", 0, "U8", "8-bit unsigned"},
|
|
|
|
|
{AUD_FORMAT_S16, "S16", 0, "S16", "16-bit signed"},
|
2019-04-17 06:17:24 +02:00
|
|
|
# ifdef WITH_SNDFILE
|
2020-12-07 14:51:06 -08:00
|
|
|
{AUD_FORMAT_S24, "S24", 0, "S24", "24-bit signed"},
|
2019-04-17 06:17:24 +02:00
|
|
|
# endif
|
2020-12-07 14:51:06 -08:00
|
|
|
{AUD_FORMAT_S32, "S32", 0, "S32", "32-bit signed"},
|
|
|
|
|
{AUD_FORMAT_FLOAT32, "F32", 0, "F32", "32-bit floating-point"},
|
|
|
|
|
{AUD_FORMAT_FLOAT64, "F64", 0, "F64", "64-bit floating-point"},
|
2019-04-17 06:17:24 +02:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const EnumPropertyItem mp3_format_items[] = {
|
2020-12-07 14:51:06 -08:00
|
|
|
{AUD_FORMAT_S16, "S16", 0, "S16", "16-bit signed"},
|
|
|
|
|
{AUD_FORMAT_S32, "S32", 0, "S32", "32-bit signed"},
|
2019-04-17 06:17:24 +02:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# ifdef WITH_SNDFILE
|
|
|
|
|
static const EnumPropertyItem flac_format_items[] = {
|
2020-12-07 14:51:06 -08:00
|
|
|
{AUD_FORMAT_S16, "S16", 0, "S16", "16-bit signed"},
|
|
|
|
|
{AUD_FORMAT_S24, "S24", 0, "S24", "24-bit signed"},
|
2019-04-17 06:17:24 +02:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
static const EnumPropertyItem all_codec_items[] = {
|
|
|
|
|
{AUD_CODEC_AAC, "AAC", 0, "AAC", "Advanced Audio Coding"},
|
|
|
|
|
{AUD_CODEC_AC3, "AC3", 0, "AC3", "Dolby Digital ATRAC 3"},
|
|
|
|
|
{AUD_CODEC_FLAC, "FLAC", 0, "FLAC", "Free Lossless Audio Codec"},
|
|
|
|
|
{AUD_CODEC_MP2, "MP2", 0, "MP2", "MPEG-1 Audio Layer II"},
|
|
|
|
|
{AUD_CODEC_MP3, "MP3", 0, "MP3", "MPEG-2 Audio Layer III"},
|
|
|
|
|
{AUD_CODEC_PCM, "PCM", 0, "PCM", "Pulse Code Modulation (RAW)"},
|
|
|
|
|
{AUD_CODEC_VORBIS, "VORBIS", 0, "Vorbis", "Xiph.Org Vorbis Codec"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const EnumPropertyItem ogg_codec_items[] = {
|
|
|
|
|
{AUD_CODEC_FLAC, "FLAC", 0, "FLAC", "Free Lossless Audio Codec"},
|
|
|
|
|
{AUD_CODEC_VORBIS, "VORBIS", 0, "Vorbis", "Xiph.Org Vorbis Codec"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uiLayout *layout = op->layout;
|
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop_format;
|
|
|
|
|
PropertyRNA *prop_codec;
|
|
|
|
|
PropertyRNA *prop_bitrate;
|
|
|
|
|
|
2020-07-21 11:13:18 -04:00
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
uiLayoutSetPropDecorate(layout, false);
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
AUD_Container container = RNA_enum_get(op->ptr, "container");
|
|
|
|
|
AUD_Codec codec = RNA_enum_get(op->ptr, "codec");
|
|
|
|
|
|
|
|
|
|
prop_format = RNA_struct_find_property(op->ptr, "format");
|
|
|
|
|
prop_codec = RNA_struct_find_property(op->ptr, "codec");
|
|
|
|
|
prop_bitrate = RNA_struct_find_property(op->ptr, "bitrate");
|
|
|
|
|
|
|
|
|
|
RNA_def_property_clear_flag(prop_bitrate, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_flag(prop_codec, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_flag(prop_format, PROP_HIDDEN);
|
|
|
|
|
|
|
|
|
|
switch (container) {
|
|
|
|
|
case AUD_CONTAINER_AC3:
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, all_codec_items);
|
|
|
|
|
RNA_enum_set(op->ptr, "codec", AUD_CODEC_AC3);
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_FLOAT32);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CONTAINER_FLAC:
|
|
|
|
|
RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, all_codec_items);
|
|
|
|
|
RNA_enum_set(op->ptr, "codec", AUD_CODEC_FLAC);
|
|
|
|
|
# ifdef WITH_SNDFILE
|
|
|
|
|
RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_format, flac_format_items);
|
|
|
|
|
# else
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
# endif
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CONTAINER_MATROSKA:
|
|
|
|
|
RNA_def_property_clear_flag(prop_codec, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, all_codec_items);
|
|
|
|
|
|
|
|
|
|
switch (codec) {
|
|
|
|
|
case AUD_CODEC_AAC:
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CODEC_AC3:
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_FLOAT32);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CODEC_FLAC:
|
|
|
|
|
RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CODEC_MP2:
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CODEC_MP3:
|
|
|
|
|
RNA_def_property_enum_items(prop_format, mp3_format_items);
|
|
|
|
|
RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CODEC_PCM:
|
|
|
|
|
RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_format, pcm_format_items);
|
|
|
|
|
RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CODEC_VORBIS:
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CONTAINER_MP2:
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
RNA_enum_set(op->ptr, "codec", AUD_CODEC_MP2);
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, all_codec_items);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CONTAINER_MP3:
|
|
|
|
|
RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_format, mp3_format_items);
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, all_codec_items);
|
|
|
|
|
RNA_enum_set(op->ptr, "codec", AUD_CODEC_MP3);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CONTAINER_OGG:
|
|
|
|
|
RNA_def_property_clear_flag(prop_codec, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, ogg_codec_items);
|
|
|
|
|
RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
|
|
|
|
|
break;
|
|
|
|
|
case AUD_CONTAINER_WAV:
|
|
|
|
|
RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
|
|
|
|
|
RNA_def_property_enum_items(prop_format, pcm_format_items);
|
|
|
|
|
RNA_def_property_enum_items(prop_codec, all_codec_items);
|
|
|
|
|
RNA_enum_set(op->ptr, "codec", AUD_CODEC_PCM);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
|
|
|
|
|
|
|
|
|
|
/* main draw call */
|
|
|
|
|
uiDefAutoButsRNA(
|
|
|
|
|
layout, &ptr, sound_mixdown_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false);
|
2011-08-06 17:57:20 +00:00
|
|
|
}
|
2020-10-10 18:19:55 +11:00
|
|
|
#endif /* WITH_AUDASPACE */
|
2011-08-06 17:57:20 +00:00
|
|
|
|
2011-09-20 04:38:59 +00:00
|
|
|
static void SOUND_OT_mixdown(wmOperatorType *ot)
|
2011-08-06 17:57:20 +00:00
|
|
|
{
|
2011-09-01 09:46:07 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2019-04-17 06:17:24 +02:00
|
|
|
static const EnumPropertyItem format_items[] = {
|
2020-12-07 14:51:06 -08:00
|
|
|
{AUD_FORMAT_U8, "U8", 0, "U8", "8-bit unsigned"},
|
|
|
|
|
{AUD_FORMAT_S16, "S16", 0, "S16", "16-bit signed"},
|
|
|
|
|
{AUD_FORMAT_S24, "S24", 0, "S24", "24-bit signed"},
|
|
|
|
|
{AUD_FORMAT_S32, "S32", 0, "S32", "32-bit signed"},
|
|
|
|
|
{AUD_FORMAT_FLOAT32, "F32", 0, "F32", "32-bit floating-point"},
|
|
|
|
|
{AUD_FORMAT_FLOAT64, "F64", 0, "F64", "64-bit floating-point"},
|
2019-04-17 06:17:24 +02:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const EnumPropertyItem codec_items[] = {
|
|
|
|
|
# ifdef WITH_FFMPEG
|
|
|
|
|
{AUD_CODEC_AAC, "AAC", 0, "AAC", "Advanced Audio Coding"},
|
|
|
|
|
{AUD_CODEC_AC3, "AC3", 0, "AC3", "Dolby Digital ATRAC 3"},
|
|
|
|
|
# endif
|
|
|
|
|
{AUD_CODEC_FLAC, "FLAC", 0, "FLAC", "Free Lossless Audio Codec"},
|
|
|
|
|
# ifdef WITH_FFMPEG
|
|
|
|
|
{AUD_CODEC_MP2, "MP2", 0, "MP2", "MPEG-1 Audio Layer II"},
|
|
|
|
|
{AUD_CODEC_MP3, "MP3", 0, "MP3", "MPEG-2 Audio Layer III"},
|
|
|
|
|
# endif
|
|
|
|
|
{AUD_CODEC_PCM, "PCM", 0, "PCM", "Pulse Code Modulation (RAW)"},
|
|
|
|
|
{AUD_CODEC_VORBIS, "VORBIS", 0, "Vorbis", "Xiph.Org Vorbis Codec"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-10 18:19:55 +11:00
|
|
|
#endif /* WITH_AUDASPACE */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Mixdown";
|
|
|
|
|
ot->description = "Mix the scene's audio to a sound file";
|
|
|
|
|
ot->idname = "SOUND_OT_mixdown";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_mixdown_exec;
|
|
|
|
|
ot->invoke = sound_mixdown_invoke;
|
2011-08-06 17:57:20 +00:00
|
|
|
|
2011-09-01 09:46:07 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2019-04-17 06:17:24 +02:00
|
|
|
ot->check = sound_mixdown_check;
|
|
|
|
|
ot->ui = sound_mixdown_draw;
|
2011-09-01 09:46:07 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_SOUND,
|
|
|
|
|
FILE_SPECIAL,
|
|
|
|
|
FILE_SAVE,
|
UI: File Browser Design Overhaul
This is a general redesign of the File Browser GUI and interaction
methods. For screenshots, check patch D5601.
Main changes in short:
* File Browser as floating window
* New layout of regions
* Popovers for view and filter options
* Vertical list view with interactive column header
* New and updated icons
* Keymap consistency fixes
* Many tweaks and fixes to the drawing of views
----
General:
* The file browser now opens as temporary floating window. It closes on
Esc. The header is hidden then.
* When the file browser is opened as regular editor, the header remains
visible.
* All file browser regions are now defined in Python (the button
layout).
* Adjusted related operator UI names.
Keymap:
Keymap is now consistent with other list-based views in Blender, such as
the Outliner.
* Left click to select, double-click to open
* Right-click context menus
* Shift-click to fill selection
* Ctrl-click to extend selection
Operator options:
These previously overlapped with the source list, which caused numerous
issues with resizing and presenting many settings in a small panel area.
It was also generally inconsistent with Blender.
* Moved to new sidebar, which can easily be shown or hidden using a
prominent Options toggle.
* IO operators have new layouts to match this new sidebar, using
sub-panels. This will have to be committed separately (Add-on
repository).
* If operators want to show the options by default, they have the option
to do so (see `WM_FILESEL_SHOW_PROPS`, `hide_props_region`), otherwise
they are hidden by default.
General Layout:
The layout has been changed to be simpler, more standard, and fits
better in with Blender 2.8.
* More conventional layout (file path at top, file name at the bottom,
execute/cancel buttons in bottom right).
* Use of popovers to group controls, and allow for more descriptive
naming.
* Search box is always live now, just like Outliner.
Views:
* Date Modified column combines both date and time, also uses user
friendly strings for recent dates (i.e. "Yesterday", "Today").
* Details columns (file size, modification date/time) are now toggleable
for all display types, they are not hardcoded per display type.
* File sizes now show as B, KB, MB, ... rather than B, KiB, MiB, … They
are now also calculated using base 10 of course.
* Option to sort in inverse order.
Vertical List View:
* This view now used a much simpler single vertical list with columns
for information.
* Users can click on the headers of these columns to order by that
category, and click again to reverse the ordering.
Icons:
* Updated icons by Jendrzych, with better centering.
* Files and folders have new icons in Icon view.
* Both files and folders have reworked superimposed icons that show
users the file/folder type.
* 3D file documents correctly use the 3d file icon, which was unused
previously.
* Workspaces now show their icon on Link/Append - also when listed in
the Outliner.
Minor Python-API breakage:
* `bpy.types.FileSelectParams.display_type`: `LIST_SHORT` and
`LIST_LONG` are replaced by `LIST_VERTICAL` and `LIST_HORIZONTAL`.
Removes the feature where directories would automatically be created if
they are entered into the file path text button, but don't exist. We
were not sure if users use it enough to keep it. We can definitely bring
it back.
----
//Combined effort by @billreynish, @harley, @jendrzych, my university
colleague Brian Meisenheimer and myself.//
Differential Revision: https://developer.blender.org/D5601
Reviewers: Brecht, Bastien
2019-09-03 15:43:38 +02:00
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
|
2019-04-17 06:17:24 +02:00
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2011-09-01 09:46:07 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_def_int(
|
|
|
|
|
ot->srna,
|
|
|
|
|
"accuracy",
|
|
|
|
|
1024,
|
|
|
|
|
1,
|
|
|
|
|
16777216,
|
|
|
|
|
"Accuracy",
|
|
|
|
|
"Sample accuracy, important for animation data (the lower the value, the more accurate)",
|
|
|
|
|
1,
|
|
|
|
|
16777216);
|
|
|
|
|
RNA_def_enum(
|
|
|
|
|
ot->srna, "container", container_items, AUD_CONTAINER_FLAC, "Container", "File format");
|
|
|
|
|
RNA_def_enum(ot->srna, "codec", codec_items, AUD_CODEC_FLAC, "Codec", "Audio Codec");
|
|
|
|
|
RNA_def_enum(ot->srna, "format", format_items, AUD_FORMAT_S16, "Format", "Sample format");
|
|
|
|
|
RNA_def_int(ot->srna, "bitrate", 192, 32, 512, "Bitrate", "Bitrate in kbit/s", 32, 512);
|
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"split_channels",
|
|
|
|
|
0,
|
|
|
|
|
"Split channels",
|
|
|
|
|
"Each channel will be rendered into a mono file");
|
2020-10-10 18:19:55 +11:00
|
|
|
#endif /* WITH_AUDASPACE */
|
2011-08-06 17:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-28 11:13:45 +00:00
|
|
|
/* ******************************************************* */
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool sound_poll(bContext *C)
|
2009-08-28 21:47:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Editing *ed = CTX_data_scene(C)->ed;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2009-08-28 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
/********************* pack operator *********************/
|
|
|
|
|
|
2011-10-28 03:02:09 +00:00
|
|
|
static int sound_pack_exec(bContext *C, wmOperator *op)
|
2009-08-28 21:47:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Editing *ed = CTX_data_scene(C)->ed;
|
|
|
|
|
bSound *sound;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sound = ed->act_seq->sound;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!sound || sound->packedfile) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-07-07 23:57:35 +10:00
|
|
|
sound->packedfile = BKE_packedfile_new(
|
2020-06-23 09:54:14 +10:00
|
|
|
op->reports, sound->filepath, ID_BLEND_PATH(bmain, &sound->id));
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_sound_load(bmain, sound);
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2009-08-28 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static void SOUND_OT_pack(wmOperatorType *ot)
|
2009-08-28 21:47:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Pack Sound";
|
|
|
|
|
ot->description = "Pack the sound into the current blend file";
|
|
|
|
|
ot->idname = "SOUND_OT_pack";
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_pack_exec;
|
|
|
|
|
ot->poll = sound_poll;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-08-28 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************* unpack operator *********************/
|
|
|
|
|
|
2011-01-26 14:18:16 +00:00
|
|
|
static int sound_unpack_exec(bContext *C, wmOperator *op)
|
2009-08-28 21:47:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
int method = RNA_enum_get(op->ptr, "method");
|
|
|
|
|
bSound *sound = NULL;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2020-03-19 20:33:23 +01:00
|
|
|
/* find the supplied image by name */
|
2019-04-17 06:17:24 +02:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "id")) {
|
|
|
|
|
char sndname[MAX_ID_NAME - 2];
|
|
|
|
|
RNA_string_get(op->ptr, "id", sndname);
|
|
|
|
|
sound = BLI_findstring(&bmain->sounds, sndname, offsetof(ID, name) + 2);
|
|
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!sound || !sound->packedfile) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.fileflags & G_FILE_AUTOPACK) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports,
|
|
|
|
|
RPT_WARNING,
|
|
|
|
|
"AutoPack is enabled, so image will be packed again on file save");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-07-07 23:57:35 +10:00
|
|
|
BKE_packedfile_unpack_sound(bmain, op->reports, sound, method);
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2009-08-28 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sound_unpack_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
2009-08-28 21:47:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Editing *ed = CTX_data_scene(C)->ed;
|
|
|
|
|
bSound *sound;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "id")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return sound_unpack_exec(C, op);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-01-26 14:18:16 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sound = ed->act_seq->sound;
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!sound || !sound->packedfile) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.fileflags & G_FILE_AUTOPACK) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports,
|
|
|
|
|
RPT_WARNING,
|
|
|
|
|
"AutoPack is enabled, so image will be packed again on file save");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2020-06-23 09:54:14 +10:00
|
|
|
unpack_menu(
|
|
|
|
|
C, "SOUND_OT_unpack", sound->id.name + 2, sound->filepath, "sounds", sound->packedfile);
|
2009-08-28 21:47:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2009-08-28 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static void SOUND_OT_unpack(wmOperatorType *ot)
|
2009-08-28 21:47:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Unpack Sound";
|
|
|
|
|
ot->description = "Unpack the sound to the samples filename";
|
|
|
|
|
ot->idname = "SOUND_OT_unpack";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = sound_unpack_exec;
|
|
|
|
|
ot->invoke = sound_unpack_invoke;
|
|
|
|
|
ot->poll = sound_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
RNA_def_enum(
|
|
|
|
|
ot->srna, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack");
|
2021-02-05 16:23:34 +11:00
|
|
|
/* XXX: weak!, will fail with library, name collisions */
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_def_string(
|
|
|
|
|
ot->srna, "id", NULL, MAX_ID_NAME - 2, "Sound Name", "Sound data-block name to unpack");
|
2009-08-28 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******************************************************* */
|
|
|
|
|
|
2009-08-28 12:27:29 +00:00
|
|
|
void ED_operatortypes_sound(void)
|
2009-08-28 11:13:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operatortype_append(SOUND_OT_open);
|
|
|
|
|
WM_operatortype_append(SOUND_OT_open_mono);
|
|
|
|
|
WM_operatortype_append(SOUND_OT_mixdown);
|
|
|
|
|
WM_operatortype_append(SOUND_OT_pack);
|
|
|
|
|
WM_operatortype_append(SOUND_OT_unpack);
|
|
|
|
|
WM_operatortype_append(SOUND_OT_update_animation_flags);
|
|
|
|
|
WM_operatortype_append(SOUND_OT_bake_animation);
|
2009-08-28 11:13:45 +00:00
|
|
|
}
|