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 a function to put filter into a exact position #429

Open
wants to merge 1 commit into
base: streamlabs
Choose a base branch
from
Open
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
50 changes: 41 additions & 9 deletions libobs/obs-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,19 @@ static size_t find_prev_filter(obs_source_t *source, obs_source_t *filter,
return find_prev_filter(source, filter, cur_idx - 1);
}

/* reorder filter targets, not the nicest way of dealing with things */
static void reorder_filters(obs_source_t *source)
{
for (size_t i = 0; i < source->filters.num; i++) {
obs_source_t *next_filter =
(i == source->filters.num - 1)
? source
: source->filters.array[i + 1];

source->filters.array[i]->filter_target = next_filter;
}
}

/* moves filters above/below matching filter types */
static bool move_filter_dir(obs_source_t *source, obs_source_t *filter,
enum obs_order_movement movement)
Expand Down Expand Up @@ -2738,15 +2751,7 @@ static bool move_filter_dir(obs_source_t *source, obs_source_t *filter,
da_move_item(source->filters, idx, 0);
}

/* reorder filter targets, not the nicest way of dealing with things */
for (size_t i = 0; i < source->filters.num; i++) {
obs_source_t *next_filter =
(i == source->filters.num - 1)
? source
: source->filters.array[i + 1];

source->filters.array[i]->filter_target = next_filter;
}
reorder_filters(source);

return true;
}
Expand All @@ -2769,6 +2774,33 @@ void obs_source_filter_set_order(obs_source_t *source, obs_source_t *filter,
obs_source_dosignal(source, NULL, "reorder_filters");
}

void obs_source_filter_set_position(obs_source_t *source, obs_source_t *filter,
size_t position)
{
bool success = false;

if (!obs_source_valid(source, "obs_source_filter_set_position"))
return;
if (!obs_ptr_valid(filter, "obs_source_filter_set_position"))
return;

pthread_mutex_lock(&source->filter_mutex);
if (position < source->filters.num) {
size_t new_idx = source->filters.num - 1 - position;
size_t idx = da_find(source->filters, &filter, 0);
if (idx != DARRAY_INVALID && idx != new_idx) {
da_move_item(source->filters, idx, new_idx);
success = true;

reorder_filters(source);
}
}
pthread_mutex_unlock(&source->filter_mutex);

if (success)
obs_source_dosignal(source, NULL, "reorder_filters");
}

obs_data_t *obs_source_get_settings(const obs_source_t *source)
{
if (!obs_source_valid(source, "obs_source_get_settings"))
Expand Down
9 changes: 9 additions & 0 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,15 @@ EXPORT void obs_source_filter_set_order(obs_source_t *source,
obs_source_t *filter,
enum obs_order_movement movement);

/**
* Set the position of a specific filter,
* positions refered to obs_source_enum_filters
* so it goes backward to filters array indexes
*/
EXPORT void obs_source_filter_set_position(obs_source_t *source,
obs_source_t *filter,
size_t position);

/** Gets the settings string for a source */
EXPORT obs_data_t *obs_source_get_settings(const obs_source_t *source);

Expand Down