You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-19 14:31:59 +00:00
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
@@ -28,32 +28,30 @@
|
||||
/*************************************************************************/
|
||||
#include "sample_library.h"
|
||||
|
||||
|
||||
bool SampleLibrary::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
bool SampleLibrary::_set(const StringName &p_name, const Variant &p_value) {
|
||||
|
||||
if (String(p_name).begins_with("samples/")) {
|
||||
|
||||
String name=String(p_name).get_slicec('/',1);
|
||||
if (p_value.get_type()==Variant::NIL)
|
||||
String name = String(p_name).get_slicec('/', 1);
|
||||
if (p_value.get_type() == Variant::NIL)
|
||||
sample_map.erase(name);
|
||||
else {
|
||||
SampleData sd;
|
||||
|
||||
if (p_value.get_type()==Variant::OBJECT)
|
||||
sd.sample=p_value;
|
||||
else if (p_value.get_type()==Variant::DICTIONARY) {
|
||||
if (p_value.get_type() == Variant::OBJECT)
|
||||
sd.sample = p_value;
|
||||
else if (p_value.get_type() == Variant::DICTIONARY) {
|
||||
|
||||
Dictionary d = p_value;
|
||||
ERR_FAIL_COND_V(!d.has("sample"),false);
|
||||
ERR_FAIL_COND_V(!d.has("pitch"),false);
|
||||
ERR_FAIL_COND_V(!d.has("db"),false);
|
||||
sd.sample=d["sample"];
|
||||
sd.pitch_scale=d["pitch"];
|
||||
sd.db=d["db"];
|
||||
ERR_FAIL_COND_V(!d.has("sample"), false);
|
||||
ERR_FAIL_COND_V(!d.has("pitch"), false);
|
||||
ERR_FAIL_COND_V(!d.has("db"), false);
|
||||
sd.sample = d["sample"];
|
||||
sd.pitch_scale = d["pitch"];
|
||||
sd.db = d["db"];
|
||||
}
|
||||
|
||||
sample_map[name]=sd;
|
||||
sample_map[name] = sd;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -62,17 +60,17 @@ bool SampleLibrary::_set(const StringName& p_name, const Variant& p_value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SampleLibrary::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
bool SampleLibrary::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
|
||||
if (String(p_name).begins_with("samples/")) {
|
||||
|
||||
String name=String(p_name).get_slicec('/',1);
|
||||
if(sample_map.has(name)) {
|
||||
String name = String(p_name).get_slicec('/', 1);
|
||||
if (sample_map.has(name)) {
|
||||
Dictionary d;
|
||||
d["sample"]=sample_map[name].sample;
|
||||
d["pitch"]=sample_map[name].pitch_scale;
|
||||
d["db"]=sample_map[name].db;
|
||||
r_ret=d;
|
||||
d["sample"] = sample_map[name].sample;
|
||||
d["pitch"] = sample_map[name].pitch_scale;
|
||||
d["db"] = sample_map[name].db;
|
||||
r_ret = d;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -81,67 +79,63 @@ bool SampleLibrary::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SampleLibrary::add_sample(const StringName& p_name, const Ref<Sample>& p_sample) {
|
||||
void SampleLibrary::add_sample(const StringName &p_name, const Ref<Sample> &p_sample) {
|
||||
|
||||
ERR_FAIL_COND(p_sample.is_null());
|
||||
|
||||
SampleData sd;
|
||||
sd.sample=p_sample;
|
||||
sample_map[p_name]=sd;
|
||||
sd.sample = p_sample;
|
||||
sample_map[p_name] = sd;
|
||||
}
|
||||
|
||||
Ref<Sample> SampleLibrary::get_sample(const StringName& p_name) const {
|
||||
Ref<Sample> SampleLibrary::get_sample(const StringName &p_name) const {
|
||||
|
||||
ERR_FAIL_COND_V(!sample_map.has(p_name),Ref<Sample>());
|
||||
ERR_FAIL_COND_V(!sample_map.has(p_name), Ref<Sample>());
|
||||
|
||||
return sample_map[p_name].sample;
|
||||
}
|
||||
|
||||
void SampleLibrary::remove_sample(const StringName& p_name) {
|
||||
void SampleLibrary::remove_sample(const StringName &p_name) {
|
||||
|
||||
sample_map.erase(p_name);
|
||||
}
|
||||
|
||||
void SampleLibrary::get_sample_list(List<StringName> *p_samples) const {
|
||||
|
||||
for(const 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool SampleLibrary::has_sample(const StringName& p_name) const {
|
||||
bool SampleLibrary::has_sample(const StringName &p_name) const {
|
||||
|
||||
return sample_map.has(p_name);
|
||||
}
|
||||
|
||||
void SampleLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
|
||||
List<PropertyInfo> tpl;
|
||||
for(Map<StringName,SampleData>::Element *E=sample_map.front();E;E=E->next()) {
|
||||
for (Map<StringName, SampleData>::Element *E = sample_map.front(); E; E = E->next()) {
|
||||
|
||||
tpl.push_back( PropertyInfo( Variant::DICTIONARY, "samples/"+E->key(),PROPERTY_HINT_RESOURCE_TYPE,"Sample",PROPERTY_USAGE_NOEDITOR ) );
|
||||
tpl.push_back(PropertyInfo(Variant::DICTIONARY, "samples/" + E->key(), PROPERTY_HINT_RESOURCE_TYPE, "Sample", PROPERTY_USAGE_NOEDITOR));
|
||||
}
|
||||
|
||||
tpl.sort();
|
||||
//sort so order is kept
|
||||
for(List<PropertyInfo>::Element *E=tpl.front();E;E=E->next()) {
|
||||
for (List<PropertyInfo>::Element *E = tpl.front(); E; E = E->next()) {
|
||||
p_list->push_back(E->get());
|
||||
}
|
||||
}
|
||||
|
||||
StringName SampleLibrary::get_sample_idx(int p_idx) const {
|
||||
|
||||
int idx=0;
|
||||
for (Map<StringName, SampleData >::Element *E=sample_map.front();E;E=E->next()) {
|
||||
int idx = 0;
|
||||
for (Map<StringName, SampleData>::Element *E = sample_map.front(); E; E = E->next()) {
|
||||
|
||||
if (p_idx==idx)
|
||||
if (p_idx == idx)
|
||||
return E->key();
|
||||
idx++;
|
||||
}
|
||||
@@ -149,30 +143,29 @@ StringName SampleLibrary::get_sample_idx(int p_idx) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
void SampleLibrary::sample_set_volume_db(const StringName& p_name, float p_db) {
|
||||
|
||||
ERR_FAIL_COND( !sample_map.has(p_name) );
|
||||
sample_map[p_name].db=p_db;
|
||||
void SampleLibrary::sample_set_volume_db(const StringName &p_name, float p_db) {
|
||||
|
||||
ERR_FAIL_COND(!sample_map.has(p_name));
|
||||
sample_map[p_name].db = p_db;
|
||||
}
|
||||
|
||||
float SampleLibrary::sample_get_volume_db(const StringName& p_name) const{
|
||||
float SampleLibrary::sample_get_volume_db(const StringName &p_name) const {
|
||||
|
||||
ERR_FAIL_COND_V( !sample_map.has(p_name),0 );
|
||||
ERR_FAIL_COND_V(!sample_map.has(p_name), 0);
|
||||
|
||||
return sample_map[p_name].db;
|
||||
}
|
||||
|
||||
void SampleLibrary::sample_set_pitch_scale(const StringName& p_name, float p_pitch){
|
||||
void SampleLibrary::sample_set_pitch_scale(const StringName &p_name, float p_pitch) {
|
||||
|
||||
ERR_FAIL_COND( !sample_map.has(p_name) );
|
||||
ERR_FAIL_COND(!sample_map.has(p_name));
|
||||
|
||||
sample_map[p_name].pitch_scale=p_pitch;
|
||||
sample_map[p_name].pitch_scale = p_pitch;
|
||||
}
|
||||
|
||||
float SampleLibrary::sample_get_pitch_scale(const StringName& p_name) const{
|
||||
float SampleLibrary::sample_get_pitch_scale(const StringName &p_name) const {
|
||||
|
||||
ERR_FAIL_COND_V( !sample_map.has(p_name),0 );
|
||||
ERR_FAIL_COND_V(!sample_map.has(p_name), 0);
|
||||
|
||||
return sample_map[p_name].pitch_scale;
|
||||
}
|
||||
@@ -185,7 +178,7 @@ Array SampleLibrary::_get_sample_list() const {
|
||||
snames.sort_custom<StringName::AlphCompare>();
|
||||
|
||||
Array ret;
|
||||
for (List<StringName>::Element *E=snames.front();E;E=E->next()) {
|
||||
for (List<StringName>::Element *E = snames.front(); E; E = E->next()) {
|
||||
ret.push_back(E->get());
|
||||
}
|
||||
|
||||
@@ -194,22 +187,19 @@ Array SampleLibrary::_get_sample_list() const {
|
||||
|
||||
void SampleLibrary::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("add_sample","name","sample:Sample"),&SampleLibrary::add_sample );
|
||||
ObjectTypeDB::bind_method(_MD("get_sample:Sample","name"),&SampleLibrary::get_sample );
|
||||
ObjectTypeDB::bind_method(_MD("has_sample","name"),&SampleLibrary::has_sample );
|
||||
ObjectTypeDB::bind_method(_MD("remove_sample","name"),&SampleLibrary::remove_sample );
|
||||
ObjectTypeDB::bind_method(_MD("add_sample", "name", "sample:Sample"), &SampleLibrary::add_sample);
|
||||
ObjectTypeDB::bind_method(_MD("get_sample:Sample", "name"), &SampleLibrary::get_sample);
|
||||
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 );
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("sample_set_pitch_scale","name","pitch"),&SampleLibrary::sample_set_pitch_scale );
|
||||
ObjectTypeDB::bind_method(_MD("sample_get_pitch_scale","name"),&SampleLibrary::sample_get_pitch_scale );
|
||||
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);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("sample_set_pitch_scale", "name", "pitch"), &SampleLibrary::sample_set_pitch_scale);
|
||||
ObjectTypeDB::bind_method(_MD("sample_get_pitch_scale", "name"), &SampleLibrary::sample_get_pitch_scale);
|
||||
}
|
||||
|
||||
SampleLibrary::SampleLibrary()
|
||||
{
|
||||
SampleLibrary::SampleLibrary() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user