@@ -39,31 +39,21 @@ with this program. If not, see <https://www.gnu.org/licenses/>
3939extern bool loaded ;
4040
4141static const char * option_keys [] = {
42- "copy_properties" ,
43- "copy_filters" ,
44- "copy_audio_monitoring" ,
45- "copy_volume" ,
46- "copy_muted" ,
47- "copy_balance" ,
48- "copy_sync_offset" ,
49- "copy_audio_tracks" ,
42+ "copy_properties" , "copy_filters" , "copy_audio_monitoring" ,
43+ "copy_volume" , "copy_muted" , "copy_balance" ,
44+ "copy_sync_offset" , "copy_audio_tracks" ,
5045};
5146
5247static const char * option_labels [] = {
53- "Properties" ,
54- "Filters" ,
55- "Audio Monitoring Type" ,
56- "Volume" ,
57- "Muted/Unmuted" ,
58- "Stereo Balance" ,
59- "Sync Offset" ,
60- "Audio Tracks" ,
48+ "Properties" , "Filters" , "Audio Monitoring Type" ,
49+ "Volume" , "Muted/Unmuted" , "Stereo Balance" ,
50+ "Sync Offset" , "Audio Tracks" ,
6151};
6252
6353struct source_defaults {
6454 obs_source_t * source ; // the filter itself
6555 obs_source_t * parent_source ;
66- bool options [sizeof ( option_labels ) / sizeof ( bool )];
56+ bool options [ARRAY_SIZE ( option_keys )];
6757};
6858
6959static void enum_filters (obs_source_t * src , obs_source_t * filter , void * param )
@@ -77,15 +67,14 @@ static void enum_filters(obs_source_t *src, obs_source_t *filter, void *param)
7767 }
7868}
7969
80- static void log_changes (struct source_defaults * src ,
81- obs_source_t * dst )
70+ static void log_changes (struct source_defaults * src , obs_source_t * dst )
8271{
8372 struct dstr log = {0 };
8473 dstr_init (& log );
8574 dstr_cat (& log , "Applied " );
8675
8776 bool first_bool = true;
88- for (int i = 0 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
77+ for (unsigned long i = 0 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
8978 if (src -> options [i ]) {
9079 if (first_bool ) {
9180 dstr_cat (& log , option_labels [i ]);
@@ -96,12 +85,12 @@ static void log_changes(struct source_defaults *src,
9685 }
9786 }
9887 if (!first_bool ) {
99- dstr_catf (& log , " from '%s'" , obs_source_get_name (src -> parent_source ));
88+ dstr_catf (& log , " from '%s'" ,
89+ obs_source_get_name (src -> parent_source ));
10090 dstr_catf (& log , " to '%s'" , obs_source_get_name (dst ));
10191 blog (LOG_INFO , "%s" , log .array );
10292 }
10393 dstr_free (& log );
104- blog (LOG_DEBUG , "%s" , option_labels [3 ]);
10594}
10695
10796static void source_created_cb (void * data , calldata_t * cd )
@@ -112,19 +101,24 @@ static void source_created_cb(void *data, calldata_t *cd)
112101 struct source_defaults * src = data ;
113102 obs_source_t * dst = (obs_source_t * )calldata_ptr (cd , "source" );
114103 bool already_encountered ;
115- blog (LOG_DEBUG , "source_created: %s" , obs_source_get_name (dst ));
116104
117105 src -> parent_source = obs_filter_get_parent (src -> source );
118- blog (LOG_DEBUG , "Parent: %s" , obs_source_get_name (src -> parent_source ));
119106
107+ if (!src -> parent_source ) {
108+ blog (LOG_WARNING ,
109+ "Filter has no parent source, so new source was skipped." );
110+ return ;
111+ }
112+
113+ // should be same type
120114 if (strcmp (obs_source_get_id (src -> parent_source ),
121115 obs_source_get_id (dst )) != 0 ) {
122116 return ;
123117 }
124118 if (obs_source_get_type (dst ) != OBS_SOURCE_TYPE_INPUT ) {
125119 return ;
126120 }
127-
121+
128122 /* We have to distinguish between new sources and
129123 sources that are only recreated due to undo,
130124 otherwise settings will be copied over to old sources
@@ -138,18 +132,24 @@ static void source_created_cb(void *data, calldata_t *cd)
138132 already_encountered =
139133 obs_data_get_bool (dst_properties , ENCOUNTERED_KEY );
140134 if (!already_encountered ) {
141- const char * dst_properties_json = obs_data_get_json (dst_properties );
135+ const char * dst_properties_json =
136+ obs_data_get_json (dst_properties );
142137 already_encountered = strcmp (dst_properties_json , "{}" ) != 0 ;
143- }
144- if (!already_encountered && !src -> options [COPY_PROPERTIES ]) {
145- obs_data_set_bool (dst_properties , ENCOUNTERED_KEY , true);
146- obs_source_update (dst , dst_properties );
138+ // If the new source has non-default settings (not "{}")
139+ // consider it already encountered, but still write the
140+ // ENCOUNTERED_KEY, so that if the user resets its properties
141+ // to default, next callback execution will see it as already encountered.
142+ if (already_encountered || !src -> options [COPY_PROPERTIES ]) {
143+ obs_data_set_bool (dst_properties , ENCOUNTERED_KEY ,
144+ true);
145+ obs_source_update (dst , dst_properties );
146+ }
147147 }
148148 obs_data_release (dst_properties );
149+
149150 if (already_encountered )
150151 return ;
151152
152-
153153 if (src -> options [COPY_PROPERTIES ]) {
154154 obs_data_t * settings =
155155 obs_source_get_settings (src -> parent_source );
@@ -160,10 +160,12 @@ static void source_created_cb(void *data, calldata_t *cd)
160160 obs_source_update (dst , settings );
161161 obs_data_release (settings );
162162
163+ #ifndef NDEBUG
163164 dst_properties = obs_source_get_settings (dst );
164165 blog (LOG_DEBUG , "dst json2: %s" ,
165166 obs_data_get_json (dst_properties ));
166167 obs_data_release (dst_properties );
168+ #endif // !NDEBUG
167169 }
168170 if (src -> options [COPY_FILTERS ]) {
169171 obs_source_enum_filters (src -> parent_source , enum_filters , dst );
@@ -202,7 +204,7 @@ static void source_created_cb(void *data, calldata_t *cd)
202204static void source_defaults_update (void * data , obs_data_t * settings )
203205{
204206 struct source_defaults * src = data ;
205- for (int i = 0 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
207+ for (unsigned long i = 0 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
206208 src -> options [i ] = obs_data_get_bool (settings , option_keys [i ]);
207209 }
208210}
@@ -222,16 +224,16 @@ static obs_properties_t *source_defaults_properties(void *data)
222224 props , "description" ,
223225 "Tick the checkboxes for those that you want to be copied to newly created sources of the same type." ,
224226 OBS_TEXT_INFO );
225-
227+
226228 for (int i = 0 ; i < 2 ; i ++ ) {
227- obs_properties_add_bool (props , option_keys [i ], option_labels [i ]);
229+ obs_properties_add_bool (props , option_keys [i ],
230+ option_labels [i ]);
228231 }
229-
230232
231233 src -> parent_source = obs_filter_get_parent (src -> source );
232234 if (obs_source_get_output_flags (src -> parent_source ) &
233235 OBS_SOURCE_AUDIO ) {
234- for (int i = 2 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
236+ for (unsigned long i = 2 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
235237 obs_properties_add_bool (props , option_keys [i ],
236238 option_labels [i ]);
237239 }
@@ -242,7 +244,7 @@ static obs_properties_t *source_defaults_properties(void *data)
242244
243245static void source_defaults_get_defaults (obs_data_t * settings )
244246{
245- for (int i = 0 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
247+ for (unsigned long i = 0 ; i < ARRAY_SIZE (option_keys ); i ++ ) {
246248 obs_data_set_default_bool (settings , option_keys [i ], true);
247249 }
248250}
@@ -308,6 +310,9 @@ static void source_defaults_destroy(void *data)
308310 bfree (data );
309311}
310312
313+ /* OBS doesn't allow creating a filter that will show up for both
314+ video and audio filters, so we define two. */
315+
311316struct obs_source_info source_defaults_video_info = {
312317 .id = "source_defaults_video" ,
313318 .version = 1 ,
@@ -319,7 +324,6 @@ struct obs_source_info source_defaults_video_info = {
319324 .get_name = source_defaults_get_name ,
320325 .get_defaults = source_defaults_get_defaults ,
321326 .get_properties = source_defaults_properties ,
322- .icon_type = OBS_ICON_TYPE_UNKNOWN ,
323327};
324328
325329struct obs_source_info source_defaults_audio_info = {
@@ -333,5 +337,4 @@ struct obs_source_info source_defaults_audio_info = {
333337 .get_name = source_defaults_get_name ,
334338 .get_defaults = source_defaults_get_defaults ,
335339 .get_properties = source_defaults_properties ,
336- .icon_type = OBS_ICON_TYPE_UNKNOWN ,
337340};
0 commit comments