Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default callback setting #136

Merged
merged 7 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion demo/Script/ChangeColor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func _ready():
# warning-ignore:return_value_discarded
self.connect("body_exited", self, "leave")
id = Fmod.create_event_instance("event:/Music/Level 02")
Fmod.set_callback(id, Fmod.FMOD_STUDIO_EVENT_CALLBACK_ALL)
Fmod.start_event(id)
Fmod.set_event_paused(id, true)

Expand Down
1 change: 1 addition & 0 deletions demo/Script/FmodTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ func _enter_tree():
Fmod.init(1024, Fmod.FMOD_STUDIO_INIT_LIVEUPDATE, Fmod.FMOD_INIT_NORMAL)
Fmod.set_sound_3D_settings(1, 32, 1)
Fmod.set_listener_number(2)
Fmod.set_default_callback(Fmod.FMOD_STUDIO_EVENT_CALLBACK_ALL)

# load banks
# warning-ignore:return_value_discarded
Expand Down
6 changes: 6 additions & 0 deletions demo/addons/fmod/Fmod.gd
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ func unmute_all_events() -> void:
func set_callback(instanceId: int, callbackMask: int) -> void:
godot_fmod.set_callback(instanceId, callbackMask)

func set_default_callback(callbackMask: int) -> void:
godot_fmod.set_default_callback(callbackMask)

func set_desc_callback(path: String, callbackMask: int) -> void:
godot_fmod.set_desc_callback(path, callbackMask)

###########
###SOUND###
###########
Expand Down
47 changes: 29 additions & 18 deletions src/godot_fmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ void Fmod::_register_methods() {
register_method("get_sound_volume", &Fmod::get_sound_volume);
register_method("set_sound_pitch", &Fmod::set_sound_pitch);
register_method("get_sound_pitch", &Fmod::get_sound_pitch);
register_method("set_callback", &Fmod::set_callback);
register_method("set_sound_3D_settings", &Fmod::set_sound_3d_settings);
register_method("wait_for_all_loads", &Fmod::wait_for_all_loads);
register_method("get_available_drivers", &Fmod::get_available_drivers);
Expand All @@ -143,6 +142,9 @@ void Fmod::_register_methods() {
register_method("get_dsp_buffer_length", &Fmod::get_system_dsp_buffer_length);
register_method("get_dsp_num_buffers", &Fmod::get_system_dsp_num_buffers);
register_method("_process", &Fmod::_process);
register_method("set_callback", &Fmod::set_callback);
register_method("set_desc_callback", &Fmod::set_desc_callback);
register_method("set_default_callback", &Fmod::set_default_callback);

register_signal<Fmod>("timeline_beat", "params", GODOT_VARIANT_TYPE_DICTIONARY);
register_signal<Fmod>("timeline_marker", "params", GODOT_VARIANT_TYPE_DICTIONARY);
Expand Down Expand Up @@ -945,8 +947,7 @@ float Fmod::desc_get_sound_size(const String& eventPath) {
Dictionary Fmod::desc_get_parameter_description_by_name(const String& eventPath, const String& name) {
Dictionary paramDesc;
FIND_AND_CHECK(eventPath, eventDescriptions, paramDesc)
FMOD_STUDIO_PARAMETER_DESCRIPTION
pDesc;
FMOD_STUDIO_PARAMETER_DESCRIPTION pDesc;
if (ERROR_CHECK(instance->getParameterDescriptionByName(name.utf8().get_data(), &pDesc))) {
paramDesc["name"] = String(pDesc.name);
paramDesc["id_first"] = pDesc.id.data1;
Expand All @@ -964,8 +965,7 @@ Dictionary Fmod::desc_get_parameter_description_by_id(const String& eventPath, c
FMOD_STUDIO_PARAMETER_ID paramId;
paramId.data1 = (unsigned int) idPair[0];
paramId.data2 = (unsigned int) idPair[1];
FMOD_STUDIO_PARAMETER_DESCRIPTION
pDesc;
FMOD_STUDIO_PARAMETER_DESCRIPTION pDesc;
if (ERROR_CHECK(instance->getParameterDescriptionByID(paramId, &pDesc))) {
paramDesc["name"] = String(pDesc.name);
paramDesc["id_first"] = pDesc.id.data1;
Expand All @@ -987,8 +987,7 @@ int Fmod::desc_get_parameter_description_count(const String& eventPath) {
Dictionary Fmod::desc_get_parameter_description_by_index(const String& eventPath, int index) {
Dictionary paramDesc;
FIND_AND_CHECK(eventPath, eventDescriptions, paramDesc)
FMOD_STUDIO_PARAMETER_DESCRIPTION
pDesc;
FMOD_STUDIO_PARAMETER_DESCRIPTION pDesc;
if (ERROR_CHECK(instance->getParameterDescriptionByIndex(index, &pDesc))) {
paramDesc["name"] = String(pDesc.name);
paramDesc["id_first"] = pDesc.id.data1;
Expand All @@ -1003,8 +1002,7 @@ Dictionary Fmod::desc_get_parameter_description_by_index(const String& eventPath
Dictionary Fmod::desc_get_user_property(const String& eventPath, const String& name) {
Dictionary propDesc;
FIND_AND_CHECK(eventPath, eventDescriptions, propDesc)
FMOD_STUDIO_USER_PROPERTY
uProp;
FMOD_STUDIO_USER_PROPERTY uProp;
if (ERROR_CHECK(instance->getUserProperty(name.utf8().get_data(), &uProp))) {
FMOD_STUDIO_USER_PROPERTY_TYPE fType = uProp.type;
if (fType == FMOD_STUDIO_USER_PROPERTY_TYPE_INTEGER)
Expand All @@ -1029,8 +1027,7 @@ int Fmod::desc_get_user_property_count(const String& eventPath) {
Dictionary Fmod::desc_user_property_by_index(const String& eventPath, int index) {
Dictionary propDesc;
FIND_AND_CHECK(eventPath, eventDescriptions, propDesc)
FMOD_STUDIO_USER_PROPERTY
uProp;
FMOD_STUDIO_USER_PROPERTY uProp;
if (ERROR_CHECK(instance->getUserPropertyByIndex(index, &uProp))) {
FMOD_STUDIO_USER_PROPERTY_TYPE fType = uProp.type;
if (fType == FMOD_STUDIO_USER_PROPERTY_TYPE_INTEGER)
Expand All @@ -1042,10 +1039,15 @@ Dictionary Fmod::desc_user_property_by_index(const String& eventPath, int index)
else if (fType == FMOD_STUDIO_USER_PROPERTY_TYPE_STRING)
propDesc[String(uProp.name)] = String(uProp.stringvalue);
}

return propDesc;
}

void Fmod::set_desc_callback(const String& eventPath, int callbackMask) {
FIND_AND_CHECK(eventPath, eventDescriptions)
ERROR_CHECK(instance->setCallback(Callbacks::eventCallback, callbackMask));
GODOT_LOG(0, String("Default callBack set on description event ") + eventPath)
}

bool Fmod::get_bus_mute(const String& busPath) {
bool mute = false;
FIND_AND_CHECK(busPath, buses, mute)
Expand Down Expand Up @@ -1213,12 +1215,17 @@ FMOD::Studio::EventInstance* Fmod::_create_instance(const String& eventName, boo
FIND_AND_CHECK(eventName, eventDescriptions, nullptr)
FMOD::Studio::EventInstance* eventInstance = nullptr;
ERROR_CHECK(instance->createInstance(&eventInstance));
if (eventInstance && (!isOneShot || gameObject)) {
auto* eventInfo = new EventInfo();
eventInfo->gameObj = gameObject;
eventInfo->isOneShot = isOneShot;
eventInstance->setUserData(eventInfo);
events.append(eventInstance);
if (eventInstance) {
if (defaultCallbackMask != 0x00000000) {
eventInstance->setCallback(Callbacks::eventCallback, defaultCallbackMask);
}
if (!isOneShot || gameObject) {
auto* eventInfo = new EventInfo();
eventInfo->gameObj = gameObject;
eventInfo->isOneShot = isOneShot;
eventInstance->setUserData(eventInfo);
events.append(eventInstance);
}
}
return eventInstance;
}
Expand Down Expand Up @@ -1692,6 +1699,10 @@ void Fmod::set_callback(const uint64_t instanceId, int callbackMask) {
GODOT_LOG(0, String("CallBack set on event ") + String::num(instanceId, 0))
}

void Fmod::set_default_callback(int p_callbackMask) {
defaultCallbackMask = p_callbackMask;
}

// runs on the game thread
void Fmod::_run_callbacks() {
std::lock_guard<std::mutex> lk(Callbacks::callback_mut);
Expand Down
7 changes: 5 additions & 2 deletions src/godot_fmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ namespace godot {
Listener listeners[FMOD_MAX_LISTENERS];
bool listenerWarning = true;

int defaultCallbackMask = 0x00000000;

Vector<LoadingBank*> loadingBanks;
Map<String, FMOD::Studio::Bank*> banks;
Map<String, FMOD::Studio::EventDescription*> eventDescriptions;
Expand Down Expand Up @@ -224,6 +226,7 @@ namespace godot {
Dictionary get_event_3d_attributes(uint64_t instanceId);
Dictionary get_event_2d_attributes(uint64_t instanceId);
void set_event_2d_attributes(uint64_t instanceId, Transform2D position);
void set_callback(uint64_t instanceId, int callbackMask);

/* event descriptions functions */
int desc_get_length(const String& eventPath);
Expand All @@ -247,6 +250,7 @@ namespace godot {
Dictionary desc_get_user_property(const String& eventPath, const String& name);
int desc_get_user_property_count(const String& eventPath);
Dictionary desc_user_property_by_index(const String& eventPath, int index);
void set_desc_callback(const String& eventPath, int callbackMask);

/* bus functions */
bool get_bus_mute(const String& busPath);
Expand Down Expand Up @@ -307,8 +311,7 @@ namespace godot {
Dictionary get_global_parameter_desc_by_id(const Array& idPair);
int get_global_parameter_desc_count();
Array get_global_parameter_desc_list();

void set_callback(const uint64_t instanceId, int callbackMask);
void set_default_callback(int p_callbackMask);
};
}// namespace godot

Expand Down