2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2007 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/editors/sound/sound_ops.c
37 #include "MEM_guardedalloc.h"
39 #include "BLI_blenlib.h"
40 #include "BLI_utildefines.h"
42 #include "DNA_anim_types.h"
43 #include "DNA_packedFile_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_sequence_types.h"
47 #include "DNA_sound_types.h"
48 #include "DNA_userdef_types.h"
50 #include "BKE_context.h"
51 #include "BKE_fcurve.h"
52 #include "BKE_global.h"
54 #include "BKE_report.h"
55 #include "BKE_packedFile.h"
56 #include "BKE_scene.h"
57 #include "BKE_sound.h"
58 #include "BKE_sequencer.h"
60 #include "RNA_access.h"
61 #include "RNA_define.h"
62 #include "RNA_enum_types.h"
64 #include "UI_interface.h"
70 # include "AUD_C-API.h"
76 #include "sound_intern.h"
78 /******************** open sound operator ********************/
80 static int sound_open_cancel(bContext *UNUSED(C), wmOperator *op)
82 MEM_freeN(op->customdata);
84 return OPERATOR_CANCELLED;
87 static void sound_open_init(bContext *C, wmOperator *op)
89 PropertyPointerRNA *pprop;
91 op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
92 uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
96 static int sound_open_exec(bContext *C, wmOperator *op)
100 PropertyPointerRNA *pprop;
103 Main *bmain = CTX_data_main(C);
105 RNA_string_get(op->ptr, "filepath", path);
106 sound = sound_new_file(bmain, path);
109 sound_open_init(C, op);
111 if (sound==NULL || sound->playback_handle == NULL) {
112 if(op->customdata) MEM_freeN(op->customdata);
113 BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
114 return OPERATOR_CANCELLED;
117 info = AUD_getInfo(sound->playback_handle);
119 if (info.specs.channels == AUD_CHANNELS_INVALID) {
120 sound_delete(bmain, sound);
121 if(op->customdata) MEM_freeN(op->customdata);
122 BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
123 return OPERATOR_CANCELLED;
126 if(RNA_boolean_get(op->ptr, "mono")) {
127 sound->flags |= SOUND_FLAGS_MONO;
128 sound_load(bmain, sound);
131 if (RNA_boolean_get(op->ptr, "cache")) {
136 pprop= op->customdata;
139 /* when creating new ID blocks, use is already 1, but RNA
140 * pointer se also increases user, so this compensates it */
143 RNA_id_pointer_create(&sound->id, &idptr);
144 RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
145 RNA_property_update(C, &pprop->ptr, pprop->prop);
148 if(op->customdata) MEM_freeN(op->customdata);
149 return OPERATOR_FINISHED;
152 #else //WITH_AUDASPACE
154 static int sound_open_exec(bContext *UNUSED(C), wmOperator *op)
156 BKE_report(op->reports, RPT_ERROR, "Compiled without sound support");
158 return OPERATOR_CANCELLED;
163 static int sound_open_invoke(bContext *C, wmOperator *op, wmEvent *event)
165 if(RNA_struct_property_is_set(op->ptr, "filepath"))
166 return sound_open_exec(C, op);
168 sound_open_init(C, op);
170 return WM_operator_filesel(C, op, event);
173 static void SOUND_OT_open(wmOperatorType *ot)
176 ot->name= "Open Sound";
177 ot->description= "Load a sound file";
178 ot->idname= "SOUND_OT_open";
181 ot->exec= sound_open_exec;
182 ot->invoke= sound_open_invoke;
183 ot->cancel= sound_open_cancel;
186 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
189 WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH);
190 RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory");
191 RNA_def_boolean(ot->srna, "mono", FALSE, "Mono", "Mixdown the sound to mono");
194 static void SOUND_OT_open_mono(wmOperatorType *ot)
197 ot->name= "Open Sound Mono";
198 ot->description= "Load a sound file as mono";
199 ot->idname= "SOUND_OT_open_mono";
202 ot->exec= sound_open_exec;
203 ot->invoke= sound_open_invoke;
204 ot->cancel= sound_open_cancel;
207 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
210 WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH);
211 RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory");
212 RNA_def_boolean(ot->srna, "mono", TRUE, "Mono", "Mixdown the sound to mono");
215 /* ******************************************************* */
217 static int sound_update_animation_flags_exec(bContext *C, wmOperator *UNUSED(op))
220 Scene* scene = CTX_data_scene(C);
224 SEQ_BEGIN(scene->ed, seq) {
225 fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "volume", 0, &driven);
227 seq->flag |= SEQ_AUDIO_VOLUME_ANIMATED;
229 seq->flag &= ~SEQ_AUDIO_VOLUME_ANIMATED;
231 fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "pitch", 0, &driven);
233 seq->flag |= SEQ_AUDIO_PITCH_ANIMATED;
235 seq->flag &= ~SEQ_AUDIO_PITCH_ANIMATED;
237 fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "pan", 0, &driven);
239 seq->flag |= SEQ_AUDIO_PAN_ANIMATED;
241 seq->flag &= ~SEQ_AUDIO_PAN_ANIMATED;
245 fcu = id_data_find_fcurve(&scene->id, scene, &RNA_Scene, "audio_volume", 0, &driven);
247 scene->audio.flag |= AUDIO_VOLUME_ANIMATED;
249 scene->audio.flag &= ~AUDIO_VOLUME_ANIMATED;
251 return OPERATOR_FINISHED;
254 static void SOUND_OT_update_animation_flags(wmOperatorType *ot)
257 This operator is needed to set a correct state of the sound animation
258 System. Unfortunately there's no really correct place to call the exec
259 function, that's why I made it an operator that's only visible in the
260 search menu. Apart from that the bake animation operator calls it too.
264 ot->name= "Update animation";
265 ot->description= "Update animation flags";
266 ot->idname= "SOUND_OT_update_animation_flags";
269 ot->exec= sound_update_animation_flags_exec;
272 ot->flag= OPTYPE_REGISTER;
275 /* ******************************************************* */
277 static int sound_bake_animation_exec(bContext *C, wmOperator *UNUSED(op))
279 Main* bmain = CTX_data_main(C);
280 Scene* scene = CTX_data_scene(C);
281 int oldfra = scene->r.cfra;
284 sound_update_animation_flags_exec(C, NULL);
286 for(cfra = scene->r.sfra > 0 ? scene->r.sfra - 1 : 0; cfra <= scene->r.efra + 1; cfra++)
288 scene->r.cfra = cfra;
289 scene_update_for_newframe(bmain, scene, scene->lay);
292 scene->r.cfra = oldfra;
293 scene_update_for_newframe(bmain, scene, scene->lay);
295 return OPERATOR_FINISHED;
298 static void SOUND_OT_bake_animation(wmOperatorType *ot)
301 ot->name= "Update animation cache";
302 ot->description= "Updates the audio animation cache so that it's up to date";
303 ot->idname= "SOUND_OT_bake_animation";
306 ot->exec= sound_bake_animation_exec;
309 ot->flag= OPTYPE_REGISTER;
313 /******************** mixdown operator ********************/
315 static int sound_mixdown_exec(bContext *C, wmOperator *op)
317 #ifdef WITH_AUDASPACE
319 char filename[FILE_MAX];
323 int bitrate, accuracy;
324 AUD_DeviceSpecs specs;
325 AUD_Container container;
329 sound_bake_animation_exec(C, op);
331 RNA_string_get(op->ptr, "filepath", path);
332 bitrate = RNA_int_get(op->ptr, "bitrate") * 1000;
333 accuracy = RNA_int_get(op->ptr, "accuracy");
334 specs.format = RNA_enum_get(op->ptr, "format");
335 container = RNA_enum_get(op->ptr, "container");
336 codec = RNA_enum_get(op->ptr, "codec");
337 scene = CTX_data_scene(C);
338 bmain = CTX_data_main(C);
339 specs.channels = scene->r.ffcodecdata.audio_channels;
340 specs.rate = scene->r.ffcodecdata.audio_mixrate;
342 BLI_strncpy(filename, path, sizeof(filename));
343 BLI_path_abs(filename, bmain->name);
345 result = AUD_mixdown(scene->sound_scene, SFRA * specs.rate / FPS, (EFRA - SFRA) * specs.rate / FPS,
346 accuracy, filename, specs, container, codec, bitrate);
350 BKE_report(op->reports, RPT_ERROR, result);
351 return OPERATOR_CANCELLED;
353 #else // WITH_AUDASPACE
356 #endif // WITH_AUDASPACE
357 return OPERATOR_FINISHED;
360 static int sound_mixdown_invoke(bContext *C, wmOperator *op, wmEvent *event)
362 if(RNA_struct_property_is_set(op->ptr, "filepath"))
363 return sound_mixdown_exec(C, op);
365 return WM_operator_filesel(C, op, event);
368 #ifdef WITH_AUDASPACE
370 static int sound_mixdown_draw_check_prop(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
372 const char *prop_id= RNA_property_identifier(prop);
373 return !( strcmp(prop_id, "filepath") == 0 ||
374 strcmp(prop_id, "directory") == 0 ||
375 strcmp(prop_id, "filename") == 0
379 static void sound_mixdown_draw(bContext *C, wmOperator *op)
381 static EnumPropertyItem pcm_format_items[] = {
382 {AUD_FORMAT_U8, "U8", 0, "U8", "8 bit unsigned"},
383 {AUD_FORMAT_S16, "S16", 0, "S16", "16 bit signed"},
385 {AUD_FORMAT_S24, "S24", 0, "S24", "24 bit signed"},
387 {AUD_FORMAT_S32, "S32", 0, "S32", "32 bit signed"},
388 {AUD_FORMAT_FLOAT32, "F32", 0, "F32", "32 bit floating point"},
389 {AUD_FORMAT_FLOAT64, "F64", 0, "F64", "64 bit floating point"},
390 {0, NULL, 0, NULL, NULL}};
392 static EnumPropertyItem mp3_format_items[] = {
393 {AUD_FORMAT_S16, "S16", 0, "S16", "16 bit signed"},
394 {AUD_FORMAT_S32, "S32", 0, "S32", "32 bit signed"},
395 {0, NULL, 0, NULL, NULL}};
397 static EnumPropertyItem ac3_format_items[] = {
398 {AUD_FORMAT_S16, "S16", 0, "S16", "16 bit signed"},
399 {AUD_FORMAT_FLOAT32, "F32", 0, "F32", "32 bit floating point"},
400 {0, NULL, 0, NULL, NULL}};
403 static EnumPropertyItem flac_format_items[] = {
404 {AUD_FORMAT_S16, "S16", 0, "S16", "16 bit signed"},
405 {AUD_FORMAT_S24, "S24", 0, "S24", "24 bit signed"},
406 {0, NULL, 0, NULL, NULL}};
409 static EnumPropertyItem all_codec_items[] = {
410 {AUD_CODEC_AAC, "AAC", 0, "AAC", "Advanced Audio Coding"},
411 {AUD_CODEC_AC3, "AC3", 0, "AC3", "Dolby Digital ATRAC 3"},
412 {AUD_CODEC_FLAC, "FLAC", 0, "FLAC", "Free Lossless Audio Codec"},
413 {AUD_CODEC_MP2, "MP2", 0, "MP2", "MPEG-1 Audio Layer II"},
414 {AUD_CODEC_MP3, "MP3", 0, "MP3", "MPEG-2 Audio Layer III"},
415 {AUD_CODEC_PCM, "PCM", 0, "PCM", "Pulse Code Modulation (RAW)"},
416 {AUD_CODEC_VORBIS, "VORBIS", 0, "Vorbis", "Xiph.Org Vorbis Codec"},
417 {0, NULL, 0, NULL, NULL}};
419 static EnumPropertyItem ogg_codec_items[] = {
420 {AUD_CODEC_FLAC, "FLAC", 0, "FLAC", "Free Lossless Audio Codec"},
421 {AUD_CODEC_VORBIS, "VORBIS", 0, "Vorbis", "Xiph.Org Vorbis Codec"},
422 {0, NULL, 0, NULL, NULL}};
424 uiLayout *layout = op->layout;
425 wmWindowManager *wm= CTX_wm_manager(C);
427 PropertyRNA *prop_format;
428 PropertyRNA *prop_codec;
429 PropertyRNA *prop_bitrate;
431 AUD_Container container = RNA_enum_get(op->ptr, "container");
432 AUD_Codec codec = RNA_enum_get(op->ptr, "codec");
434 prop_format = RNA_struct_find_property(op->ptr, "format");
435 prop_codec = RNA_struct_find_property(op->ptr, "codec");
436 prop_bitrate = RNA_struct_find_property(op->ptr, "bitrate");
438 RNA_def_property_clear_flag(prop_bitrate, PROP_HIDDEN);
439 RNA_def_property_flag(prop_codec, PROP_HIDDEN);
440 RNA_def_property_flag(prop_format, PROP_HIDDEN);
444 case AUD_CONTAINER_AC3:
445 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
446 RNA_def_property_enum_items(prop_format, ac3_format_items);
447 RNA_def_property_enum_items(prop_codec, all_codec_items);
448 RNA_enum_set(op->ptr, "codec", AUD_CODEC_AC3);
450 case AUD_CONTAINER_FLAC:
451 RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
452 RNA_def_property_enum_items(prop_codec, all_codec_items);
453 RNA_enum_set(op->ptr, "codec", AUD_CODEC_FLAC);
455 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
456 RNA_def_property_enum_items(prop_format, flac_format_items);
458 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
461 case AUD_CONTAINER_MATROSKA:
462 RNA_def_property_clear_flag(prop_codec, PROP_HIDDEN);
463 RNA_def_property_enum_items(prop_codec, all_codec_items);
468 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
471 RNA_def_property_enum_items(prop_format, ac3_format_items);
472 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
475 RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
476 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
479 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
482 RNA_def_property_enum_items(prop_format, mp3_format_items);
483 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
486 RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
487 RNA_def_property_enum_items(prop_format, pcm_format_items);
488 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
490 case AUD_CODEC_VORBIS:
491 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
498 case AUD_CONTAINER_MP2:
499 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
500 RNA_enum_set(op->ptr, "codec", AUD_CODEC_MP2);
501 RNA_def_property_enum_items(prop_codec, all_codec_items);
503 case AUD_CONTAINER_MP3:
504 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
505 RNA_def_property_enum_items(prop_format, mp3_format_items);
506 RNA_def_property_enum_items(prop_codec, all_codec_items);
507 RNA_enum_set(op->ptr, "codec", AUD_CODEC_MP3);
509 case AUD_CONTAINER_OGG:
510 RNA_def_property_clear_flag(prop_codec, PROP_HIDDEN);
511 RNA_def_property_enum_items(prop_codec, ogg_codec_items);
512 RNA_enum_set(op->ptr, "format", AUD_FORMAT_S16);
514 case AUD_CONTAINER_WAV:
515 RNA_def_property_flag(prop_bitrate, PROP_HIDDEN);
516 RNA_def_property_clear_flag(prop_format, PROP_HIDDEN);
517 RNA_def_property_enum_items(prop_format, pcm_format_items);
518 RNA_def_property_enum_items(prop_codec, all_codec_items);
519 RNA_enum_set(op->ptr, "codec", AUD_CODEC_PCM);
525 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
528 uiDefAutoButsRNA(layout, &ptr, sound_mixdown_draw_check_prop, '\0');
530 #endif // WITH_AUDASPACE
532 static void SOUND_OT_mixdown(wmOperatorType *ot)
534 #ifdef WITH_AUDASPACE
535 static EnumPropertyItem format_items[] = {
536 {AUD_FORMAT_U8, "U8", 0, "U8", "8 bit unsigned"},
537 {AUD_FORMAT_S16, "S16", 0, "S16", "16 bit signed"},
538 {AUD_FORMAT_S24, "S24", 0, "S24", "24 bit signed"},
539 {AUD_FORMAT_S32, "S32", 0, "S32", "32 bit signed"},
540 {AUD_FORMAT_FLOAT32, "F32", 0, "F32", "32 bit floating point"},
541 {AUD_FORMAT_FLOAT64, "F64", 0, "F64", "64 bit floating point"},
542 {0, NULL, 0, NULL, NULL}};
544 static EnumPropertyItem container_items[] = {
546 {AUD_CONTAINER_AC3, "AC3", 0, "ac3", "Dolby Digital ATRAC 3"},
548 {AUD_CONTAINER_FLAC, "FLAC", 0, "flac", "Free Lossless Audio Codec"},
550 {AUD_CONTAINER_MATROSKA, "MATROSKA", 0, "mkv", "Matroska"},
551 {AUD_CONTAINER_MP2, "MP2", 0, "mp2", "MPEG-1 Audio Layer II"},
552 {AUD_CONTAINER_MP3, "MP3", 0, "mp3", "MPEG-2 Audio Layer III"},
554 {AUD_CONTAINER_OGG, "OGG", 0, "ogg", "Xiph.Org Ogg Container"},
555 {AUD_CONTAINER_WAV, "WAV", 0, "wav", "Waveform Audio File Format"},
556 {0, NULL, 0, NULL, NULL}};
558 static EnumPropertyItem codec_items[] = {
560 {AUD_CODEC_AAC, "AAC", 0, "AAC", "Advanced Audio Coding"},
561 {AUD_CODEC_AC3, "AC3", 0, "AC3", "Dolby Digital ATRAC 3"},
563 {AUD_CODEC_FLAC, "FLAC", 0, "FLAC", "Free Lossless Audio Codec"},
565 {AUD_CODEC_MP2, "MP2", 0, "MP2", "MPEG-1 Audio Layer II"},
566 {AUD_CODEC_MP3, "MP3", 0, "MP3", "MPEG-2 Audio Layer III"},
568 {AUD_CODEC_PCM, "PCM", 0, "PCM", "Pulse Code Modulation (RAW)"},
569 {AUD_CODEC_VORBIS, "VORBIS", 0, "Vorbis", "Xiph.Org Vorbis Codec"},
570 {0, NULL, 0, NULL, NULL}};
572 #endif // WITH_AUDASPACE
576 ot->description= "Mixes the scene's audio to a sound file";
577 ot->idname= "SOUND_OT_mixdown";
580 ot->exec= sound_mixdown_exec;
581 ot->invoke= sound_mixdown_invoke;
583 #ifdef WITH_AUDASPACE
584 ot->ui= sound_mixdown_draw;
587 ot->flag= OPTYPE_REGISTER;
590 WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH);
591 #ifdef WITH_AUDASPACE
592 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);
593 RNA_def_enum(ot->srna, "container", container_items, AUD_CONTAINER_FLAC, "Container", "File format");
594 RNA_def_enum(ot->srna, "codec", codec_items, AUD_CODEC_FLAC, "Codec", "Audio Codec");
595 RNA_def_enum(ot->srna, "format", format_items, AUD_FORMAT_S16, "Format", "Sample format");
596 RNA_def_int(ot->srna, "bitrate", 192, 32, 512, "Bitrate", "Bitrate in kbit/s", 32, 512);
597 #endif // WITH_AUDASPACE
600 /* ******************************************************* */
602 static int sound_poll(bContext *C)
604 Editing* ed = CTX_data_scene(C)->ed;
606 if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND)
611 /********************* pack operator *********************/
613 static int sound_pack_exec(bContext *C, wmOperator *op)
615 Main *bmain= CTX_data_main(C);
616 Editing* ed = CTX_data_scene(C)->ed;
619 if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND)
620 return OPERATOR_CANCELLED;
622 sound = ed->act_seq->sound;
624 if(!sound || sound->packedfile)
625 return OPERATOR_CANCELLED;
627 sound->packedfile= newPackedFile(op->reports, sound->name, ID_BLEND_PATH(bmain, &sound->id));
628 sound_load(CTX_data_main(C), sound);
630 return OPERATOR_FINISHED;
633 static void SOUND_OT_pack(wmOperatorType *ot)
636 ot->name= "Pack Sound";
637 ot->description= "Pack the sound into the current blend file";
638 ot->idname= "SOUND_OT_pack";
641 ot->exec= sound_pack_exec;
642 ot->poll= sound_poll;
645 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
648 /********************* unpack operator *********************/
650 static int sound_unpack_exec(bContext *C, wmOperator *op)
652 int method= RNA_enum_get(op->ptr, "method");
655 /* find the suppplied image by name */
656 if (RNA_struct_property_is_set(op->ptr, "id")) {
657 char sndname[MAX_ID_NAME-2];
658 RNA_string_get(op->ptr, "id", sndname);
659 sound = BLI_findstring(&CTX_data_main(C)->sound, sndname, offsetof(ID, name) + 2);
662 if(!sound || !sound->packedfile)
663 return OPERATOR_CANCELLED;
665 if(G.fileflags & G_AUTOPACK)
666 BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save");
668 unpackSound(CTX_data_main(C), op->reports, sound, method);
670 return OPERATOR_FINISHED;
673 static int sound_unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
675 Editing* ed = CTX_data_scene(C)->ed;
678 if(RNA_struct_property_is_set(op->ptr, "id"))
679 return sound_unpack_exec(C, op);
681 if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND)
682 return OPERATOR_CANCELLED;
684 sound = ed->act_seq->sound;
686 if(!sound || !sound->packedfile)
687 return OPERATOR_CANCELLED;
689 if(G.fileflags & G_AUTOPACK)
690 BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save");
692 unpack_menu(C, "SOUND_OT_unpack", sound->id.name+2, sound->name, "sounds", sound->packedfile);
694 return OPERATOR_FINISHED;
697 static void SOUND_OT_unpack(wmOperatorType *ot)
700 ot->name= "Unpack Sound";
701 ot->description= "Unpack the sound to the samples filename";
702 ot->idname= "SOUND_OT_unpack";
705 ot->exec= sound_unpack_exec;
706 ot->invoke= sound_unpack_invoke;
707 ot->poll= sound_poll;
710 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
713 RNA_def_enum(ot->srna, "method", unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack");
714 RNA_def_string(ot->srna, "id", "", MAX_ID_NAME-2, "Sound Name", "Sound datablock name to unpack"); /* XXX, weark!, will fail with library, name collisions */
717 /* ******************************************************* */
719 void ED_operatortypes_sound(void)
721 WM_operatortype_append(SOUND_OT_open);
722 WM_operatortype_append(SOUND_OT_open_mono);
723 WM_operatortype_append(SOUND_OT_mixdown);
724 WM_operatortype_append(SOUND_OT_pack);
725 WM_operatortype_append(SOUND_OT_unpack);
726 WM_operatortype_append(SOUND_OT_update_animation_flags);
727 WM_operatortype_append(SOUND_OT_bake_animation);