Skip to content

Commit

Permalink
chore(filtersettings): was able to build the flow to get all filterse…
Browse files Browse the repository at this point in the history
…ttings of the filters of a sceneitem and was also able to match them in a dynamicinput - still need to work on updating them and the UI for that
  • Loading branch information
Kounex committed Dec 1, 2023
1 parent aa3a619 commit 3ddb973
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 99 deletions.
5 changes: 5 additions & 0 deletions lib/shared/general/base/adaptive_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BaseAdaptiveTextField extends StatefulWidget {

final TargetPlatform? platform;

final void Function(String text)? onChanged;

const BaseAdaptiveTextField({
Key? key,
required this.controller,
Expand All @@ -81,6 +83,7 @@ class BaseAdaptiveTextField extends StatefulWidget {
this.suffixIcon,
this.errorPaddingAlways = false,
this.platform,
this.onChanged,
}) : super(key: key);

@override
Expand Down Expand Up @@ -154,6 +157,7 @@ class BaseAdaptiveTextFieldState extends State<BaseAdaptiveTextField> {
readOnly: this.widget.readOnly,
prefix: this.widget.prefix,
suffix: this.widget.suffix ?? this.widget.suffixIcon,
onChanged: this.widget.onChanged,
),
_ => Padding(
padding: const EdgeInsets.only(bottom: 4.0),
Expand Down Expand Up @@ -195,6 +199,7 @@ class BaseAdaptiveTextFieldState extends State<BaseAdaptiveTextField> {
obscureText: this.widget.obscureText,
enabled: this.widget.enabled,
readOnly: this.widget.readOnly,
onChanged: this.widget.onChanged,
),
),
},
Expand Down
73 changes: 72 additions & 1 deletion lib/stores/views/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:obs_blade/models/hotkey.dart';
import 'package:obs_blade/types/classes/api/input.dart';
import 'package:obs_blade/types/classes/api/transition.dart';
import 'package:obs_blade/types/classes/stream/batch_responses/base.dart';
import 'package:obs_blade/types/classes/stream/batch_responses/filter_default_settings.dart';
import 'package:obs_blade/types/classes/stream/batch_responses/filter_list.dart';
import 'package:obs_blade/types/classes/stream/batch_responses/inputs.dart';
import 'package:obs_blade/types/classes/stream/batch_responses/screenshot.dart';
Expand All @@ -24,6 +25,7 @@ import 'package:obs_blade/types/classes/stream/responses/get_profile_list.dart';
import 'package:obs_blade/types/classes/stream/responses/get_record_directory.dart';
import 'package:obs_blade/types/classes/stream/responses/get_replay_buffer_status.dart';
import 'package:obs_blade/types/classes/stream/responses/get_scene_collection_list.dart';
import 'package:obs_blade/types/classes/stream/responses/get_source_filter_default_settings.dart';
import 'package:obs_blade/types/classes/stream/responses/get_source_filter_list.dart';
import 'package:obs_blade/types/classes/stream/responses/get_special_inputs.dart';
import 'package:obs_blade/types/enums/request_batch_type.dart';
Expand All @@ -34,6 +36,7 @@ import 'package:obs_blade/types/extensions/int.dart';
import '../../models/enums/log_level.dart';
import '../../models/past_record_data.dart';
import '../../models/past_stream_data.dart';
import '../../types/classes/api/filter.dart';
import '../../types/classes/api/record_stats.dart';
import '../../types/classes/api/scene.dart';
import '../../types/classes/api/scene_item.dart';
Expand Down Expand Up @@ -1155,7 +1158,7 @@ abstract class _DashboardStore with Store {
GetReplayBufferStatusResponse(response.jsonRAW);

this.isReplayBufferActive =
getReplayBufferStatusResponse.isReplayBufferActive;
getReplayBufferStatusResponse.isReplayBufferActive ?? false;

break;
case RequestType.GetVirtualCamStatus:
Expand Down Expand Up @@ -1543,6 +1546,74 @@ abstract class _DashboardStore with Store {
filters: (filterObject['response'] as GetSourceFilterListResponse)
.filters);
}));

/// Now we need to also fetch the default settings since previously we
/// only got the ones who have non default values
Set<String> filterKinds = {};

for (final sceneItem in this.currentSceneItems) {
for (final filter in sceneItem.filters ?? <Filter>[]) {
filterKinds.add(filter.filterKind);
}
}

NetworkHelper.makeBatchRequest(
GetIt.instance<NetworkStore>().activeSession!.socket,
RequestBatchType.FilterDefaultSettings,
filterKinds
.map(
(filterKind) => RequestBatchObject(
RequestType.GetSourceFilterDefaultSettings, {
'filterKind': filterKind,
}),
)
.toList(),
);
break;
case RequestBatchType.FilterDefaultSettings:
FilterDefaultSettingsResponse filterDefaultSettingsResponse =
FilterDefaultSettingsResponse(batchResponse.jsonRAW);
final requestBatchObjects = NetworkHelper.getRequestBatchBodyForUUID(
filterDefaultSettingsResponse.uuid)!;

List<Map<String, dynamic>> filterDefaultSettings = [];

for (final getSourceFilterDefaultSettingsResponse
in filterDefaultSettingsResponse.defaultSettings) {
for (final requestBatchObject in requestBatchObjects) {
if (getSourceFilterDefaultSettingsResponse.uuid ==
requestBatchObject.uuid) {
filterDefaultSettings.add({
'filterKind': requestBatchObject.body!['filterKind'],
'response': getSourceFilterDefaultSettingsResponse,
});
}
}
}

this.currentSceneItems =
ObservableList.of(this.currentSceneItems.map((sceneItem) {
return sceneItem.copyWith(
filters: sceneItem.filters?.map((filter) {
late final GetSourceFilterDefaultSettingsResponse
getSourceFilterDefaultSettingsResponse;
try {
getSourceFilterDefaultSettingsResponse =
filterDefaultSettings.firstWhere((filterDefaultSetting) =>
filterDefaultSetting['filterKind'] ==
filter.filterKind)['response']
as GetSourceFilterDefaultSettingsResponse;

return filter.copyWith(
filterSettings:
getSourceFilterDefaultSettingsResponse.defaultFilterSettings
..addAll(filter.filterSettings),
);
} catch (_) {}
return filter;
}).toList());
}));

break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:obs_blade/types/classes/stream/batch_responses/base.dart';
import 'package:obs_blade/types/classes/stream/responses/get_source_filter_default_settings.dart';

class FilterDefaultSettingsResponse extends BaseBatchResponse {
FilterDefaultSettingsResponse(super.json);

Iterable<GetSourceFilterDefaultSettingsResponse> get defaultSettings =>
this.responses.map((response) =>
GetSourceFilterDefaultSettingsResponse(response.jsonRAW));
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ class GetReplayBufferStatusResponse extends BaseResponse {
GetReplayBufferStatusResponse(super.json);

/// Current recording status
bool get isReplayBufferActive => this.json['isReplayBufferActive'];
bool? get isReplayBufferActive => this.json['isReplayBufferActive'];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'base.dart';

/// Gets the default settings for a filter kind.
class GetSourceFilterDefaultSettingsResponse extends BaseResponse {
GetSourceFilterDefaultSettingsResponse(super.json);

/// Object of default settings for the filter kind
Map<String, dynamic> get defaultFilterSettings =>
this.json['defaultFilterSettings'];
}
14 changes: 13 additions & 1 deletion lib/types/enums/request_batch_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ enum RequestBatchType {
/// of these requests in one go and handle them at once!
///
/// RequestType.GetSourceFilterList
FilterList;
FilterList,

/// [RequestType.GetSourceFilterList] returns the settings for the filters,
/// but only those which are changed (not default values). So we need to also
/// get the default values because otherwise we don't know the values
/// at all
///
/// RequestType.GetSourceFilterDefaultSettings
FilterDefaultSettings;

List<RequestType> get requestTypes => {
RequestBatchType.Input: [
Expand All @@ -50,6 +58,9 @@ enum RequestBatchType {
RequestBatchType.FilterList: [
RequestType.GetSourceFilterList,
],
RequestBatchType.FilterDefaultSettings: [
RequestType.GetSourceFilterDefaultSettings,
],
}[this]!;

/// Indicates whether we need to persist this request to get the
Expand All @@ -62,5 +73,6 @@ enum RequestBatchType {
RequestBatchType.Stats: false,
RequestBatchType.Screenshot: false,
RequestBatchType.FilterList: true,
RequestBatchType.FilterDefaultSettings: true,
}[this]!;
}
13 changes: 13 additions & 0 deletions lib/types/enums/request_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ enum RequestType {
/// { 'sourceName': String } - Name of the source
GetSourceFilterList,

/// Gets the default settings for a filter kind.
///
/// { 'filterKind': String } - Filter kind to get the default settings for
GetSourceFilterDefaultSettings,

/**
* -----------------------------------------------------------------------
* Requests which serve as 'setter' - we will set specific parameters
Expand Down Expand Up @@ -284,4 +289,12 @@ enum RequestType {
/// {'filterName': String } - Name of the filter
/// {'filterEnabled': bool } - New enable state of the filter
SetSourceFilterEnabled,

/// Sets the settings of a source filter.
///
/// {'sourceName': String } - Name of the source the filter is on
/// {'filterName': String } - Name of the filter to set the settings of
/// {'filterSettings': Object } - Object of settings to apply
/// (Optional) {'overlay': bool } - True == apply the settings on top of existing ones, False == reset the input to its defaults, then apply settings.
SetSourceFilterSettings,
}

This file was deleted.

Loading

0 comments on commit 3ddb973

Please sign in to comment.