Merge pull request #372 from Palakis/frontend-events-ifelse-refactor

events: refactor the massive if else chain in the frontend event callback
This commit is contained in:
Stéphane Lepin 2019-09-03 02:40:07 +02:00 committed by GitHub
commit 6c881a5da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,87 +132,112 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private
return; return;
} }
if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) { switch (event) {
owner->hookTransitionBeginEvent(); case OBS_FRONTEND_EVENT_FINISHED_LOADING:
} owner->hookTransitionBeginEvent();
else if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) { break;
owner->OnSceneChange();
}
else if (event == OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED) {
owner->OnSceneListChange();
}
else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) {
owner->hookTransitionBeginEvent();
owner->OnSceneCollectionChange();
}
else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED) {
owner->OnSceneCollectionListChange();
}
else if (event == OBS_FRONTEND_EVENT_TRANSITION_CHANGED) {
owner->OnTransitionChange();
}
else if (event == OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED) {
owner->hookTransitionBeginEvent();
owner->OnTransitionListChange();
}
else if (event == OBS_FRONTEND_EVENT_PROFILE_CHANGED) {
owner->OnProfileChange();
}
else if (event == OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED) {
owner->OnProfileListChange();
}
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTING) {
owner->OnStreamStarting();
}
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTED) {
owner->streamStatusTimer.start(STATUS_INTERVAL);
owner->StreamStatus();
owner->OnStreamStarted(); case OBS_FRONTEND_EVENT_SCENE_CHANGED:
} owner->OnSceneChange();
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPING) { break;
owner->streamStatusTimer.stop();
owner->OnStreamStopping(); case OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED:
} owner->OnSceneListChange();
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPED) { break;
owner->OnStreamStopped();
} case OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED:
else if (event == OBS_FRONTEND_EVENT_RECORDING_STARTING) { owner->hookTransitionBeginEvent();
owner->OnRecordingStarting(); owner->OnSceneCollectionChange();
} break;
else if (event == OBS_FRONTEND_EVENT_RECORDING_STARTED) {
owner->OnRecordingStarted(); case OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED:
} owner->OnSceneCollectionListChange();
else if (event == OBS_FRONTEND_EVENT_RECORDING_STOPPING) { break;
owner->OnRecordingStopping();
} case OBS_FRONTEND_EVENT_TRANSITION_CHANGED:
else if (event == OBS_FRONTEND_EVENT_RECORDING_STOPPED) { owner->OnTransitionChange();
owner->OnRecordingStopped(); break;
}
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING) { case OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED:
owner->OnReplayStarting(); owner->hookTransitionBeginEvent();
} owner->OnTransitionListChange();
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED) { break;
owner->OnReplayStarted();
} case OBS_FRONTEND_EVENT_PROFILE_CHANGED:
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING) { owner->OnProfileChange();
owner->OnReplayStopping(); break;
}
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED) { case OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED:
owner->OnReplayStopped(); owner->OnProfileListChange();
} break;
else if (event == OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED) {
owner->OnStudioModeSwitched(true); case OBS_FRONTEND_EVENT_STREAMING_STARTING:
} owner->OnStreamStarting();
else if (event == OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED) { break;
owner->OnStudioModeSwitched(false);
} case OBS_FRONTEND_EVENT_STREAMING_STARTED:
else if (event == OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED) { owner->streamStatusTimer.start(STATUS_INTERVAL);
owner->OnPreviewSceneChanged(); owner->StreamStatus();
} owner->OnStreamStarted();
else if (event == OBS_FRONTEND_EVENT_EXIT) { break;
owner->unhookTransitionBeginEvent();
owner->OnExit(); case OBS_FRONTEND_EVENT_STREAMING_STOPPING:
owner->streamStatusTimer.stop();
owner->OnStreamStopping();
break;
case OBS_FRONTEND_EVENT_STREAMING_STOPPED:
owner->OnStreamStopped();
break;
case OBS_FRONTEND_EVENT_RECORDING_STARTING:
owner->OnRecordingStarting();
break;
case OBS_FRONTEND_EVENT_RECORDING_STARTED:
owner->OnRecordingStarted();
break;
case OBS_FRONTEND_EVENT_RECORDING_STOPPING:
owner->OnRecordingStopping();
break;
case OBS_FRONTEND_EVENT_RECORDING_STOPPED:
owner->OnRecordingStopped();
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING:
owner->OnReplayStarting();
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED:
owner->OnReplayStarted();
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING:
owner->OnReplayStopping();
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED:
owner->OnReplayStopped();
break;
case OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED:
owner->OnStudioModeSwitched(true);
break;
case OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED:
owner->OnStudioModeSwitched(false);
break;
case OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED:
owner->OnPreviewSceneChanged();
break;
case OBS_FRONTEND_EVENT_EXIT:
owner->unhookTransitionBeginEvent();
owner->OnExit();
break;
} }
} }