Skip to content

Commit

Permalink
Add midpoint to move source filter
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro committed May 24, 2024
1 parent 934270e commit f214a62
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ ChangeVisibility.HideStartEnd="Hide during movement"
ChangeVisibility.Toggle="Toggle"
ChangeVisibility.ToggleStart="Toggle at the start of movement"
ChangeVisibility.ToggleEnd="Toggle at the end of movement"
ChangeVisibility.ShowMidpoint="Show at the midpoint of movement"
ChangeVisibility.HideMidpoint="Hide at the midpoint of movement"
ChangeVisibility.ToggleMidpoint="Toggle at the midpoint of movement"
ChangeOrder="Order"
ChangeOrder.No="No Change"
ChangeOrder.StartRelative="Start Relative"
ChangeOrder.MidpointRelative="Midpoint Relative"
ChangeOrder.EndRelative="End Relative"
ChangeOrder.StartAbsolute="Start Absolute"
ChangeOrder.MidpointAbsolute="Midpoint Absolute"
ChangeOrder.EndAbsolute="End Absolute"
OrderPosition="Difference / Position"
MediaAction="Media"
Expand All @@ -182,8 +187,10 @@ AudioAction="Audio"
MuteAction="Mute"
MuteAction.None="None"
MuteAction.MuteStart="Mute at Start"
MuteAction.MuteMidpoint="Mute at Midpoint"
MuteAction.MuteEnd="Mute at End"
MuteAction.UnmuteStart="Unmute at Start"
MuteAction.UnmuteMidpoint="Unmute at Midpoint"
MuteAction.UnmuteEnd="Unmute at End"
MuteAction.MuteDuring="Mute During: Mute at Start and Unmute at End"
MuteAction.UnmuteDuring="Unmute During: Unmute at Start and Mute at End"
Expand Down
44 changes: 44 additions & 0 deletions move-source-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct move_source_info {
float audio_fade_from;
float audio_fade_to;
long long mute_action;
bool midpoint;
};

void move_source_scene_remove(void *data, calldata_t *call_data);
Expand Down Expand Up @@ -305,6 +306,7 @@ void move_source_start(struct move_source_info *move_source)

move_source->audio_fade_from = obs_source_get_volume(obs_sceneitem_get_source(move_source->scene_item));
}
move_source->midpoint = false;
}

bool move_source_start_button(obs_properties_t *props, obs_property_t *property, void *data)
Expand Down Expand Up @@ -955,13 +957,20 @@ static obs_properties_t *move_source_properties(void *data)
obs_property_list_add_int(p, obs_module_text("ChangeVisibility.Toggle"), CHANGE_VISIBILITY_TOGGLE);
obs_property_list_add_int(p, obs_module_text("ChangeVisibility.ToggleStart"), CHANGE_VISIBILITY_TOGGLE_START);
obs_property_list_add_int(p, obs_module_text("ChangeVisibility.ToggleEnd"), CHANGE_VISIBILITY_TOGGLE_END);
obs_property_list_add_int(p, obs_module_text("ChangeVisibility.ShowMidpoint"), CHANGE_VISIBILITY_SHOW_MIDPOINT);
obs_property_list_add_int(p, obs_module_text("ChangeVisibility.HideMidpoint"), CHANGE_VISIBILITY_HIDE_MIDPOINT);
obs_property_list_add_int(p, obs_module_text("ChangeVisibility.ToggleMidpoint"), CHANGE_VISIBILITY_TOGGLE_MIDPOINT);

p = obs_properties_add_list(group, S_CHANGE_ORDER, obs_module_text("ChangeOrder"), OBS_COMBO_TYPE_LIST,
OBS_COMBO_FORMAT_INT);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.No"), CHANGE_ORDER_NONE);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.StartAbsolute"), CHANGE_ORDER_START | CHANGE_ORDER_ABSOLUTE);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.MidpointAbsolute"),
CHANGE_ORDER_MIDPOINT | CHANGE_ORDER_ABSOLUTE);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.EndAbsolute"), CHANGE_ORDER_END | CHANGE_ORDER_ABSOLUTE);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.StartRelative"), CHANGE_ORDER_START | CHANGE_ORDER_RELATIVE);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.MidpointRelative"),
CHANGE_ORDER_MIDPOINT | CHANGE_ORDER_RELATIVE);
obs_property_list_add_int(p, obs_module_text("ChangeOrder.EndRelative"), CHANGE_ORDER_END | CHANGE_ORDER_RELATIVE);
p = obs_properties_add_int(group, S_ORDER_POSITION, obs_module_text("OrderPosition"), -1000, 1000, 1);

Expand Down Expand Up @@ -998,8 +1007,10 @@ static obs_properties_t *move_source_properties(void *data)

obs_property_list_add_int(p, obs_module_text("MuteAction.None"), MUTE_ACTION_NONE);
obs_property_list_add_int(p, obs_module_text("MuteAction.MuteStart"), MUTE_ACTION_MUTE_START);
obs_property_list_add_int(p, obs_module_text("MuteAction.MuteMidpoint"), MUTE_ACTION_MUTE_MIDPOINT);
obs_property_list_add_int(p, obs_module_text("MuteAction.MuteEnd"), MUTE_ACTION_MUTE_END);
obs_property_list_add_int(p, obs_module_text("MuteAction.UnmuteStart"), MUTE_ACTION_UNMUTE_START);
obs_property_list_add_int(p, obs_module_text("MuteAction.UnmuteMidpoint"), MUTE_ACTION_UNMUTE_MIDPOINT);
obs_property_list_add_int(p, obs_module_text("MuteAction.UnmuteEnd"), MUTE_ACTION_UNMUTE_END);
obs_property_list_add_int(p, obs_module_text("MuteAction.MuteDuring"), MUTE_ACTION_MUTE_DURING);
obs_property_list_add_int(p, obs_module_text("MuteAction.UnmuteDuring"), MUTE_ACTION_UNMUTE_DURING);
Expand Down Expand Up @@ -1157,6 +1168,39 @@ void move_source_tick(void *data, float seconds)
return;
}

if (!move_source->midpoint && t >= 0.5) {
move_source->midpoint = true;
if (move_source->change_visibility == CHANGE_VISIBILITY_SHOW_MIDPOINT) {
obs_sceneitem_set_visible(move_source->scene_item, true);
} else if (move_source->change_visibility == CHANGE_VISIBILITY_HIDE_MIDPOINT) {
obs_sceneitem_set_visible(move_source->scene_item, false);
} else if (move_source->change_visibility == CHANGE_VISIBILITY_TOGGLE_MIDPOINT) {
obs_sceneitem_set_visible(move_source->scene_item, !obs_sceneitem_visible(move_source->scene_item));
}
if ((move_source->change_order & CHANGE_ORDER_MIDPOINT) != 0) {
if ((move_source->change_order & CHANGE_ORDER_RELATIVE) != 0 && move_source->order_position) {
if (move_source->order_position > 0) {
for (int i = 0; i < move_source->order_position; i++) {
obs_sceneitem_set_order(move_source->scene_item, OBS_ORDER_MOVE_UP);
}
} else if (move_source->order_position < 0) {
for (int i = 0; i > move_source->order_position; i--) {
obs_sceneitem_set_order(move_source->scene_item, OBS_ORDER_MOVE_DOWN);
}
}
} else if ((move_source->change_order & CHANGE_ORDER_ABSOLUTE) != 0) {
obs_sceneitem_set_order_position(move_source->scene_item, (int)move_source->order_position);
}
}
if (move_source->mute_action == MUTE_ACTION_MUTE_MIDPOINT &&
!obs_source_muted(obs_sceneitem_get_source(move_source->scene_item))) {
obs_source_set_muted(obs_sceneitem_get_source(move_source->scene_item), true);
} else if (move_source->mute_action == MUTE_ACTION_UNMUTE_MIDPOINT &&
obs_source_muted(obs_sceneitem_get_source(move_source->scene_item))) {
obs_source_set_muted(obs_sceneitem_get_source(move_source->scene_item), false);
}
}

float ot = t;
if (t > 1.0f)
ot = 1.0f;
Expand Down
6 changes: 6 additions & 0 deletions move-transition.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,16 @@
#define CHANGE_VISIBILITY_TOGGLE_END 7
#define CHANGE_VISIBILITY_SHOW_START_END 8
#define CHANGE_VISIBILITY_HIDE_START_END 9
#define CHANGE_VISIBILITY_SHOW_MIDPOINT 10
#define CHANGE_VISIBILITY_HIDE_MIDPOINT 11
#define CHANGE_VISIBILITY_TOGGLE_MIDPOINT 12

#define CHANGE_ORDER_NONE 0
#define CHANGE_ORDER_RELATIVE (1 << 0)
#define CHANGE_ORDER_ABSOLUTE (1 << 1)
#define CHANGE_ORDER_START (1 << 2)
#define CHANGE_ORDER_END (1 << 3)
#define CHANGE_ORDER_MIDPOINT (1 << 4)

#define MEDIA_ACTION_NONE 0
#define MEDIA_ACTION_PLAY 1
Expand All @@ -221,6 +225,8 @@
#define MUTE_ACTION_UNMUTE_END 4
#define MUTE_ACTION_MUTE_DURING 5
#define MUTE_ACTION_UNMUTE_DURING 6
#define MUTE_ACTION_MUTE_MIDPOINT 7
#define MUTE_ACTION_UNMUTE_MIDPOINT 8

#define MOVE_VALUE_TYPE_SINGLE_SETTING 0
#define MOVE_VALUE_TYPE_SETTINGS 1
Expand Down

0 comments on commit f214a62

Please sign in to comment.