Skip to content

Commit

Permalink
Merge branch 'pr/117'
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyarger committed Mar 20, 2021
2 parents 156260d + ef962db commit 75d5490
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/Midi_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MidiHook::MidiHook(const QString &json_string)
filter = obs_data_get_string(data, "filter");
transition = obs_data_get_string(data, "transition");
item = obs_data_get_string(data, "item");
hotkey = obs_data_get_string(data, "hotkey");
hotkey = obs_data_get_string(data, "hotkey");
audio_source = obs_data_get_string(data, "audio_source");
media_source = obs_data_get_string(data, "media_source");
duration.emplace(obs_data_get_int(data, "duration"));
Expand Down
4 changes: 2 additions & 2 deletions src/Midi_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class MidiHook : public QObject {
Q_OBJECT
public:
MidiHook();
MidiHook(const QString& json_string);
MidiMessage* get_message_from_hook();
MidiHook(const QString &json_string);
MidiMessage *get_message_from_hook();
QString GetData();

int channel = -1; // midi channel
Expand Down
97 changes: 40 additions & 57 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ ActionsClass::Actions ActionsClass::string_to_action(const QString &action)
{
return QVariant(action).value<ActionsClass::Actions>();
}
QString
ActionsClass::event_to_string(const ActionsClass::obs_event_type &enumval)
QString ActionsClass::event_to_string(const ActionsClass::obs_event_type &enumval)
{
return std::move(QVariant::fromValue(enumval).toString());
}

ActionsClass::obs_event_type
ActionsClass::string_to_event(const QString &action)
ActionsClass::obs_event_type ActionsClass::string_to_event(const QString &action)
{
return QVariant(action).value<ActionsClass::obs_event_type>();
}
Expand All @@ -29,8 +27,7 @@ ActionsClass::string_to_event(const QString &action)
*/
void ActionsClass::SetCurrentScene(const QString &sceneName)
{
OBSSourceAutoRelease source =
obs_get_source_by_name(sceneName.toStdString().c_str());
OBSSourceAutoRelease source = obs_get_source_by_name(sceneName.toStdString().c_str());

if (source) {
obs_frontend_set_current_scene(source);
Expand Down Expand Up @@ -69,8 +66,8 @@ void ActionsClass::SetCurrentSceneCollection(const QString &sceneCollection)
}

/**
* Reset a scene item.
*/
* Reset a scene item.
*/
void ActionsClass::ResetSceneItem(const QString &sceneName, const QString &itemName)
{
OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName);
Expand All @@ -79,12 +76,10 @@ void ActionsClass::ResetSceneItem(const QString &sceneName, const QString &itemN
}

obs_data_t *params = obs_data_create();
obs_data_set_string(params, "scene-name",
sceneName.toStdString().c_str());
obs_data_set_string(params, "scene-name", sceneName.toStdString().c_str());
OBSDataItemAutoRelease itemField = obs_data_item_byname(params, "item");

OBSSceneItemAutoRelease sceneItem =
Utils::GetSceneItemFromRequestField(scene, itemField);
OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField);
if (!sceneItem) {
throw("specified scene item doesn't exist");
}
Expand All @@ -107,8 +102,7 @@ void ActionsClass::TransitionToProgram()
* Transitions the currently previewed scene to the main output using specified transition.
* transitionDuration is optional. (milliseconds)
*/
void ActionsClass::TransitionToProgram(const QString &transitionName,
int transitionDuration)
void ActionsClass::TransitionToProgram(const QString &transitionName, int transitionDuration)
{
if (!obs_frontend_preview_program_mode_active()) {
throw("studio mode not enabled");
Expand Down Expand Up @@ -145,21 +139,20 @@ void ActionsClass::SetTransitionDuration(int duration)
obs_frontend_set_transition_duration(duration);
}

void ActionsClass::SetSourceVisibility() {} //DOESNT EXIST
void ActionsClass::SetSourceVisibility() {} // DOESNT EXIST

void ActionsClass::ToggleSourceVisibility() {} //DOESNT EXIST
void ActionsClass::ToggleSourceVisibility() {} // DOESNT EXIST

/**
* Inverts the mute status of a specified source.
*/
* Inverts the mute status of a specified source.
*/
void ActionsClass::ToggleMute(const QString &sourceName)
{
if (sourceName.isEmpty()) {
throw("sourceName is empty");
}

OBSSourceAutoRelease source =
obs_get_source_by_name(sourceName.toUtf8());
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.toUtf8());
if (!source) {
throw("sourceName not found");
}
Expand All @@ -176,8 +169,7 @@ void ActionsClass::SetMute(const QString &sourceName, bool mute)
throw("sourceName is empty");
}

OBSSourceAutoRelease source =
obs_get_source_by_name(sourceName.toUtf8());
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.toUtf8());
if (!source) {
throw("specified source doesn't exist");
}
Expand Down Expand Up @@ -221,8 +213,7 @@ void ActionsClass::StopStreaming()
*/
void ActionsClass::StartStopRecording()
{
(obs_frontend_recording_active() ? obs_frontend_recording_stop()
: obs_frontend_recording_start());
(obs_frontend_recording_active() ? obs_frontend_recording_stop() : obs_frontend_recording_start());
}

/**
Expand All @@ -246,8 +237,8 @@ void ActionsClass::StopRecording()
}

/**
* Pause the current recording.
*/
* Pause the current recording.
*/
void ActionsClass::PauseRecording()
{
if (obs_frontend_recording_active()) {
Expand All @@ -256,8 +247,8 @@ void ActionsClass::PauseRecording()
}

/**
* Resume/unpause the current recording (if paused).
*/
* Resume/unpause the current recording (if paused).
*/
void ActionsClass::ResumeRecording()
{
if (obs_frontend_recording_active()) {
Expand All @@ -266,8 +257,8 @@ void ActionsClass::ResumeRecording()
}

/**
* Toggle the Replay Buffer on/off.
*/
* Toggle the Replay Buffer on/off.
*/
void ActionsClass::StartStopReplayBuffer()
{
if (obs_frontend_replay_buffer_active()) {
Expand All @@ -278,11 +269,11 @@ void ActionsClass::StartStopReplayBuffer()
}

/**
* Start recording into the Replay Buffer.
* Will throw an error if "Save Replay Buffer" hotkey is not set in OBS' settings.
* Setting this hotkey is mandatory, even when triggering saves only
* through obs-midi.
*/
* Start recording into the Replay Buffer.
* Will throw an error if "Save Replay Buffer" hotkey is not set in OBS' settings.
* Setting this hotkey is mandatory, even when triggering saves only
* through obs-midi.
*/
void ActionsClass::StartReplayBuffer()
{
if (!Utils::ReplayBufferEnabled()) {
Expand All @@ -295,8 +286,8 @@ void ActionsClass::StartReplayBuffer()
}

/**
* Stop recording into the Replay Buffer.
*/
* Stop recording into the Replay Buffer.
*/
void ActionsClass::StopReplayBuffer()
{
if (obs_frontend_replay_buffer_active() == true) {
Expand All @@ -305,18 +296,17 @@ void ActionsClass::StopReplayBuffer()
}

/**
* Flush and save the contents of the Replay Buffer to disk. This is
* basically the same as triggering the "Save Replay Buffer" hotkey.
* Will return an `error` if the Replay Buffer is not active.
*/
* Flush and save the contents of the Replay Buffer to disk. This is
* basically the same as triggering the "Save Replay Buffer" hotkey.
* Will return an `error` if the Replay Buffer is not active.
*/
void ActionsClass::SaveReplayBuffer()
{
if (!obs_frontend_replay_buffer_active()) {
throw("replay buffer not active");
}

OBSOutputAutoRelease replayOutput =
obs_frontend_get_replay_buffer_output();
OBSOutputAutoRelease replayOutput = obs_frontend_get_replay_buffer_output();

calldata_t cd = {0};
proc_handler_t *ph = obs_output_get_proc_handler(replayOutput);
Expand All @@ -342,8 +332,7 @@ void ActionsClass::ReloadBrowserSource() {}

void ActionsClass::TakeSourceScreenshot(const QString &source)
{
obs_frontend_take_source_screenshot(
obs_get_source_by_name(source.toStdString().c_str()));
obs_frontend_take_source_screenshot(obs_get_source_by_name(source.toStdString().c_str()));
}

void ActionsClass::EnableSourceFilter() {}
Expand All @@ -358,8 +347,7 @@ void ActionsClass::ToggleSourceFilter() {}

void ActionsClass::SetVolume(const QString &source, float volume)
{
OBSSourceAutoRelease obsSource =
obs_get_source_by_name(source.toUtf8());
OBSSourceAutoRelease obsSource = obs_get_source_by_name(source.toUtf8());
if (!obsSource) {
return; // source does not exist
}
Expand All @@ -376,8 +364,7 @@ void ActionsClass::SetSyncOffset(const QString &sourceName, int64_t sourceSyncOf
throw("source name is empty");
}

OBSSourceAutoRelease source =
obs_get_source_by_name(sourceName.toUtf8());
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.toUtf8());
if (!source) {
throw("specified source doesn't exist");
}
Expand All @@ -395,8 +382,7 @@ void ActionsClass::SetGainFilter() {}

void ActionsClass::SetOpacity() {}

void ActionsClass::do_obs_action(MidiHook *hook, int MidiVal,
ActionsClass::Actions action)
void ActionsClass::do_obs_action(MidiHook *hook, int MidiVal, ActionsClass::Actions action)
{
switch (action) {
case ActionsClass::Actions::Set_Current_Scene:
Expand All @@ -412,8 +398,7 @@ void ActionsClass::do_obs_action(MidiHook *hook, int MidiVal,
if (hook->transition.isEmpty()) {
ActionsClass::TransitionToProgram();
} else if (hook->duration != -1) {
ActionsClass::TransitionToProgram(hook->transition,
hook->duration);
ActionsClass::TransitionToProgram(hook->transition, hook->duration);
} else {
ActionsClass::TransitionToProgram(hook->transition);
}
Expand Down Expand Up @@ -459,8 +444,7 @@ void ActionsClass::do_obs_action(MidiHook *hook, int MidiVal,
ActionsClass::StopReplayBuffer();
break;
case ActionsClass::Actions::Set_Volume:
ActionsClass::SetVolume(hook->audio_source,
pow(Utils::mapper(MidiVal), 3.0));
ActionsClass::SetVolume(hook->audio_source, pow(Utils::mapper(MidiVal), 3.0));
break;
case ActionsClass::Actions::Take_Source_Screenshot:
ActionsClass::TakeSourceScreenshot(hook->source);
Expand Down Expand Up @@ -502,8 +486,7 @@ void ActionsClass::do_obs_action(MidiHook *hook, int MidiVal,
ActionsClass::ReloadBrowserSource();
break;
case ActionsClass::Actions::Set_Sync_Offset:
ActionsClass::SetSyncOffset(hook->media_source,
(int64_t)MidiVal);
ActionsClass::SetSyncOffset(hook->media_source, (int64_t)MidiVal);
break;
case ActionsClass::Actions::Set_Source_Rotation:
ActionsClass::SetSourceRotation();
Expand Down
8 changes: 3 additions & 5 deletions src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ class ActionsClass : public QObject {
void SetCurrentSceneCollection(const QString &sceneCollection);
void ResetSceneItem(const QString &sceneName, const QString &itemName);
void TransitionToProgram();
void TransitionToProgram(const QString &transitionName,
int transitionDuration = 300);
void TransitionToProgram(const QString &transitionName, int transitionDuration = 300);
void SetCurrentTransition(const QString &name);
void SetTransitionDuration(int duration); // can also be used with cc

void SetSourceVisibility(); // doesn't exist??
void ToggleSourceVisibility(); //doesn't exist?
void ToggleSourceVisibility(); // doesn't exist?

void ToggleMute(const QString &sourceName);
void SetMute(const QString &sourceName, bool mute);
Expand Down Expand Up @@ -184,6 +183,5 @@ class ActionsClass : public QObject {
void SetGainFilter();
void SetOpacity();

void do_obs_action(MidiHook *hook, int MidiVal,
ActionsClass::Actions action);
void do_obs_action(MidiHook *hook, int MidiVal, ActionsClass::Actions action);
};
3 changes: 2 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ QString Config::GetConfigStore(std::optional<QString> prepend)
os_mkdirs(path);
bfree(path);

const auto filepath = (prepend) ? obs_module_config_path(get_file_name(prepend).toStdString().c_str()) :obs_module_config_path(get_file_name().toStdString().c_str());
const auto filepath = (prepend) ? obs_module_config_path(get_file_name(prepend).toStdString().c_str())
: obs_module_config_path(get_file_name().toStdString().c_str());
obs_data_t *midiConfig = os_file_exists(filepath) ? obs_data_create_from_json_file(filepath) : obs_data_create();
if (!os_file_exists(filepath)) {
obs_data_save_json_safe(midiConfig, filepath, ".tmp", ".bkp");
Expand Down
4 changes: 1 addition & 3 deletions src/device-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
*/
#include "device-manager.h"
#include "forms/settings-dialog.h"
DeviceManager::DeviceManager()
{
}
DeviceManager::DeviceManager() {}
DeviceManager::~DeviceManager()
{
Unload();
Expand Down
21 changes: 10 additions & 11 deletions src/events.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* obs-midi
*
*
* 2020-2021 Chris Yarger <[email protected]>
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -66,7 +66,6 @@ Events::Events() : _streamStarttime(0), _lastBytesSent(0), _lastBytesSentTime(0)
Events::~Events() {}
void Events::startup()
{


// Connect to signals of all existing sources
obs_enum_sources(
Expand Down Expand Up @@ -389,10 +388,10 @@ void Events::OnSceneChange()
}
void Events::FinishedLoading()
{
hookTransitionPlaybackEvents();
startup();
started=true;
Utils::build_hotkey_map();
hookTransitionPlaybackEvents();
startup();
started = true;
Utils::build_hotkey_map();
broadcastUpdate("LoadingFinished");
}
/**
Expand Down Expand Up @@ -878,13 +877,13 @@ void Events::OnTransitionEnd(void *param, calldata_t *data)
state::transitioning = false;
auto instance = reinterpret_cast<Events *>(param);
const OBSSource transition = calldata_get_pointer<obs_source_t>(data, "source");

if (!transition) {
return;
}
if (state()._TransitionWasCalled) {
obs_frontend_set_transition_duration(state()._CurrentTransitionDuration);
const auto t =Utils::GetTransitionFromName(state()._CurrentTransition);
const auto t = Utils::GetTransitionFromName(state()._CurrentTransition);
obs_frontend_set_current_transition(t);
obs_source_release(t);
state()._TransitionWasCalled = false;
Expand All @@ -893,7 +892,6 @@ void Events::OnTransitionEnd(void *param, calldata_t *data)
blog(LOG_DEBUG, "transition %s ended - to scene %s", obs_data_get_string(fields, "name"), obs_data_get_string(fields, "to-scene"));
instance->broadcastUpdate("TransitionEnd", fields);
obs_data_release(fields);

}
/**
* A stinger transition has finished playing its video.
Expand Down Expand Up @@ -1180,7 +1178,8 @@ void Events::OnSourceFilterAdded(void *param, calldata_t *data)
* @category sources
* @since 4.6.0
*/
void Events::OnSourceRemoved(void *param, calldata_t *data) {
void Events::OnSourceRemoved(void *param, calldata_t *data)
{
auto self = reinterpret_cast<Events *>(param);

auto *source = calldata_get_pointer<obs_source_t>(data, "source");
Expand Down
Loading

0 comments on commit 75d5490

Please sign in to comment.