Blender V4.5
rna_sound_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2015 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "RNA_define.hh"
10#include "RNA_enum_types.hh"
11
12#include "BKE_packedFile.hh"
13
14#include "rna_internal.hh"
15
16#ifdef RNA_RUNTIME
17
18static void rna_Sound_pack(bSound *sound, Main *bmain, ReportList *reports)
19{
20 const bool is_packed = sound->packedfile != nullptr;
21
22 if (is_packed) {
23 /* Sound is already packed and considered unmodified, do not attempt to repack it, since its
24 * original file may not be available anymore on the current FS.
25 *
26 * See #152638.
27 */
28 return;
29 }
30
32 reports, sound->filepath, ID_BLEND_PATH(bmain, &sound->id));
33}
34
35static void rna_Sound_unpack(bSound *sound, Main *bmain, ReportList *reports, int method)
36{
37 if (!sound->packedfile) {
38 BKE_report(reports, RPT_ERROR, "Sound not packed");
39 return;
40 }
41
42 if (!ID_IS_EDITABLE(&sound->id)) {
43 BKE_report(reports, RPT_ERROR, "Sound is not editable");
44 return;
45 }
46
47 /* reports its own error on failure */
49}
50
51#else
52
54{
55 FunctionRNA *func;
56
57 func = RNA_def_function(srna, "pack", "rna_Sound_pack");
58 RNA_def_function_ui_description(func, "Pack the sound into the current blend file");
60
61 func = RNA_def_function(srna, "unpack", "rna_Sound_unpack");
62 RNA_def_function_ui_description(func, "Unpack the sound to the samples filename");
65 func, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "method", "How to unpack");
66}
67
68#endif
int BKE_packedfile_unpack_sound(Main *bmain, ReportList *reports, bSound *sound, enum ePF_FileStatus how)
PackedFile * BKE_packedfile_new(ReportList *reports, const char *filepath_rel, const char *basepath)
ePF_FileStatus
@ PF_USE_LOCAL
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
@ FUNC_USE_REPORTS
Definition RNA_types.hh:805
@ FUNC_USE_MAIN
Definition RNA_types.hh:803
ReportList * reports
Definition WM_types.hh:1025
#define ID_BLEND_PATH(_bmain, _id)
#define ID_IS_EDITABLE(_id)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_function_flag(FunctionRNA *func, int flag)
const EnumPropertyItem rna_enum_unpack_method_items[]
void RNA_api_sound(StructRNA *srna)
struct PackedFile * packedfile
char filepath[1024]