Debian Codegraph @

modules/mp3/resource_importer_mp3.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* resource_importer_mp3.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "resource_importer_mp3.h"
32
33 #include "core/io/file_access.h"
34 #include "core/io/resource_saver.h"
35
36 #ifdef TOOLS_ENABLED
37 #include "editor/import/audio_stream_import_settings.h"
38 #endif
39
40 String ResourceImporterMP3::get_importer_name() const {
41 return "mp3";
42 }
43
44 String ResourceImporterMP3::get_visible_name() const {
45 return "MP3";
46 }
47
48 void ResourceImporterMP3::get_recognized_extensions(List<String> *p_extensions) const {
49 #ifndef DR_MP3_ONLY_MP3
50 p_extensions->push_back("mp1");
51 p_extensions->push_back("mp2");
52 #endif
53 p_extensions->push_back("mp3");
54 }
55
56 String ResourceImporterMP3::get_save_extension() const {
57 return "mp3str";
58 }
59
60 String ResourceImporterMP3::get_resource_type() const {
61 return "AudioStreamMP3";
62 }
63
64 bool ResourceImporterMP3::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
65 return true;
66 }
67
68 int ResourceImporterMP3::get_preset_count() const {
69 return 0;
70 }
71
72 String ResourceImporterMP3::get_preset_name(int p_idx) const {
73 return String();
74 }
75
76 void ResourceImporterMP3::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
77 r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), false));
78 r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "loop_offset"), 0));
79 r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "bpm", PROPERTY_HINT_RANGE, "0,400,0.01,or_greater"), 0));
80 r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "beat_count", PROPERTY_HINT_RANGE, "0,512,or_greater"), 0));
81 r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "bar_beats", PROPERTY_HINT_RANGE, "2,32,or_greater"), 4));
82 }
83
84 #ifdef TOOLS_ENABLED
85 bool ResourceImporterMP3::has_advanced_options() const {
86 return true;
87 }
88
89 void ResourceImporterMP3::show_advanced_options(const String &p_path) {
90 Ref<AudioStreamMP3> mp3_stream = AudioStreamMP3::load_from_file(p_path);
91 if (mp3_stream.is_valid()) {
92 AudioStreamImportSettingsDialog::get_singleton()->edit(p_path, "mp3", mp3_stream);
93 }
94 }
95 #endif
96
97 Error ResourceImporterMP3::import(ResourceUID::ID p_source_id, const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
98 bool loop = p_options["loop"];
99 float loop_offset = p_options["loop_offset"];
100 double bpm = p_options["bpm"];
101 float beat_count = p_options["beat_count"];
102 float bar_beats = p_options["bar_beats"];
103
104 Ref<AudioStreamMP3> mp3_stream = AudioStreamMP3::load_from_file(p_source_file);
105 if (mp3_stream.is_null()) {
106 return ERR_CANT_OPEN;
107 }
108
109 mp3_stream->set_loop(loop);
110 mp3_stream->set_loop_offset(loop_offset);
111 mp3_stream->set_bpm(bpm);
112 mp3_stream->set_beat_count(beat_count);
113 mp3_stream->set_bar_beats(bar_beats);
114
115 return ResourceSaver::save(mp3_stream, p_save_path + ".mp3str");
116 }
117
118 ResourceImporterMP3::ResourceImporterMP3() {
119 }