2
0
Эх сурвалжийг харах

Add function to get the list of samples, closes #5561

Juan Linietsky 9 жил өмнө
parent
commit
49b288d331

+ 17 - 2
scene/resources/sample_library.cpp

@@ -106,9 +106,9 @@ void SampleLibrary::remove_sample(const StringName& p_name) {
 	sample_map.erase(p_name);
 }
 
-void SampleLibrary::get_sample_list(List<StringName> *p_samples) {
+void SampleLibrary::get_sample_list(List<StringName> *p_samples) const {
 
-	for(Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) {
+	for(const Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) {
 
 		p_samples->push_back(E->key());
 	}
@@ -177,7 +177,20 @@ float SampleLibrary::sample_get_pitch_scale(const StringName& p_name) const{
 	return sample_map[p_name].pitch_scale;
 }
 
+Array SampleLibrary::_get_sample_list() const {
 
+	List<StringName> snames;
+	get_sample_list(&snames);
+
+	snames.sort_custom<StringName::AlphCompare>();
+
+	Array ret;
+	for (List<StringName>::Element *E=snames.front();E;E=E->next()) {
+		ret.push_back(E->get());
+	}
+
+	return ret;
+}
 
 void SampleLibrary::_bind_methods() {
 
@@ -186,6 +199,8 @@ void SampleLibrary::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("has_sample","name"),&SampleLibrary::has_sample );
 	ObjectTypeDB::bind_method(_MD("remove_sample","name"),&SampleLibrary::remove_sample );
 
+	ObjectTypeDB::bind_method(_MD("get_sample_list"),&SampleLibrary::_get_sample_list );
+
 	ObjectTypeDB::bind_method(_MD("sample_set_volume_db","name","db"),&SampleLibrary::sample_set_volume_db );
 	ObjectTypeDB::bind_method(_MD("sample_get_volume_db","name"),&SampleLibrary::sample_get_volume_db );
 

+ 3 - 1
scene/resources/sample_library.h

@@ -47,6 +47,8 @@ class SampleLibrary : public Resource {
 	};
 
 	Map<StringName,SampleData > sample_map;
+
+	Array _get_sample_list() const;
 protected:
 
 	bool _set(const StringName& p_name, const Variant& p_value);
@@ -66,7 +68,7 @@ public:
 	void sample_set_pitch_scale(const StringName& p_name, float p_pitch);
 	float sample_get_pitch_scale(const StringName& p_name) const;
 	Ref<Sample> get_sample(const StringName& p_name) const;
-	void get_sample_list(List<StringName> *p_samples);
+	void get_sample_list(List<StringName> *p_samples) const;
 	void remove_sample(const StringName& p_name);
 	StringName get_sample_idx(int p_idx) const;