From c1abd89aab8102f768402a7f40499b8020758225 Mon Sep 17 00:00:00 2001 From: Agash Date: Tue, 25 Aug 2026 23:21:12 +0200 Subject: [PATCH 01/12] feat(core): typed batch references grouped by protocol category Batch requests are reached through the protocol's own categories, so b.Scenes.GetSceneList rather than one flat list of 147 methods, and each returns a BatchRef carrying its response type. Results are read with results.Get(reference), which restates neither the position nor the type and stays correct when a request type appears several times in one batch. Replaces the chainable positional methods; capturing a reference needs a statement per request anyway. Count stays at one method per request. LOGGEN036 is fixed by typing the generated log parameters rather than suppressing the diagnostic. --- .../Generation/Emitter.BatchBuilder.cs | 222 ++- ObsWebSocket.Core/BatchRef.cs | 105 ++ .../Client/ObsBatchBuilder.Requests.g.cs | 1275 ++++++++++------- ObsWebSocket.Core/ObsBatchBuilder.cs | 16 + ObsWebSocket.Core/ObsWebSocket.Core.csproj | 11 - .../ObsWebSocketClient.Helper.Convenience.cs | 33 + ObsWebSocket.Core/ObsWebSocketClient.cs | 8 +- ObsWebSocket.Core/ObsWebSocketClientLog.cs | 130 +- .../Serialization/SerializerLog.cs | 25 +- ObsWebSocket.Example/Worker.cs | 134 +- .../BatchBuilderAndEnumTests.cs | 44 +- ObsWebSocket.Tests/BatchResultTests.cs | 4 +- ObsWebSocket.Tests/ReadmeCompileCheck.cs | 57 +- README.md | 68 +- 14 files changed, 1280 insertions(+), 852 deletions(-) create mode 100644 ObsWebSocket.Core/BatchRef.cs diff --git a/ObsWebSocket.Codegen.Tasks/Generation/Emitter.BatchBuilder.cs b/ObsWebSocket.Codegen.Tasks/Generation/Emitter.BatchBuilder.cs index fd613c1..f2e91df 100644 --- a/ObsWebSocket.Codegen.Tasks/Generation/Emitter.BatchBuilder.cs +++ b/ObsWebSocket.Codegen.Tasks/Generation/Emitter.BatchBuilder.cs @@ -6,13 +6,14 @@ namespace ObsWebSocket.Codegen.Tasks.Generation; /// -/// Emitter logic for the typed batch builder, which pairs each request type string with the -/// request data record the protocol defines for it. +/// Emitter logic for the typed batch builder. Requests are grouped by protocol category, and each +/// returns a reference carrying its response type so a result can be read without restating +/// either its position or its type. /// internal static partial class Emitter { /// - /// Generates one builder method per protocol request. + /// Generates the category groups and their request methods. /// /// The source production context. /// The parsed protocol definition. @@ -26,93 +27,172 @@ ProtocolDefinition protocol return; } - StringBuilder builder = BuildSourceHeader("// Helper: typed batch builder methods"); + StringBuilder builder = BuildSourceHeader("// Helper: typed batch builder groups"); builder.AppendLine("using System;"); builder.AppendLine($"using {GeneratedRequestsNamespace};"); + builder.AppendLine($"using {GeneratedResponsesNamespace};"); builder.AppendLine(); builder.AppendLine($"namespace {ExtensionsNamespace};"); builder.AppendLine(); + + List<(string Category, string GroupName)> groups = []; + foreach ( + IGrouping group in protocol + .Requests.GroupBy(r => r.Category ?? "general", StringComparer.OrdinalIgnoreCase) + .OrderBy(g => g.Key, StringComparer.Ordinal) + ) + { + string groupName = ToGroupName(group.Key); + groups.Add((group.Key, groupName)); + + builder.AppendLine("/// "); + builder.AppendLine( + $"/// Batch requests in the {System.Security.SecurityElement.Escape(group.Key)} category." + ); + builder.AppendLine("/// "); + builder.AppendLine("/// The batch being built."); + builder.AppendLine( + $"public readonly struct {groupName}BatchGroup(ObsBatchBuilder builder)" + ); + builder.AppendLine("{"); + + foreach (RequestDefinition request in group) + { + EmitBatchRequestMethod(context, builder, request); + } + + builder.AppendLine("}"); + builder.AppendLine(); + } + builder.AppendLine("public sealed partial class ObsBatchBuilder"); builder.AppendLine("{"); + foreach ((string category, string groupName) in groups) + { + builder.AppendLine(" /// "); + builder.AppendLine( + $" /// Requests in the {System.Security.SecurityElement.Escape(category)} category." + ); + builder.AppendLine(" /// "); + builder.AppendLine($" public {groupName}BatchGroup {groupName} => new(this);"); + builder.AppendLine(); + } + + builder.AppendLine("}"); + + context.AddSource( + "ObsBatchBuilder.Requests.g.cs", + SourceText.From(builder.ToString(), Encoding.UTF8) + ); + } - foreach (RequestDefinition request in protocol.Requests) + /// + /// Emits one request method, returning a reference to its eventual result. + /// + private static void EmitBatchRequestMethod( + SourceProductionContext context, + StringBuilder builder, + RequestDefinition request + ) + { + try { - try + string requestType = request.RequestType; + string methodName = SanitizeIdentifier(requestType); + if (string.IsNullOrEmpty(methodName)) { - string requestType = request.RequestType; - string methodName = SanitizeIdentifier(requestType); - if (string.IsNullOrEmpty(methodName)) - { - continue; - } + return; + } - bool hasData = request.RequestFields?.Count > 0; + bool hasData = request.RequestFields?.Count > 0; + bool hasResponse = request.ResponseFields?.Count > 0; - builder.AppendLine(" /// "); + string returnType = hasResponse + ? $"BatchRef<{GeneratedResponsesNamespace}.{methodName}ResponseData>" + : "BatchRef"; + + builder.AppendLine(" /// "); + builder.AppendLine($" /// Adds a {requestType} request to the batch."); + if (!string.IsNullOrWhiteSpace(request.Description)) + { builder.AppendLine( - $" /// Appends a {requestType} request to the batch." + $" /// {FlattenBatchDescription(request.Description)}" ); - if (!string.IsNullOrWhiteSpace(request.Description)) - { - builder.AppendLine( - $" /// {FlattenDescription(request.Description)}" - ); - } - - builder.AppendLine(" /// "); - builder.AppendLine(" /// The same builder, for chaining."); - if (request.Deprecated) - { - builder.AppendLine( - $" [System.Obsolete(\"Deprecated in OBS Websocket version {request.InitialVersion}\")]" - ); - } - - if (hasData) - { - string dataTypeName = - $"{GeneratedRequestsNamespace}.{methodName}RequestData"; - builder.AppendLine( - $" /// The payload for this request." - ); - builder.AppendLine( - $" public ObsBatchBuilder {methodName}({dataTypeName} requestData)" - ); - builder.AppendLine(" {"); - builder.AppendLine(" ArgumentNullException.ThrowIfNull(requestData);"); - builder.AppendLine( - $" return Add(\"{requestType}\", requestData);" - ); - builder.AppendLine(" }"); - } - else - { - builder.AppendLine( - $" public ObsBatchBuilder {methodName}() => Add(\"{requestType}\", null);" - ); - } - - builder.AppendLine(); } - catch (Exception ex) + + builder.AppendLine(" /// "); + if (hasData) { - context.ReportDiagnostic( - Diagnostic.Create( - Diagnostics.IdentifierGenerationError, - Location.None, - request.RequestType, - $"Generating batch builder method for {request.RequestType}", - ex.Message - ) + builder.AppendLine( + " /// The payload for this request." ); } - } - builder.AppendLine("}"); + builder.AppendLine( + " /// A reference used to read this request's result." + ); + if (request.Deprecated) + { + builder.AppendLine( + $" [System.Obsolete(\"Request '{requestType}' is deprecated since OBS Websocket version {request.InitialVersion}\")]" + ); + } - context.AddSource( - "ObsBatchBuilder.Requests.g.cs", - SourceText.From(builder.ToString(), Encoding.UTF8) - ); + if (hasData) + { + string dataTypeName = $"{GeneratedRequestsNamespace}.{methodName}RequestData"; + builder.AppendLine( + $" public {returnType} {methodName}({dataTypeName} requestData)" + ); + builder.AppendLine(" {"); + builder.AppendLine(" ArgumentNullException.ThrowIfNull(requestData);"); + builder.AppendLine( + $" return new(builder.AddRequest(\"{requestType}\", requestData));" + ); + builder.AppendLine(" }"); + } + else + { + builder.AppendLine( + $" public {returnType} {methodName}() => new(builder.AddRequest(\"{requestType}\", null));" + ); + } + + builder.AppendLine(); + } + catch (Exception ex) + { + context.ReportDiagnostic( + Diagnostic.Create( + Diagnostics.IdentifierGenerationError, + Location.None, + request.RequestType, + $"Generating batch builder method for {request.RequestType}", + ex.Message + ) + ); + } } + + /// + /// Converts a protocol category such as scene items into a PascalCase group name. + /// + private static string ToGroupName(string category) => + string.Concat( + category + .Split([' ', '-', '_'], StringSplitOptions.RemoveEmptyEntries) + .Select(part => + part.Length == 0 + ? part + : char.ToUpperInvariant(part[0]) + part.Substring(1).ToLowerInvariant() + ) + ); + + /// + /// Flattens a protocol description onto a single line for a doc comment. + /// + private static string FlattenBatchDescription(string description) => + System.Security.SecurityElement.Escape( + System.Text.RegularExpressions.Regex.Replace(description, @"\s+", " ").Trim() + ) ?? string.Empty; } diff --git a/ObsWebSocket.Core/BatchRef.cs b/ObsWebSocket.Core/BatchRef.cs new file mode 100644 index 0000000..39f60b4 --- /dev/null +++ b/ObsWebSocket.Core/BatchRef.cs @@ -0,0 +1,105 @@ +using ObsWebSocket.Core.Protocol; + +namespace ObsWebSocket.Core; + +/// +/// Identifies a request within a batch, without a response type. +/// +/// Position of the request in the batch. +public readonly record struct BatchRef(int Index); + +/// +/// Identifies a request within a batch, carrying the type of its response. +/// +/// The response record this request produces. +/// Position of the request in the batch. +public readonly record struct BatchRef(int Index) + where TResponse : class +{ + /// Drops the response type, leaving a plain reference. + /// The reference to convert. + public static implicit operator BatchRef(BatchRef reference) => + new(reference.Index); + + /// Drops the response type, leaving a plain reference. + public BatchRef ToBatchRef() => new(Index); +} + +/// +/// The results of a batch call, addressable by the references the builder handed out. +/// +/// +/// Indexing by a ties a result to the request that produced it +/// and to that request's response type, so neither the position nor the type has to be restated +/// at the call site. +/// +public sealed class BatchResults +{ + private readonly IReadOnlyList> _results; + + /// Initializes results from the payloads OBS returned. + /// The results, in submission order. + public BatchResults(IReadOnlyList> results) + { + ArgumentNullException.ThrowIfNull(results); + _results = results; + } + + /// Number of results returned. + /// + /// Fewer than the number of requests sent when OBS stopped early on a failure. + /// + public int Count => _results.Count; + + /// The raw results, in submission order. + public IReadOnlyList> Raw => _results; + + /// Gets the result for a request by position. + /// Position of the request in the batch. + public RequestResponsePayload this[int index] => _results[index]; + + /// Gets the result for a request that returns no data. + /// The reference the builder returned. + /// Thrown if the batch stopped before this request ran. + public RequestResponsePayload this[BatchRef reference] => Require(reference.Index); + + /// Gets the typed response for a request. + /// The response record for that request, inferred from the reference. + /// The reference the builder returned. + /// Thrown if the batch stopped before this request ran. + /// Thrown if OBS rejected that request. + public TResponse Get(BatchRef reference) + where TResponse : class => Require(reference.Index).GetRequiredData(); + + /// + /// Reads a typed response, reporting whether it was available rather than throwing. + /// + /// The response record for that request. + /// The reference the builder returned. + /// The response data, when one was returned. + public bool TryGet(BatchRef reference, out TResponse? data) + where TResponse : class + { + if (reference.Index >= _results.Count) + { + data = null; + return false; + } + + return _results[reference.Index].TryGetData(out data); + } + + /// Returns whether every request in the batch succeeded. + public bool AllSucceeded() => _results.All(r => r.RequestStatus.Result); + + /// Returns the results OBS reported as failed. + public IEnumerable> GetFailures() => + _results.Where(r => !r.RequestStatus.Result); + + private RequestResponsePayload Require(int index) => + index < _results.Count + ? _results[index] + : throw new ObsWebSocketException( + $"The batch returned {_results.Count} result(s), so the request at position {index} never ran. This happens when haltOnFailure stopped the batch early." + ); +} diff --git a/ObsWebSocket.Core/Generated/Client/ObsBatchBuilder.Requests.g.cs b/ObsWebSocket.Core/Generated/Client/ObsBatchBuilder.Requests.g.cs index d311df2..baf345d 100644 --- a/ObsWebSocket.Core/Generated/Client/ObsBatchBuilder.Requests.g.cs +++ b/ObsWebSocket.Core/Generated/Client/ObsBatchBuilder.Requests.g.cs @@ -1,1556 +1,1739 @@ // -// Helper: typed batch builder methods +// Helper: typed batch builder groups #nullable enable using System; using ObsWebSocket.Core.Protocol.Requests; +using ObsWebSocket.Core.Protocol.Responses; namespace ObsWebSocket.Core; -public sealed partial class ObsBatchBuilder +/// +/// Batch requests in the canvases category. +/// +/// The batch being built. +public readonly struct CanvasesBatchGroup(ObsBatchBuilder builder) { /// - /// Appends a GetCanvasList request to the batch. + /// Adds a GetCanvasList request to the batch. /// Gets an array of canvases in OBS. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetCanvasList() => Add("GetCanvasList", null); + /// A reference used to read this request's result. + public BatchRef GetCanvasList() => new(builder.AddRequest("GetCanvasList", null)); + +} +/// +/// Batch requests in the config category. +/// +/// The batch being built. +public readonly struct ConfigBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetPersistentData request to the batch. + /// Adds a GetPersistentData request to the batch. /// Gets the value of a "slot" from the selected persistent data realm. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetPersistentData(ObsWebSocket.Core.Protocol.Requests.GetPersistentDataRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetPersistentData(ObsWebSocket.Core.Protocol.Requests.GetPersistentDataRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetPersistentData", requestData); + return new(builder.AddRequest("GetPersistentData", requestData)); } /// - /// Appends a SetPersistentData request to the batch. + /// Adds a SetPersistentData request to the batch. /// Sets the value of a "slot" from the selected persistent data realm. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetPersistentData(ObsWebSocket.Core.Protocol.Requests.SetPersistentDataRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetPersistentData(ObsWebSocket.Core.Protocol.Requests.SetPersistentDataRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetPersistentData", requestData); + return new(builder.AddRequest("SetPersistentData", requestData)); } /// - /// Appends a GetSceneCollectionList request to the batch. + /// Adds a GetSceneCollectionList request to the batch. /// Gets an array of all scene collections /// - /// The same builder, for chaining. - public ObsBatchBuilder GetSceneCollectionList() => Add("GetSceneCollectionList", null); + /// A reference used to read this request's result. + public BatchRef GetSceneCollectionList() => new(builder.AddRequest("GetSceneCollectionList", null)); /// - /// Appends a SetCurrentSceneCollection request to the batch. + /// Adds a SetCurrentSceneCollection request to the batch. /// Switches to a scene collection. Note: This will block until the collection has finished changing. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentSceneCollection(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneCollectionRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentSceneCollection(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneCollectionRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentSceneCollection", requestData); + return new(builder.AddRequest("SetCurrentSceneCollection", requestData)); } /// - /// Appends a CreateSceneCollection request to the batch. + /// Adds a CreateSceneCollection request to the batch. /// Creates a new scene collection, switching to it in the process. Note: This will block until the collection has finished changing. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateSceneCollection(ObsWebSocket.Core.Protocol.Requests.CreateSceneCollectionRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateSceneCollection(ObsWebSocket.Core.Protocol.Requests.CreateSceneCollectionRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateSceneCollection", requestData); + return new(builder.AddRequest("CreateSceneCollection", requestData)); } /// - /// Appends a GetProfileList request to the batch. + /// Adds a GetProfileList request to the batch. /// Gets an array of all profiles /// - /// The same builder, for chaining. - public ObsBatchBuilder GetProfileList() => Add("GetProfileList", null); + /// A reference used to read this request's result. + public BatchRef GetProfileList() => new(builder.AddRequest("GetProfileList", null)); /// - /// Appends a SetCurrentProfile request to the batch. + /// Adds a SetCurrentProfile request to the batch. /// Switches to a profile. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentProfile(ObsWebSocket.Core.Protocol.Requests.SetCurrentProfileRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentProfile(ObsWebSocket.Core.Protocol.Requests.SetCurrentProfileRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentProfile", requestData); + return new(builder.AddRequest("SetCurrentProfile", requestData)); } /// - /// Appends a CreateProfile request to the batch. + /// Adds a CreateProfile request to the batch. /// Creates a new profile, switching to it in the process /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateProfile(ObsWebSocket.Core.Protocol.Requests.CreateProfileRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateProfile(ObsWebSocket.Core.Protocol.Requests.CreateProfileRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateProfile", requestData); + return new(builder.AddRequest("CreateProfile", requestData)); } /// - /// Appends a RemoveProfile request to the batch. + /// Adds a RemoveProfile request to the batch. /// Removes a profile. If the current profile is chosen, it will change to a different profile first. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder RemoveProfile(ObsWebSocket.Core.Protocol.Requests.RemoveProfileRequestData requestData) + /// A reference used to read this request's result. + public BatchRef RemoveProfile(ObsWebSocket.Core.Protocol.Requests.RemoveProfileRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("RemoveProfile", requestData); + return new(builder.AddRequest("RemoveProfile", requestData)); } /// - /// Appends a GetProfileParameter request to the batch. + /// Adds a GetProfileParameter request to the batch. /// Gets a parameter from the current profile's configuration. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetProfileParameter(ObsWebSocket.Core.Protocol.Requests.GetProfileParameterRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetProfileParameter(ObsWebSocket.Core.Protocol.Requests.GetProfileParameterRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetProfileParameter", requestData); + return new(builder.AddRequest("GetProfileParameter", requestData)); } /// - /// Appends a SetProfileParameter request to the batch. + /// Adds a SetProfileParameter request to the batch. /// Sets the value of a parameter in the current profile's configuration. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetProfileParameter(ObsWebSocket.Core.Protocol.Requests.SetProfileParameterRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetProfileParameter(ObsWebSocket.Core.Protocol.Requests.SetProfileParameterRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetProfileParameter", requestData); + return new(builder.AddRequest("SetProfileParameter", requestData)); } /// - /// Appends a GetVideoSettings request to the batch. + /// Adds a GetVideoSettings request to the batch. /// Gets the current video settings. Note: To get the true FPS value, divide the FPS numerator by the FPS denominator. Example: `60000/1001` /// - /// The same builder, for chaining. - public ObsBatchBuilder GetVideoSettings() => Add("GetVideoSettings", null); + /// A reference used to read this request's result. + public BatchRef GetVideoSettings() => new(builder.AddRequest("GetVideoSettings", null)); /// - /// Appends a SetVideoSettings request to the batch. + /// Adds a SetVideoSettings request to the batch. /// Sets the current video settings. Note: Fields must be specified in pairs. For example, you cannot set only `baseWidth` without needing to specify `baseHeight`. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetVideoSettings(ObsWebSocket.Core.Protocol.Requests.SetVideoSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetVideoSettings(ObsWebSocket.Core.Protocol.Requests.SetVideoSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetVideoSettings", requestData); + return new(builder.AddRequest("SetVideoSettings", requestData)); } /// - /// Appends a GetStreamServiceSettings request to the batch. + /// Adds a GetStreamServiceSettings request to the batch. /// Gets the current stream service settings (stream destination). /// - /// The same builder, for chaining. - public ObsBatchBuilder GetStreamServiceSettings() => Add("GetStreamServiceSettings", null); + /// A reference used to read this request's result. + public BatchRef GetStreamServiceSettings() => new(builder.AddRequest("GetStreamServiceSettings", null)); /// - /// Appends a SetStreamServiceSettings request to the batch. + /// Adds a SetStreamServiceSettings request to the batch. /// Sets the current stream service settings (stream destination). Note: Simple RTMP settings can be set with type `rtmp_custom` and the settings fields `server` and `key`. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetStreamServiceSettings(ObsWebSocket.Core.Protocol.Requests.SetStreamServiceSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetStreamServiceSettings(ObsWebSocket.Core.Protocol.Requests.SetStreamServiceSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetStreamServiceSettings", requestData); + return new(builder.AddRequest("SetStreamServiceSettings", requestData)); } /// - /// Appends a GetRecordDirectory request to the batch. + /// Adds a GetRecordDirectory request to the batch. /// Gets the current directory that the record output is set to. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetRecordDirectory() => Add("GetRecordDirectory", null); + /// A reference used to read this request's result. + public BatchRef GetRecordDirectory() => new(builder.AddRequest("GetRecordDirectory", null)); /// - /// Appends a SetRecordDirectory request to the batch. + /// Adds a SetRecordDirectory request to the batch. /// Sets the current directory that the record output writes files to. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetRecordDirectory(ObsWebSocket.Core.Protocol.Requests.SetRecordDirectoryRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetRecordDirectory(ObsWebSocket.Core.Protocol.Requests.SetRecordDirectoryRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetRecordDirectory", requestData); + return new(builder.AddRequest("SetRecordDirectory", requestData)); } +} + +/// +/// Batch requests in the filters category. +/// +/// The batch being built. +public readonly struct FiltersBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetSourceFilterKindList request to the batch. + /// Adds a GetSourceFilterKindList request to the batch. /// Gets an array of all available source filter kinds. Similar to `GetInputKindList` /// - /// The same builder, for chaining. - public ObsBatchBuilder GetSourceFilterKindList() => Add("GetSourceFilterKindList", null); + /// A reference used to read this request's result. + public BatchRef GetSourceFilterKindList() => new(builder.AddRequest("GetSourceFilterKindList", null)); /// - /// Appends a GetSourceFilterList request to the batch. + /// Adds a GetSourceFilterList request to the batch. /// Gets an array of all of a source's filters. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSourceFilterList(ObsWebSocket.Core.Protocol.Requests.GetSourceFilterListRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSourceFilterList(ObsWebSocket.Core.Protocol.Requests.GetSourceFilterListRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSourceFilterList", requestData); + return new(builder.AddRequest("GetSourceFilterList", requestData)); } /// - /// Appends a GetSourceFilterDefaultSettings request to the batch. + /// Adds a GetSourceFilterDefaultSettings request to the batch. /// Gets the default settings for a filter kind. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSourceFilterDefaultSettings(ObsWebSocket.Core.Protocol.Requests.GetSourceFilterDefaultSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSourceFilterDefaultSettings(ObsWebSocket.Core.Protocol.Requests.GetSourceFilterDefaultSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSourceFilterDefaultSettings", requestData); + return new(builder.AddRequest("GetSourceFilterDefaultSettings", requestData)); } /// - /// Appends a CreateSourceFilter request to the batch. + /// Adds a CreateSourceFilter request to the batch. /// Creates a new filter, adding it to the specified source. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateSourceFilter(ObsWebSocket.Core.Protocol.Requests.CreateSourceFilterRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateSourceFilter(ObsWebSocket.Core.Protocol.Requests.CreateSourceFilterRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateSourceFilter", requestData); + return new(builder.AddRequest("CreateSourceFilter", requestData)); } /// - /// Appends a RemoveSourceFilter request to the batch. + /// Adds a RemoveSourceFilter request to the batch. /// Removes a filter from a source. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder RemoveSourceFilter(ObsWebSocket.Core.Protocol.Requests.RemoveSourceFilterRequestData requestData) + /// A reference used to read this request's result. + public BatchRef RemoveSourceFilter(ObsWebSocket.Core.Protocol.Requests.RemoveSourceFilterRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("RemoveSourceFilter", requestData); + return new(builder.AddRequest("RemoveSourceFilter", requestData)); } /// - /// Appends a SetSourceFilterName request to the batch. + /// Adds a SetSourceFilterName request to the batch. /// Sets the name of a source filter (rename). /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSourceFilterName(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterNameRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSourceFilterName(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterNameRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSourceFilterName", requestData); + return new(builder.AddRequest("SetSourceFilterName", requestData)); } /// - /// Appends a GetSourceFilter request to the batch. + /// Adds a GetSourceFilter request to the batch. /// Gets the info for a specific source filter. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSourceFilter(ObsWebSocket.Core.Protocol.Requests.GetSourceFilterRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSourceFilter(ObsWebSocket.Core.Protocol.Requests.GetSourceFilterRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSourceFilter", requestData); + return new(builder.AddRequest("GetSourceFilter", requestData)); } /// - /// Appends a SetSourceFilterIndex request to the batch. + /// Adds a SetSourceFilterIndex request to the batch. /// Sets the index position of a filter on a source. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSourceFilterIndex(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterIndexRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSourceFilterIndex(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterIndexRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSourceFilterIndex", requestData); + return new(builder.AddRequest("SetSourceFilterIndex", requestData)); } /// - /// Appends a SetSourceFilterSettings request to the batch. + /// Adds a SetSourceFilterSettings request to the batch. /// Sets the settings of a source filter. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSourceFilterSettings(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSourceFilterSettings(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSourceFilterSettings", requestData); + return new(builder.AddRequest("SetSourceFilterSettings", requestData)); } /// - /// Appends a SetSourceFilterEnabled request to the batch. + /// Adds a SetSourceFilterEnabled request to the batch. /// Sets the enable state of a source filter. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSourceFilterEnabled(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterEnabledRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSourceFilterEnabled(ObsWebSocket.Core.Protocol.Requests.SetSourceFilterEnabledRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSourceFilterEnabled", requestData); + return new(builder.AddRequest("SetSourceFilterEnabled", requestData)); } +} + +/// +/// Batch requests in the general category. +/// +/// The batch being built. +public readonly struct GeneralBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetVersion request to the batch. + /// Adds a GetVersion request to the batch. /// Gets data about the current plugin and RPC version. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetVersion() => Add("GetVersion", null); + /// A reference used to read this request's result. + public BatchRef GetVersion() => new(builder.AddRequest("GetVersion", null)); /// - /// Appends a GetStats request to the batch. + /// Adds a GetStats request to the batch. /// Gets statistics about OBS, obs-websocket, and the current session. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetStats() => Add("GetStats", null); + /// A reference used to read this request's result. + public BatchRef GetStats() => new(builder.AddRequest("GetStats", null)); /// - /// Appends a BroadcastCustomEvent request to the batch. + /// Adds a BroadcastCustomEvent request to the batch. /// Broadcasts a `CustomEvent` to all WebSocket clients. Receivers are clients which are identified and subscribed. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder BroadcastCustomEvent(ObsWebSocket.Core.Protocol.Requests.BroadcastCustomEventRequestData requestData) + /// A reference used to read this request's result. + public BatchRef BroadcastCustomEvent(ObsWebSocket.Core.Protocol.Requests.BroadcastCustomEventRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("BroadcastCustomEvent", requestData); + return new(builder.AddRequest("BroadcastCustomEvent", requestData)); } /// - /// Appends a CallVendorRequest request to the batch. + /// Adds a CallVendorRequest request to the batch. /// Call a request registered to a vendor. A vendor is a unique name registered by a third-party plugin or script, which allows for custom requests and events to be added to obs-websocket. If a plugin or script implements vendor requests or events, documentation is expected to be provided with them. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CallVendorRequest(ObsWebSocket.Core.Protocol.Requests.CallVendorRequestRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CallVendorRequest(ObsWebSocket.Core.Protocol.Requests.CallVendorRequestRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CallVendorRequest", requestData); + return new(builder.AddRequest("CallVendorRequest", requestData)); } /// - /// Appends a GetHotkeyList request to the batch. + /// Adds a GetHotkeyList request to the batch. /// Gets an array of all hotkey names in OBS. Note: Hotkey functionality in obs-websocket comes as-is, and we do not guarantee support if things are broken. In 9/10 usages of hotkey requests, there exists a better, more reliable method via other requests. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetHotkeyList() => Add("GetHotkeyList", null); + /// A reference used to read this request's result. + public BatchRef GetHotkeyList() => new(builder.AddRequest("GetHotkeyList", null)); /// - /// Appends a TriggerHotkeyByName request to the batch. + /// Adds a TriggerHotkeyByName request to the batch. /// Triggers a hotkey using its name. See `GetHotkeyList`. Note: Hotkey functionality in obs-websocket comes as-is, and we do not guarantee support if things are broken. In 9/10 usages of hotkey requests, there exists a better, more reliable method via other requests. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder TriggerHotkeyByName(ObsWebSocket.Core.Protocol.Requests.TriggerHotkeyByNameRequestData requestData) + /// A reference used to read this request's result. + public BatchRef TriggerHotkeyByName(ObsWebSocket.Core.Protocol.Requests.TriggerHotkeyByNameRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("TriggerHotkeyByName", requestData); + return new(builder.AddRequest("TriggerHotkeyByName", requestData)); } /// - /// Appends a TriggerHotkeyByKeySequence request to the batch. + /// Adds a TriggerHotkeyByKeySequence request to the batch. /// Triggers a hotkey using a sequence of keys. Note: Hotkey functionality in obs-websocket comes as-is, and we do not guarantee support if things are broken. In 9/10 usages of hotkey requests, there exists a better, more reliable method via other requests. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder TriggerHotkeyByKeySequence(ObsWebSocket.Core.Protocol.Requests.TriggerHotkeyByKeySequenceRequestData requestData) + /// A reference used to read this request's result. + public BatchRef TriggerHotkeyByKeySequence(ObsWebSocket.Core.Protocol.Requests.TriggerHotkeyByKeySequenceRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("TriggerHotkeyByKeySequence", requestData); + return new(builder.AddRequest("TriggerHotkeyByKeySequence", requestData)); } /// - /// Appends a Sleep request to the batch. + /// Adds a Sleep request to the batch. /// Sleeps for a time duration or number of frames. Only available in request batches with types `SERIAL_REALTIME` or `SERIAL_FRAME`. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder Sleep(ObsWebSocket.Core.Protocol.Requests.SleepRequestData requestData) + /// A reference used to read this request's result. + public BatchRef Sleep(ObsWebSocket.Core.Protocol.Requests.SleepRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("Sleep", requestData); + return new(builder.AddRequest("Sleep", requestData)); } +} + +/// +/// Batch requests in the inputs category. +/// +/// The batch being built. +public readonly struct InputsBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetInputList request to the batch. + /// Adds a GetInputList request to the batch. /// Gets an array of all inputs in OBS. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputList(ObsWebSocket.Core.Protocol.Requests.GetInputListRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputList(ObsWebSocket.Core.Protocol.Requests.GetInputListRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputList", requestData); + return new(builder.AddRequest("GetInputList", requestData)); } /// - /// Appends a GetInputKindList request to the batch. + /// Adds a GetInputKindList request to the batch. /// Gets an array of all available input kinds in OBS. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputKindList(ObsWebSocket.Core.Protocol.Requests.GetInputKindListRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputKindList(ObsWebSocket.Core.Protocol.Requests.GetInputKindListRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputKindList", requestData); + return new(builder.AddRequest("GetInputKindList", requestData)); } /// - /// Appends a GetSpecialInputs request to the batch. + /// Adds a GetSpecialInputs request to the batch. /// Gets the names of all special inputs. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetSpecialInputs() => Add("GetSpecialInputs", null); + /// A reference used to read this request's result. + public BatchRef GetSpecialInputs() => new(builder.AddRequest("GetSpecialInputs", null)); /// - /// Appends a CreateInput request to the batch. + /// Adds a CreateInput request to the batch. /// Creates a new input, adding it as a scene item to the specified scene. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateInput(ObsWebSocket.Core.Protocol.Requests.CreateInputRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateInput(ObsWebSocket.Core.Protocol.Requests.CreateInputRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateInput", requestData); + return new(builder.AddRequest("CreateInput", requestData)); } /// - /// Appends a RemoveInput request to the batch. + /// Adds a RemoveInput request to the batch. /// Removes an existing input. Note: Will immediately remove all associated scene items. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder RemoveInput(ObsWebSocket.Core.Protocol.Requests.RemoveInputRequestData requestData) + /// A reference used to read this request's result. + public BatchRef RemoveInput(ObsWebSocket.Core.Protocol.Requests.RemoveInputRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("RemoveInput", requestData); + return new(builder.AddRequest("RemoveInput", requestData)); } /// - /// Appends a SetInputName request to the batch. + /// Adds a SetInputName request to the batch. /// Sets the name of an input (rename). /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputName(ObsWebSocket.Core.Protocol.Requests.SetInputNameRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputName(ObsWebSocket.Core.Protocol.Requests.SetInputNameRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputName", requestData); + return new(builder.AddRequest("SetInputName", requestData)); } /// - /// Appends a GetInputDefaultSettings request to the batch. + /// Adds a GetInputDefaultSettings request to the batch. /// Gets the default settings for an input kind. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputDefaultSettings(ObsWebSocket.Core.Protocol.Requests.GetInputDefaultSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputDefaultSettings(ObsWebSocket.Core.Protocol.Requests.GetInputDefaultSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputDefaultSettings", requestData); + return new(builder.AddRequest("GetInputDefaultSettings", requestData)); } /// - /// Appends a GetInputSettings request to the batch. + /// Adds a GetInputSettings request to the batch. /// Gets the settings of an input. Note: Does not include defaults. To create the entire settings object, overlay `inputSettings` over the `defaultInputSettings` provided by `GetInputDefaultSettings`. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputSettings(ObsWebSocket.Core.Protocol.Requests.GetInputSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputSettings(ObsWebSocket.Core.Protocol.Requests.GetInputSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputSettings", requestData); + return new(builder.AddRequest("GetInputSettings", requestData)); } /// - /// Appends a SetInputSettings request to the batch. + /// Adds a SetInputSettings request to the batch. /// Sets the settings of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputSettings(ObsWebSocket.Core.Protocol.Requests.SetInputSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputSettings(ObsWebSocket.Core.Protocol.Requests.SetInputSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputSettings", requestData); + return new(builder.AddRequest("SetInputSettings", requestData)); } /// - /// Appends a GetInputMute request to the batch. + /// Adds a GetInputMute request to the batch. /// Gets the audio mute state of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputMute(ObsWebSocket.Core.Protocol.Requests.GetInputMuteRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputMute(ObsWebSocket.Core.Protocol.Requests.GetInputMuteRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputMute", requestData); + return new(builder.AddRequest("GetInputMute", requestData)); } /// - /// Appends a SetInputMute request to the batch. + /// Adds a SetInputMute request to the batch. /// Sets the audio mute state of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputMute(ObsWebSocket.Core.Protocol.Requests.SetInputMuteRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputMute(ObsWebSocket.Core.Protocol.Requests.SetInputMuteRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputMute", requestData); + return new(builder.AddRequest("SetInputMute", requestData)); } /// - /// Appends a ToggleInputMute request to the batch. + /// Adds a ToggleInputMute request to the batch. /// Toggles the audio mute state of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder ToggleInputMute(ObsWebSocket.Core.Protocol.Requests.ToggleInputMuteRequestData requestData) + /// A reference used to read this request's result. + public BatchRef ToggleInputMute(ObsWebSocket.Core.Protocol.Requests.ToggleInputMuteRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("ToggleInputMute", requestData); + return new(builder.AddRequest("ToggleInputMute", requestData)); } /// - /// Appends a GetInputVolume request to the batch. + /// Adds a GetInputVolume request to the batch. /// Gets the current volume setting of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputVolume(ObsWebSocket.Core.Protocol.Requests.GetInputVolumeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputVolume(ObsWebSocket.Core.Protocol.Requests.GetInputVolumeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputVolume", requestData); + return new(builder.AddRequest("GetInputVolume", requestData)); } /// - /// Appends a SetInputVolume request to the batch. + /// Adds a SetInputVolume request to the batch. /// Sets the volume setting of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputVolume(ObsWebSocket.Core.Protocol.Requests.SetInputVolumeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputVolume(ObsWebSocket.Core.Protocol.Requests.SetInputVolumeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputVolume", requestData); + return new(builder.AddRequest("SetInputVolume", requestData)); } /// - /// Appends a GetInputAudioBalance request to the batch. + /// Adds a GetInputAudioBalance request to the batch. /// Gets the audio balance of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputAudioBalance(ObsWebSocket.Core.Protocol.Requests.GetInputAudioBalanceRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputAudioBalance(ObsWebSocket.Core.Protocol.Requests.GetInputAudioBalanceRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputAudioBalance", requestData); + return new(builder.AddRequest("GetInputAudioBalance", requestData)); } /// - /// Appends a SetInputAudioBalance request to the batch. + /// Adds a SetInputAudioBalance request to the batch. /// Sets the audio balance of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputAudioBalance(ObsWebSocket.Core.Protocol.Requests.SetInputAudioBalanceRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputAudioBalance(ObsWebSocket.Core.Protocol.Requests.SetInputAudioBalanceRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputAudioBalance", requestData); + return new(builder.AddRequest("SetInputAudioBalance", requestData)); } /// - /// Appends a GetInputAudioSyncOffset request to the batch. + /// Adds a GetInputAudioSyncOffset request to the batch. /// Gets the audio sync offset of an input. Note: The audio sync offset can be negative too! /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputAudioSyncOffset(ObsWebSocket.Core.Protocol.Requests.GetInputAudioSyncOffsetRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputAudioSyncOffset(ObsWebSocket.Core.Protocol.Requests.GetInputAudioSyncOffsetRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputAudioSyncOffset", requestData); + return new(builder.AddRequest("GetInputAudioSyncOffset", requestData)); } /// - /// Appends a SetInputAudioSyncOffset request to the batch. + /// Adds a SetInputAudioSyncOffset request to the batch. /// Sets the audio sync offset of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputAudioSyncOffset(ObsWebSocket.Core.Protocol.Requests.SetInputAudioSyncOffsetRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputAudioSyncOffset(ObsWebSocket.Core.Protocol.Requests.SetInputAudioSyncOffsetRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputAudioSyncOffset", requestData); + return new(builder.AddRequest("SetInputAudioSyncOffset", requestData)); } /// - /// Appends a GetInputAudioMonitorType request to the batch. + /// Adds a GetInputAudioMonitorType request to the batch. /// Gets the audio monitor type of an input. The available audio monitor types are: - `OBS_MONITORING_TYPE_NONE` - `OBS_MONITORING_TYPE_MONITOR_ONLY` - `OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT` /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputAudioMonitorType(ObsWebSocket.Core.Protocol.Requests.GetInputAudioMonitorTypeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputAudioMonitorType(ObsWebSocket.Core.Protocol.Requests.GetInputAudioMonitorTypeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputAudioMonitorType", requestData); + return new(builder.AddRequest("GetInputAudioMonitorType", requestData)); } /// - /// Appends a SetInputAudioMonitorType request to the batch. + /// Adds a SetInputAudioMonitorType request to the batch. /// Sets the audio monitor type of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputAudioMonitorType(ObsWebSocket.Core.Protocol.Requests.SetInputAudioMonitorTypeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputAudioMonitorType(ObsWebSocket.Core.Protocol.Requests.SetInputAudioMonitorTypeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputAudioMonitorType", requestData); + return new(builder.AddRequest("SetInputAudioMonitorType", requestData)); } /// - /// Appends a GetInputAudioTracks request to the batch. + /// Adds a GetInputAudioTracks request to the batch. /// Gets the enable state of all audio tracks of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputAudioTracks(ObsWebSocket.Core.Protocol.Requests.GetInputAudioTracksRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputAudioTracks(ObsWebSocket.Core.Protocol.Requests.GetInputAudioTracksRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputAudioTracks", requestData); + return new(builder.AddRequest("GetInputAudioTracks", requestData)); } /// - /// Appends a SetInputAudioTracks request to the batch. + /// Adds a SetInputAudioTracks request to the batch. /// Sets the enable state of audio tracks of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputAudioTracks(ObsWebSocket.Core.Protocol.Requests.SetInputAudioTracksRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputAudioTracks(ObsWebSocket.Core.Protocol.Requests.SetInputAudioTracksRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputAudioTracks", requestData); + return new(builder.AddRequest("SetInputAudioTracks", requestData)); } /// - /// Appends a GetInputDeinterlaceMode request to the batch. + /// Adds a GetInputDeinterlaceMode request to the batch. /// Gets the deinterlace mode of an input. Deinterlace Modes: - `OBS_DEINTERLACE_MODE_DISABLE` - `OBS_DEINTERLACE_MODE_DISCARD` - `OBS_DEINTERLACE_MODE_RETRO` - `OBS_DEINTERLACE_MODE_BLEND` - `OBS_DEINTERLACE_MODE_BLEND_2X` - `OBS_DEINTERLACE_MODE_LINEAR` - `OBS_DEINTERLACE_MODE_LINEAR_2X` - `OBS_DEINTERLACE_MODE_YADIF` - `OBS_DEINTERLACE_MODE_YADIF_2X` Note: Deinterlacing functionality is restricted to async inputs only. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputDeinterlaceMode(ObsWebSocket.Core.Protocol.Requests.GetInputDeinterlaceModeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputDeinterlaceMode(ObsWebSocket.Core.Protocol.Requests.GetInputDeinterlaceModeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputDeinterlaceMode", requestData); + return new(builder.AddRequest("GetInputDeinterlaceMode", requestData)); } /// - /// Appends a SetInputDeinterlaceMode request to the batch. + /// Adds a SetInputDeinterlaceMode request to the batch. /// Sets the deinterlace mode of an input. Note: Deinterlacing functionality is restricted to async inputs only. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputDeinterlaceMode(ObsWebSocket.Core.Protocol.Requests.SetInputDeinterlaceModeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputDeinterlaceMode(ObsWebSocket.Core.Protocol.Requests.SetInputDeinterlaceModeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputDeinterlaceMode", requestData); + return new(builder.AddRequest("SetInputDeinterlaceMode", requestData)); } /// - /// Appends a GetInputDeinterlaceFieldOrder request to the batch. + /// Adds a GetInputDeinterlaceFieldOrder request to the batch. /// Gets the deinterlace field order of an input. Deinterlace Field Orders: - `OBS_DEINTERLACE_FIELD_ORDER_TOP` - `OBS_DEINTERLACE_FIELD_ORDER_BOTTOM` Note: Deinterlacing functionality is restricted to async inputs only. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputDeinterlaceFieldOrder(ObsWebSocket.Core.Protocol.Requests.GetInputDeinterlaceFieldOrderRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputDeinterlaceFieldOrder(ObsWebSocket.Core.Protocol.Requests.GetInputDeinterlaceFieldOrderRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputDeinterlaceFieldOrder", requestData); + return new(builder.AddRequest("GetInputDeinterlaceFieldOrder", requestData)); } /// - /// Appends a SetInputDeinterlaceFieldOrder request to the batch. + /// Adds a SetInputDeinterlaceFieldOrder request to the batch. /// Sets the deinterlace field order of an input. Note: Deinterlacing functionality is restricted to async inputs only. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetInputDeinterlaceFieldOrder(ObsWebSocket.Core.Protocol.Requests.SetInputDeinterlaceFieldOrderRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetInputDeinterlaceFieldOrder(ObsWebSocket.Core.Protocol.Requests.SetInputDeinterlaceFieldOrderRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetInputDeinterlaceFieldOrder", requestData); + return new(builder.AddRequest("SetInputDeinterlaceFieldOrder", requestData)); } /// - /// Appends a GetInputPropertiesListPropertyItems request to the batch. + /// Adds a GetInputPropertiesListPropertyItems request to the batch. /// Gets the items of a list property from an input's properties. Note: Use this in cases where an input provides a dynamic, selectable list of items. For example, display capture, where it provides a list of available displays. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetInputPropertiesListPropertyItems(ObsWebSocket.Core.Protocol.Requests.GetInputPropertiesListPropertyItemsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetInputPropertiesListPropertyItems(ObsWebSocket.Core.Protocol.Requests.GetInputPropertiesListPropertyItemsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetInputPropertiesListPropertyItems", requestData); + return new(builder.AddRequest("GetInputPropertiesListPropertyItems", requestData)); } /// - /// Appends a PressInputPropertiesButton request to the batch. + /// Adds a PressInputPropertiesButton request to the batch. /// Presses a button in the properties of an input. Some known `propertyName` values are: - `refreshnocache` - Browser source reload button Note: Use this in cases where there is a button in the properties of an input that cannot be accessed in any other way. For example, browser sources, where there is a refresh button. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder PressInputPropertiesButton(ObsWebSocket.Core.Protocol.Requests.PressInputPropertiesButtonRequestData requestData) + /// A reference used to read this request's result. + public BatchRef PressInputPropertiesButton(ObsWebSocket.Core.Protocol.Requests.PressInputPropertiesButtonRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("PressInputPropertiesButton", requestData); + return new(builder.AddRequest("PressInputPropertiesButton", requestData)); } +} + +/// +/// Batch requests in the media inputs category. +/// +/// The batch being built. +public readonly struct MediaInputsBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetMediaInputStatus request to the batch. + /// Adds a GetMediaInputStatus request to the batch. /// Gets the status of a media input. Media States: - `OBS_MEDIA_STATE_NONE` - `OBS_MEDIA_STATE_PLAYING` - `OBS_MEDIA_STATE_OPENING` - `OBS_MEDIA_STATE_BUFFERING` - `OBS_MEDIA_STATE_PAUSED` - `OBS_MEDIA_STATE_STOPPED` - `OBS_MEDIA_STATE_ENDED` - `OBS_MEDIA_STATE_ERROR` /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetMediaInputStatus(ObsWebSocket.Core.Protocol.Requests.GetMediaInputStatusRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetMediaInputStatus(ObsWebSocket.Core.Protocol.Requests.GetMediaInputStatusRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetMediaInputStatus", requestData); + return new(builder.AddRequest("GetMediaInputStatus", requestData)); } /// - /// Appends a SetMediaInputCursor request to the batch. + /// Adds a SetMediaInputCursor request to the batch. /// Sets the cursor position of a media input. This request does not perform bounds checking of the cursor position. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetMediaInputCursor(ObsWebSocket.Core.Protocol.Requests.SetMediaInputCursorRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetMediaInputCursor(ObsWebSocket.Core.Protocol.Requests.SetMediaInputCursorRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetMediaInputCursor", requestData); + return new(builder.AddRequest("SetMediaInputCursor", requestData)); } /// - /// Appends a OffsetMediaInputCursor request to the batch. + /// Adds a OffsetMediaInputCursor request to the batch. /// Offsets the current cursor position of a media input by the specified value. This request does not perform bounds checking of the cursor position. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder OffsetMediaInputCursor(ObsWebSocket.Core.Protocol.Requests.OffsetMediaInputCursorRequestData requestData) + /// A reference used to read this request's result. + public BatchRef OffsetMediaInputCursor(ObsWebSocket.Core.Protocol.Requests.OffsetMediaInputCursorRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("OffsetMediaInputCursor", requestData); + return new(builder.AddRequest("OffsetMediaInputCursor", requestData)); } /// - /// Appends a TriggerMediaInputAction request to the batch. + /// Adds a TriggerMediaInputAction request to the batch. /// Triggers an action on a media input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder TriggerMediaInputAction(ObsWebSocket.Core.Protocol.Requests.TriggerMediaInputActionRequestData requestData) + /// A reference used to read this request's result. + public BatchRef TriggerMediaInputAction(ObsWebSocket.Core.Protocol.Requests.TriggerMediaInputActionRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("TriggerMediaInputAction", requestData); + return new(builder.AddRequest("TriggerMediaInputAction", requestData)); } +} + +/// +/// Batch requests in the outputs category. +/// +/// The batch being built. +public readonly struct OutputsBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetVirtualCamStatus request to the batch. + /// Adds a GetVirtualCamStatus request to the batch. /// Gets the status of the virtualcam output. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetVirtualCamStatus() => Add("GetVirtualCamStatus", null); + /// A reference used to read this request's result. + public BatchRef GetVirtualCamStatus() => new(builder.AddRequest("GetVirtualCamStatus", null)); /// - /// Appends a ToggleVirtualCam request to the batch. + /// Adds a ToggleVirtualCam request to the batch. /// Toggles the state of the virtualcam output. /// - /// The same builder, for chaining. - public ObsBatchBuilder ToggleVirtualCam() => Add("ToggleVirtualCam", null); + /// A reference used to read this request's result. + public BatchRef ToggleVirtualCam() => new(builder.AddRequest("ToggleVirtualCam", null)); /// - /// Appends a StartVirtualCam request to the batch. + /// Adds a StartVirtualCam request to the batch. /// Starts the virtualcam output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StartVirtualCam() => Add("StartVirtualCam", null); + /// A reference used to read this request's result. + public BatchRef StartVirtualCam() => new(builder.AddRequest("StartVirtualCam", null)); /// - /// Appends a StopVirtualCam request to the batch. + /// Adds a StopVirtualCam request to the batch. /// Stops the virtualcam output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StopVirtualCam() => Add("StopVirtualCam", null); + /// A reference used to read this request's result. + public BatchRef StopVirtualCam() => new(builder.AddRequest("StopVirtualCam", null)); /// - /// Appends a GetReplayBufferStatus request to the batch. + /// Adds a GetReplayBufferStatus request to the batch. /// Gets the status of the replay buffer output. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetReplayBufferStatus() => Add("GetReplayBufferStatus", null); + /// A reference used to read this request's result. + public BatchRef GetReplayBufferStatus() => new(builder.AddRequest("GetReplayBufferStatus", null)); /// - /// Appends a ToggleReplayBuffer request to the batch. + /// Adds a ToggleReplayBuffer request to the batch. /// Toggles the state of the replay buffer output. /// - /// The same builder, for chaining. - public ObsBatchBuilder ToggleReplayBuffer() => Add("ToggleReplayBuffer", null); + /// A reference used to read this request's result. + public BatchRef ToggleReplayBuffer() => new(builder.AddRequest("ToggleReplayBuffer", null)); /// - /// Appends a StartReplayBuffer request to the batch. + /// Adds a StartReplayBuffer request to the batch. /// Starts the replay buffer output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StartReplayBuffer() => Add("StartReplayBuffer", null); + /// A reference used to read this request's result. + public BatchRef StartReplayBuffer() => new(builder.AddRequest("StartReplayBuffer", null)); /// - /// Appends a StopReplayBuffer request to the batch. + /// Adds a StopReplayBuffer request to the batch. /// Stops the replay buffer output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StopReplayBuffer() => Add("StopReplayBuffer", null); + /// A reference used to read this request's result. + public BatchRef StopReplayBuffer() => new(builder.AddRequest("StopReplayBuffer", null)); /// - /// Appends a SaveReplayBuffer request to the batch. + /// Adds a SaveReplayBuffer request to the batch. /// Saves the contents of the replay buffer output. /// - /// The same builder, for chaining. - public ObsBatchBuilder SaveReplayBuffer() => Add("SaveReplayBuffer", null); + /// A reference used to read this request's result. + public BatchRef SaveReplayBuffer() => new(builder.AddRequest("SaveReplayBuffer", null)); /// - /// Appends a GetLastReplayBufferReplay request to the batch. + /// Adds a GetLastReplayBufferReplay request to the batch. /// Gets the filename of the last replay buffer save file. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetLastReplayBufferReplay() => Add("GetLastReplayBufferReplay", null); + /// A reference used to read this request's result. + public BatchRef GetLastReplayBufferReplay() => new(builder.AddRequest("GetLastReplayBufferReplay", null)); /// - /// Appends a GetOutputList request to the batch. + /// Adds a GetOutputList request to the batch. /// Gets the list of available outputs. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetOutputList() => Add("GetOutputList", null); + /// A reference used to read this request's result. + public BatchRef GetOutputList() => new(builder.AddRequest("GetOutputList", null)); /// - /// Appends a GetOutputStatus request to the batch. + /// Adds a GetOutputStatus request to the batch. /// Gets the status of an output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetOutputStatus(ObsWebSocket.Core.Protocol.Requests.GetOutputStatusRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetOutputStatus(ObsWebSocket.Core.Protocol.Requests.GetOutputStatusRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetOutputStatus", requestData); + return new(builder.AddRequest("GetOutputStatus", requestData)); } /// - /// Appends a ToggleOutput request to the batch. + /// Adds a ToggleOutput request to the batch. /// Toggles the status of an output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder ToggleOutput(ObsWebSocket.Core.Protocol.Requests.ToggleOutputRequestData requestData) + /// A reference used to read this request's result. + public BatchRef ToggleOutput(ObsWebSocket.Core.Protocol.Requests.ToggleOutputRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("ToggleOutput", requestData); + return new(builder.AddRequest("ToggleOutput", requestData)); } /// - /// Appends a StartOutput request to the batch. + /// Adds a StartOutput request to the batch. /// Starts an output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder StartOutput(ObsWebSocket.Core.Protocol.Requests.StartOutputRequestData requestData) + /// A reference used to read this request's result. + public BatchRef StartOutput(ObsWebSocket.Core.Protocol.Requests.StartOutputRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("StartOutput", requestData); + return new(builder.AddRequest("StartOutput", requestData)); } /// - /// Appends a StopOutput request to the batch. + /// Adds a StopOutput request to the batch. /// Stops an output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder StopOutput(ObsWebSocket.Core.Protocol.Requests.StopOutputRequestData requestData) + /// A reference used to read this request's result. + public BatchRef StopOutput(ObsWebSocket.Core.Protocol.Requests.StopOutputRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("StopOutput", requestData); + return new(builder.AddRequest("StopOutput", requestData)); } /// - /// Appends a GetOutputSettings request to the batch. + /// Adds a GetOutputSettings request to the batch. /// Gets the settings of an output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetOutputSettings(ObsWebSocket.Core.Protocol.Requests.GetOutputSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetOutputSettings(ObsWebSocket.Core.Protocol.Requests.GetOutputSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetOutputSettings", requestData); + return new(builder.AddRequest("GetOutputSettings", requestData)); } /// - /// Appends a SetOutputSettings request to the batch. + /// Adds a SetOutputSettings request to the batch. /// Sets the settings of an output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetOutputSettings(ObsWebSocket.Core.Protocol.Requests.SetOutputSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetOutputSettings(ObsWebSocket.Core.Protocol.Requests.SetOutputSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetOutputSettings", requestData); + return new(builder.AddRequest("SetOutputSettings", requestData)); } +} + +/// +/// Batch requests in the record category. +/// +/// The batch being built. +public readonly struct RecordBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetRecordStatus request to the batch. + /// Adds a GetRecordStatus request to the batch. /// Gets the status of the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetRecordStatus() => Add("GetRecordStatus", null); + /// A reference used to read this request's result. + public BatchRef GetRecordStatus() => new(builder.AddRequest("GetRecordStatus", null)); /// - /// Appends a ToggleRecord request to the batch. + /// Adds a ToggleRecord request to the batch. /// Toggles the status of the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder ToggleRecord() => Add("ToggleRecord", null); + /// A reference used to read this request's result. + public BatchRef ToggleRecord() => new(builder.AddRequest("ToggleRecord", null)); /// - /// Appends a StartRecord request to the batch. + /// Adds a StartRecord request to the batch. /// Starts the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StartRecord() => Add("StartRecord", null); + /// A reference used to read this request's result. + public BatchRef StartRecord() => new(builder.AddRequest("StartRecord", null)); /// - /// Appends a StopRecord request to the batch. + /// Adds a StopRecord request to the batch. /// Stops the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StopRecord() => Add("StopRecord", null); + /// A reference used to read this request's result. + public BatchRef StopRecord() => new(builder.AddRequest("StopRecord", null)); /// - /// Appends a ToggleRecordPause request to the batch. + /// Adds a ToggleRecordPause request to the batch. /// Toggles pause on the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder ToggleRecordPause() => Add("ToggleRecordPause", null); + /// A reference used to read this request's result. + public BatchRef ToggleRecordPause() => new(builder.AddRequest("ToggleRecordPause", null)); /// - /// Appends a PauseRecord request to the batch. + /// Adds a PauseRecord request to the batch. /// Pauses the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder PauseRecord() => Add("PauseRecord", null); + /// A reference used to read this request's result. + public BatchRef PauseRecord() => new(builder.AddRequest("PauseRecord", null)); /// - /// Appends a ResumeRecord request to the batch. + /// Adds a ResumeRecord request to the batch. /// Resumes the record output. /// - /// The same builder, for chaining. - public ObsBatchBuilder ResumeRecord() => Add("ResumeRecord", null); + /// A reference used to read this request's result. + public BatchRef ResumeRecord() => new(builder.AddRequest("ResumeRecord", null)); /// - /// Appends a SplitRecordFile request to the batch. + /// Adds a SplitRecordFile request to the batch. /// Splits the current file being recorded into a new file. /// - /// The same builder, for chaining. - public ObsBatchBuilder SplitRecordFile() => Add("SplitRecordFile", null); + /// A reference used to read this request's result. + public BatchRef SplitRecordFile() => new(builder.AddRequest("SplitRecordFile", null)); /// - /// Appends a CreateRecordChapter request to the batch. + /// Adds a CreateRecordChapter request to the batch. /// Adds a new chapter marker to the file currently being recorded. Note: As of OBS 30.2.0, the only file format supporting this feature is Hybrid MP4. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateRecordChapter(ObsWebSocket.Core.Protocol.Requests.CreateRecordChapterRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateRecordChapter(ObsWebSocket.Core.Protocol.Requests.CreateRecordChapterRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateRecordChapter", requestData); + return new(builder.AddRequest("CreateRecordChapter", requestData)); } +} + +/// +/// Batch requests in the scene items category. +/// +/// The batch being built. +public readonly struct SceneItemsBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetSceneItemList request to the batch. + /// Adds a GetSceneItemList request to the batch. /// Gets a list of all scene items in a scene. Scenes only /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemList(ObsWebSocket.Core.Protocol.Requests.GetSceneItemListRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemList(ObsWebSocket.Core.Protocol.Requests.GetSceneItemListRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemList", requestData); + return new(builder.AddRequest("GetSceneItemList", requestData)); } /// - /// Appends a GetGroupSceneItemList request to the batch. + /// Adds a GetGroupSceneItemList request to the batch. /// Basically GetSceneItemList, but for groups. Using groups at all in OBS is discouraged, as they are very broken under the hood. Please use nested scenes instead. Groups only /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetGroupSceneItemList(ObsWebSocket.Core.Protocol.Requests.GetGroupSceneItemListRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetGroupSceneItemList(ObsWebSocket.Core.Protocol.Requests.GetGroupSceneItemListRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetGroupSceneItemList", requestData); + return new(builder.AddRequest("GetGroupSceneItemList", requestData)); } /// - /// Appends a GetSceneItemId request to the batch. + /// Adds a GetSceneItemId request to the batch. /// Searches a scene for a source, and returns its id. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemId(ObsWebSocket.Core.Protocol.Requests.GetSceneItemIdRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemId(ObsWebSocket.Core.Protocol.Requests.GetSceneItemIdRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemId", requestData); + return new(builder.AddRequest("GetSceneItemId", requestData)); } /// - /// Appends a GetSceneItemSource request to the batch. + /// Adds a GetSceneItemSource request to the batch. /// Gets the source associated with a scene item. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemSource(ObsWebSocket.Core.Protocol.Requests.GetSceneItemSourceRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemSource(ObsWebSocket.Core.Protocol.Requests.GetSceneItemSourceRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemSource", requestData); + return new(builder.AddRequest("GetSceneItemSource", requestData)); } /// - /// Appends a CreateSceneItem request to the batch. + /// Adds a CreateSceneItem request to the batch. /// Creates a new scene item using a source. Scenes only /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateSceneItem(ObsWebSocket.Core.Protocol.Requests.CreateSceneItemRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateSceneItem(ObsWebSocket.Core.Protocol.Requests.CreateSceneItemRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateSceneItem", requestData); + return new(builder.AddRequest("CreateSceneItem", requestData)); } /// - /// Appends a RemoveSceneItem request to the batch. + /// Adds a RemoveSceneItem request to the batch. /// Removes a scene item from a scene. Scenes only /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder RemoveSceneItem(ObsWebSocket.Core.Protocol.Requests.RemoveSceneItemRequestData requestData) + /// A reference used to read this request's result. + public BatchRef RemoveSceneItem(ObsWebSocket.Core.Protocol.Requests.RemoveSceneItemRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("RemoveSceneItem", requestData); + return new(builder.AddRequest("RemoveSceneItem", requestData)); } /// - /// Appends a DuplicateSceneItem request to the batch. + /// Adds a DuplicateSceneItem request to the batch. /// Duplicates a scene item, copying all transform and crop info. Scenes only /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder DuplicateSceneItem(ObsWebSocket.Core.Protocol.Requests.DuplicateSceneItemRequestData requestData) + /// A reference used to read this request's result. + public BatchRef DuplicateSceneItem(ObsWebSocket.Core.Protocol.Requests.DuplicateSceneItemRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("DuplicateSceneItem", requestData); + return new(builder.AddRequest("DuplicateSceneItem", requestData)); } /// - /// Appends a GetSceneItemTransform request to the batch. + /// Adds a GetSceneItemTransform request to the batch. /// Gets the transform and crop info of a scene item. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemTransform(ObsWebSocket.Core.Protocol.Requests.GetSceneItemTransformRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemTransform(ObsWebSocket.Core.Protocol.Requests.GetSceneItemTransformRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemTransform", requestData); + return new(builder.AddRequest("GetSceneItemTransform", requestData)); } /// - /// Appends a SetSceneItemTransform request to the batch. + /// Adds a SetSceneItemTransform request to the batch. /// Sets the transform and crop info of a scene item. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneItemTransform(ObsWebSocket.Core.Protocol.Requests.SetSceneItemTransformRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneItemTransform(ObsWebSocket.Core.Protocol.Requests.SetSceneItemTransformRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneItemTransform", requestData); + return new(builder.AddRequest("SetSceneItemTransform", requestData)); } /// - /// Appends a GetSceneItemEnabled request to the batch. + /// Adds a GetSceneItemEnabled request to the batch. /// Gets the enable state of a scene item. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemEnabled(ObsWebSocket.Core.Protocol.Requests.GetSceneItemEnabledRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemEnabled(ObsWebSocket.Core.Protocol.Requests.GetSceneItemEnabledRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemEnabled", requestData); + return new(builder.AddRequest("GetSceneItemEnabled", requestData)); } /// - /// Appends a SetSceneItemEnabled request to the batch. + /// Adds a SetSceneItemEnabled request to the batch. /// Sets the enable state of a scene item. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneItemEnabled(ObsWebSocket.Core.Protocol.Requests.SetSceneItemEnabledRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneItemEnabled(ObsWebSocket.Core.Protocol.Requests.SetSceneItemEnabledRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneItemEnabled", requestData); + return new(builder.AddRequest("SetSceneItemEnabled", requestData)); } /// - /// Appends a GetSceneItemLocked request to the batch. + /// Adds a GetSceneItemLocked request to the batch. /// Gets the lock state of a scene item. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemLocked(ObsWebSocket.Core.Protocol.Requests.GetSceneItemLockedRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemLocked(ObsWebSocket.Core.Protocol.Requests.GetSceneItemLockedRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemLocked", requestData); + return new(builder.AddRequest("GetSceneItemLocked", requestData)); } /// - /// Appends a SetSceneItemLocked request to the batch. + /// Adds a SetSceneItemLocked request to the batch. /// Sets the lock state of a scene item. Scenes and Group /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneItemLocked(ObsWebSocket.Core.Protocol.Requests.SetSceneItemLockedRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneItemLocked(ObsWebSocket.Core.Protocol.Requests.SetSceneItemLockedRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneItemLocked", requestData); + return new(builder.AddRequest("SetSceneItemLocked", requestData)); } /// - /// Appends a GetSceneItemIndex request to the batch. + /// Adds a GetSceneItemIndex request to the batch. /// Gets the index position of a scene item in a scene. An index of 0 is at the bottom of the source list in the UI. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemIndex(ObsWebSocket.Core.Protocol.Requests.GetSceneItemIndexRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemIndex(ObsWebSocket.Core.Protocol.Requests.GetSceneItemIndexRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemIndex", requestData); + return new(builder.AddRequest("GetSceneItemIndex", requestData)); } /// - /// Appends a SetSceneItemIndex request to the batch. + /// Adds a SetSceneItemIndex request to the batch. /// Sets the index position of a scene item in a scene. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneItemIndex(ObsWebSocket.Core.Protocol.Requests.SetSceneItemIndexRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneItemIndex(ObsWebSocket.Core.Protocol.Requests.SetSceneItemIndexRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneItemIndex", requestData); + return new(builder.AddRequest("SetSceneItemIndex", requestData)); } /// - /// Appends a GetSceneItemBlendMode request to the batch. + /// Adds a GetSceneItemBlendMode request to the batch. /// Gets the blend mode of a scene item. Blend modes: - `OBS_BLEND_NORMAL` - `OBS_BLEND_ADDITIVE` - `OBS_BLEND_SUBTRACT` - `OBS_BLEND_SCREEN` - `OBS_BLEND_MULTIPLY` - `OBS_BLEND_LIGHTEN` - `OBS_BLEND_DARKEN` Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneItemBlendMode(ObsWebSocket.Core.Protocol.Requests.GetSceneItemBlendModeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneItemBlendMode(ObsWebSocket.Core.Protocol.Requests.GetSceneItemBlendModeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneItemBlendMode", requestData); + return new(builder.AddRequest("GetSceneItemBlendMode", requestData)); } /// - /// Appends a SetSceneItemBlendMode request to the batch. + /// Adds a SetSceneItemBlendMode request to the batch. /// Sets the blend mode of a scene item. Scenes and Groups /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneItemBlendMode(ObsWebSocket.Core.Protocol.Requests.SetSceneItemBlendModeRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneItemBlendMode(ObsWebSocket.Core.Protocol.Requests.SetSceneItemBlendModeRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneItemBlendMode", requestData); + return new(builder.AddRequest("SetSceneItemBlendMode", requestData)); } +} + +/// +/// Batch requests in the scenes category. +/// +/// The batch being built. +public readonly struct ScenesBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetSceneList request to the batch. + /// Adds a GetSceneList request to the batch. /// Gets an array of scenes in OBS. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneList(ObsWebSocket.Core.Protocol.Requests.GetSceneListRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneList(ObsWebSocket.Core.Protocol.Requests.GetSceneListRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneList", requestData); + return new(builder.AddRequest("GetSceneList", requestData)); } /// - /// Appends a GetGroupList request to the batch. + /// Adds a GetGroupList request to the batch. /// Gets an array of all groups in OBS. Groups in OBS are actually scenes, but renamed and modified. In obs-websocket, we treat them as scenes where we can. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetGroupList() => Add("GetGroupList", null); + /// A reference used to read this request's result. + public BatchRef GetGroupList() => new(builder.AddRequest("GetGroupList", null)); /// - /// Appends a GetCurrentProgramScene request to the batch. + /// Adds a GetCurrentProgramScene request to the batch. /// Gets the current program scene. Note 1: This request is slated to have the `currentProgram`-prefixed fields removed from in an upcoming RPC version. Note 2: Canvases do not have any concept of a program or preview scene, so this request does not support canvases. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetCurrentProgramScene() => Add("GetCurrentProgramScene", null); + /// A reference used to read this request's result. + public BatchRef GetCurrentProgramScene() => new(builder.AddRequest("GetCurrentProgramScene", null)); /// - /// Appends a SetCurrentProgramScene request to the batch. + /// Adds a SetCurrentProgramScene request to the batch. /// Sets the current program scene. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentProgramScene(ObsWebSocket.Core.Protocol.Requests.SetCurrentProgramSceneRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentProgramScene(ObsWebSocket.Core.Protocol.Requests.SetCurrentProgramSceneRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentProgramScene", requestData); + return new(builder.AddRequest("SetCurrentProgramScene", requestData)); } /// - /// Appends a GetCurrentPreviewScene request to the batch. + /// Adds a GetCurrentPreviewScene request to the batch. /// Gets the current preview scene. Only available when studio mode is enabled. Note: This request is slated to have the `currentPreview`-prefixed fields removed from in an upcoming RPC version. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetCurrentPreviewScene() => Add("GetCurrentPreviewScene", null); + /// A reference used to read this request's result. + public BatchRef GetCurrentPreviewScene() => new(builder.AddRequest("GetCurrentPreviewScene", null)); /// - /// Appends a SetCurrentPreviewScene request to the batch. + /// Adds a SetCurrentPreviewScene request to the batch. /// Sets the current preview scene. Only available when studio mode is enabled. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentPreviewScene(ObsWebSocket.Core.Protocol.Requests.SetCurrentPreviewSceneRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentPreviewScene(ObsWebSocket.Core.Protocol.Requests.SetCurrentPreviewSceneRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentPreviewScene", requestData); + return new(builder.AddRequest("SetCurrentPreviewScene", requestData)); } /// - /// Appends a CreateScene request to the batch. + /// Adds a CreateScene request to the batch. /// Creates a new scene in OBS. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder CreateScene(ObsWebSocket.Core.Protocol.Requests.CreateSceneRequestData requestData) + /// A reference used to read this request's result. + public BatchRef CreateScene(ObsWebSocket.Core.Protocol.Requests.CreateSceneRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("CreateScene", requestData); + return new(builder.AddRequest("CreateScene", requestData)); } /// - /// Appends a RemoveScene request to the batch. + /// Adds a RemoveScene request to the batch. /// Removes a scene from OBS. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder RemoveScene(ObsWebSocket.Core.Protocol.Requests.RemoveSceneRequestData requestData) + /// A reference used to read this request's result. + public BatchRef RemoveScene(ObsWebSocket.Core.Protocol.Requests.RemoveSceneRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("RemoveScene", requestData); + return new(builder.AddRequest("RemoveScene", requestData)); } /// - /// Appends a SetSceneName request to the batch. + /// Adds a SetSceneName request to the batch. /// Sets the name of a scene (rename). /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneName(ObsWebSocket.Core.Protocol.Requests.SetSceneNameRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneName(ObsWebSocket.Core.Protocol.Requests.SetSceneNameRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneName", requestData); + return new(builder.AddRequest("SetSceneName", requestData)); } /// - /// Appends a GetSceneSceneTransitionOverride request to the batch. + /// Adds a GetSceneSceneTransitionOverride request to the batch. /// Gets the scene transition overridden for a scene. Note: A transition UUID response field is not currently able to be implemented as of 2024-1-18. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSceneSceneTransitionOverride(ObsWebSocket.Core.Protocol.Requests.GetSceneSceneTransitionOverrideRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSceneSceneTransitionOverride(ObsWebSocket.Core.Protocol.Requests.GetSceneSceneTransitionOverrideRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSceneSceneTransitionOverride", requestData); + return new(builder.AddRequest("GetSceneSceneTransitionOverride", requestData)); } /// - /// Appends a SetSceneSceneTransitionOverride request to the batch. + /// Adds a SetSceneSceneTransitionOverride request to the batch. /// Sets the scene transition overridden for a scene. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetSceneSceneTransitionOverride(ObsWebSocket.Core.Protocol.Requests.SetSceneSceneTransitionOverrideRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetSceneSceneTransitionOverride(ObsWebSocket.Core.Protocol.Requests.SetSceneSceneTransitionOverrideRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetSceneSceneTransitionOverride", requestData); + return new(builder.AddRequest("SetSceneSceneTransitionOverride", requestData)); } +} + +/// +/// Batch requests in the sources category. +/// +/// The batch being built. +public readonly struct SourcesBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetSourceActive request to the batch. + /// Adds a GetSourceActive request to the batch. /// Gets the active and show state of a source. **Compatible with inputs and scenes.** /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSourceActive(ObsWebSocket.Core.Protocol.Requests.GetSourceActiveRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSourceActive(ObsWebSocket.Core.Protocol.Requests.GetSourceActiveRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSourceActive", requestData); + return new(builder.AddRequest("GetSourceActive", requestData)); } /// - /// Appends a GetSourceScreenshot request to the batch. + /// Adds a GetSourceScreenshot request to the batch. /// Gets a Base64-encoded screenshot of a source. The `imageWidth` and `imageHeight` parameters are treated as "scale to inner", meaning the smallest ratio will be used and the aspect ratio of the original resolution is kept. If `imageWidth` and `imageHeight` are not specified, the compressed image will use the full resolution of the source. **Compatible with inputs and scenes.** /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder GetSourceScreenshot(ObsWebSocket.Core.Protocol.Requests.GetSourceScreenshotRequestData requestData) + /// A reference used to read this request's result. + public BatchRef GetSourceScreenshot(ObsWebSocket.Core.Protocol.Requests.GetSourceScreenshotRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("GetSourceScreenshot", requestData); + return new(builder.AddRequest("GetSourceScreenshot", requestData)); } /// - /// Appends a SaveSourceScreenshot request to the batch. + /// Adds a SaveSourceScreenshot request to the batch. /// Saves a screenshot of a source to the filesystem. The `imageWidth` and `imageHeight` parameters are treated as "scale to inner", meaning the smallest ratio will be used and the aspect ratio of the original resolution is kept. If `imageWidth` and `imageHeight` are not specified, the compressed image will use the full resolution of the source. **Compatible with inputs and scenes.** /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SaveSourceScreenshot(ObsWebSocket.Core.Protocol.Requests.SaveSourceScreenshotRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SaveSourceScreenshot(ObsWebSocket.Core.Protocol.Requests.SaveSourceScreenshotRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SaveSourceScreenshot", requestData); + return new(builder.AddRequest("SaveSourceScreenshot", requestData)); } +} + +/// +/// Batch requests in the stream category. +/// +/// The batch being built. +public readonly struct StreamBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetStreamStatus request to the batch. + /// Adds a GetStreamStatus request to the batch. /// Gets the status of the stream output. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetStreamStatus() => Add("GetStreamStatus", null); + /// A reference used to read this request's result. + public BatchRef GetStreamStatus() => new(builder.AddRequest("GetStreamStatus", null)); /// - /// Appends a ToggleStream request to the batch. + /// Adds a ToggleStream request to the batch. /// Toggles the status of the stream output. /// - /// The same builder, for chaining. - public ObsBatchBuilder ToggleStream() => Add("ToggleStream", null); + /// A reference used to read this request's result. + public BatchRef ToggleStream() => new(builder.AddRequest("ToggleStream", null)); /// - /// Appends a StartStream request to the batch. + /// Adds a StartStream request to the batch. /// Starts the stream output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StartStream() => Add("StartStream", null); + /// A reference used to read this request's result. + public BatchRef StartStream() => new(builder.AddRequest("StartStream", null)); /// - /// Appends a StopStream request to the batch. + /// Adds a StopStream request to the batch. /// Stops the stream output. /// - /// The same builder, for chaining. - public ObsBatchBuilder StopStream() => Add("StopStream", null); + /// A reference used to read this request's result. + public BatchRef StopStream() => new(builder.AddRequest("StopStream", null)); /// - /// Appends a SendStreamCaption request to the batch. + /// Adds a SendStreamCaption request to the batch. /// Sends CEA-608 caption text over the stream output. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SendStreamCaption(ObsWebSocket.Core.Protocol.Requests.SendStreamCaptionRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SendStreamCaption(ObsWebSocket.Core.Protocol.Requests.SendStreamCaptionRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SendStreamCaption", requestData); + return new(builder.AddRequest("SendStreamCaption", requestData)); } +} + +/// +/// Batch requests in the transitions category. +/// +/// The batch being built. +public readonly struct TransitionsBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetTransitionKindList request to the batch. + /// Adds a GetTransitionKindList request to the batch. /// Gets an array of all available transition kinds. Similar to `GetInputKindList` /// - /// The same builder, for chaining. - public ObsBatchBuilder GetTransitionKindList() => Add("GetTransitionKindList", null); + /// A reference used to read this request's result. + public BatchRef GetTransitionKindList() => new(builder.AddRequest("GetTransitionKindList", null)); /// - /// Appends a GetSceneTransitionList request to the batch. + /// Adds a GetSceneTransitionList request to the batch. /// Gets an array of all scene transitions in OBS. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetSceneTransitionList() => Add("GetSceneTransitionList", null); + /// A reference used to read this request's result. + public BatchRef GetSceneTransitionList() => new(builder.AddRequest("GetSceneTransitionList", null)); /// - /// Appends a GetCurrentSceneTransition request to the batch. + /// Adds a GetCurrentSceneTransition request to the batch. /// Gets information about the current scene transition. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetCurrentSceneTransition() => Add("GetCurrentSceneTransition", null); + /// A reference used to read this request's result. + public BatchRef GetCurrentSceneTransition() => new(builder.AddRequest("GetCurrentSceneTransition", null)); /// - /// Appends a SetCurrentSceneTransition request to the batch. + /// Adds a SetCurrentSceneTransition request to the batch. /// Sets the current scene transition. Small note: While the namespace of scene transitions is generally unique, that uniqueness is not a guarantee as it is with other resources like inputs. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentSceneTransition(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneTransitionRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentSceneTransition(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneTransitionRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentSceneTransition", requestData); + return new(builder.AddRequest("SetCurrentSceneTransition", requestData)); } /// - /// Appends a SetCurrentSceneTransitionDuration request to the batch. + /// Adds a SetCurrentSceneTransitionDuration request to the batch. /// Sets the duration of the current scene transition, if it is not fixed. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentSceneTransitionDuration(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneTransitionDurationRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentSceneTransitionDuration(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneTransitionDurationRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentSceneTransitionDuration", requestData); + return new(builder.AddRequest("SetCurrentSceneTransitionDuration", requestData)); } /// - /// Appends a SetCurrentSceneTransitionSettings request to the batch. + /// Adds a SetCurrentSceneTransitionSettings request to the batch. /// Sets the settings of the current scene transition. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetCurrentSceneTransitionSettings(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneTransitionSettingsRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetCurrentSceneTransitionSettings(ObsWebSocket.Core.Protocol.Requests.SetCurrentSceneTransitionSettingsRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetCurrentSceneTransitionSettings", requestData); + return new(builder.AddRequest("SetCurrentSceneTransitionSettings", requestData)); } /// - /// Appends a GetCurrentSceneTransitionCursor request to the batch. + /// Adds a GetCurrentSceneTransitionCursor request to the batch. /// Gets the cursor position of the current scene transition. Note: `transitionCursor` will return 1.0 when the transition is inactive. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetCurrentSceneTransitionCursor() => Add("GetCurrentSceneTransitionCursor", null); + /// A reference used to read this request's result. + public BatchRef GetCurrentSceneTransitionCursor() => new(builder.AddRequest("GetCurrentSceneTransitionCursor", null)); /// - /// Appends a TriggerStudioModeTransition request to the batch. + /// Adds a TriggerStudioModeTransition request to the batch. /// Triggers the current scene transition. Same functionality as the `Transition` button in studio mode. /// - /// The same builder, for chaining. - public ObsBatchBuilder TriggerStudioModeTransition() => Add("TriggerStudioModeTransition", null); + /// A reference used to read this request's result. + public BatchRef TriggerStudioModeTransition() => new(builder.AddRequest("TriggerStudioModeTransition", null)); /// - /// Appends a SetTBarPosition request to the batch. + /// Adds a SetTBarPosition request to the batch. /// Sets the position of the TBar. **Very important note**: This will be deprecated and replaced in a future version of obs-websocket. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetTBarPosition(ObsWebSocket.Core.Protocol.Requests.SetTBarPositionRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetTBarPosition(ObsWebSocket.Core.Protocol.Requests.SetTBarPositionRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetTBarPosition", requestData); + return new(builder.AddRequest("SetTBarPosition", requestData)); } +} + +/// +/// Batch requests in the ui category. +/// +/// The batch being built. +public readonly struct UiBatchGroup(ObsBatchBuilder builder) +{ /// - /// Appends a GetStudioModeEnabled request to the batch. + /// Adds a GetStudioModeEnabled request to the batch. /// Gets whether studio is enabled. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetStudioModeEnabled() => Add("GetStudioModeEnabled", null); + /// A reference used to read this request's result. + public BatchRef GetStudioModeEnabled() => new(builder.AddRequest("GetStudioModeEnabled", null)); /// - /// Appends a SetStudioModeEnabled request to the batch. + /// Adds a SetStudioModeEnabled request to the batch. /// Enables or disables studio mode /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder SetStudioModeEnabled(ObsWebSocket.Core.Protocol.Requests.SetStudioModeEnabledRequestData requestData) + /// A reference used to read this request's result. + public BatchRef SetStudioModeEnabled(ObsWebSocket.Core.Protocol.Requests.SetStudioModeEnabledRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("SetStudioModeEnabled", requestData); + return new(builder.AddRequest("SetStudioModeEnabled", requestData)); } /// - /// Appends a OpenInputPropertiesDialog request to the batch. + /// Adds a OpenInputPropertiesDialog request to the batch. /// Opens the properties dialog of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder OpenInputPropertiesDialog(ObsWebSocket.Core.Protocol.Requests.OpenInputPropertiesDialogRequestData requestData) + /// A reference used to read this request's result. + public BatchRef OpenInputPropertiesDialog(ObsWebSocket.Core.Protocol.Requests.OpenInputPropertiesDialogRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("OpenInputPropertiesDialog", requestData); + return new(builder.AddRequest("OpenInputPropertiesDialog", requestData)); } /// - /// Appends a OpenInputFiltersDialog request to the batch. + /// Adds a OpenInputFiltersDialog request to the batch. /// Opens the filters dialog of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder OpenInputFiltersDialog(ObsWebSocket.Core.Protocol.Requests.OpenInputFiltersDialogRequestData requestData) + /// A reference used to read this request's result. + public BatchRef OpenInputFiltersDialog(ObsWebSocket.Core.Protocol.Requests.OpenInputFiltersDialogRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("OpenInputFiltersDialog", requestData); + return new(builder.AddRequest("OpenInputFiltersDialog", requestData)); } /// - /// Appends a OpenInputInteractDialog request to the batch. + /// Adds a OpenInputInteractDialog request to the batch. /// Opens the interact dialog of an input. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder OpenInputInteractDialog(ObsWebSocket.Core.Protocol.Requests.OpenInputInteractDialogRequestData requestData) + /// A reference used to read this request's result. + public BatchRef OpenInputInteractDialog(ObsWebSocket.Core.Protocol.Requests.OpenInputInteractDialogRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("OpenInputInteractDialog", requestData); + return new(builder.AddRequest("OpenInputInteractDialog", requestData)); } /// - /// Appends a GetMonitorList request to the batch. + /// Adds a GetMonitorList request to the batch. /// Gets a list of connected monitors and information about them. /// - /// The same builder, for chaining. - public ObsBatchBuilder GetMonitorList() => Add("GetMonitorList", null); + /// A reference used to read this request's result. + public BatchRef GetMonitorList() => new(builder.AddRequest("GetMonitorList", null)); /// - /// Appends a OpenVideoMixProjector request to the batch. + /// Adds a OpenVideoMixProjector request to the batch. /// Opens a projector for a specific output video mix. Mix types: - `OBS_WEBSOCKET_VIDEO_MIX_TYPE_PREVIEW` - `OBS_WEBSOCKET_VIDEO_MIX_TYPE_PROGRAM` - `OBS_WEBSOCKET_VIDEO_MIX_TYPE_MULTIVIEW` Note: This request serves to provide feature parity with 4.x. It is very likely to be changed/deprecated in a future release. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder OpenVideoMixProjector(ObsWebSocket.Core.Protocol.Requests.OpenVideoMixProjectorRequestData requestData) + /// A reference used to read this request's result. + public BatchRef OpenVideoMixProjector(ObsWebSocket.Core.Protocol.Requests.OpenVideoMixProjectorRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("OpenVideoMixProjector", requestData); + return new(builder.AddRequest("OpenVideoMixProjector", requestData)); } /// - /// Appends a OpenSourceProjector request to the batch. + /// Adds a OpenSourceProjector request to the batch. /// Opens a projector for a source. Note: This request serves to provide feature parity with 4.x. It is very likely to be changed/deprecated in a future release. /// - /// The same builder, for chaining. /// The payload for this request. - public ObsBatchBuilder OpenSourceProjector(ObsWebSocket.Core.Protocol.Requests.OpenSourceProjectorRequestData requestData) + /// A reference used to read this request's result. + public BatchRef OpenSourceProjector(ObsWebSocket.Core.Protocol.Requests.OpenSourceProjectorRequestData requestData) { ArgumentNullException.ThrowIfNull(requestData); - return Add("OpenSourceProjector", requestData); + return new(builder.AddRequest("OpenSourceProjector", requestData)); } } + +public sealed partial class ObsBatchBuilder +{ + /// + /// Requests in the canvases category. + /// + public CanvasesBatchGroup Canvases => new(this); + + /// + /// Requests in the config category. + /// + public ConfigBatchGroup Config => new(this); + + /// + /// Requests in the filters category. + /// + public FiltersBatchGroup Filters => new(this); + + /// + /// Requests in the general category. + /// + public GeneralBatchGroup General => new(this); + + /// + /// Requests in the inputs category. + /// + public InputsBatchGroup Inputs => new(this); + + /// + /// Requests in the media inputs category. + /// + public MediaInputsBatchGroup MediaInputs => new(this); + + /// + /// Requests in the outputs category. + /// + public OutputsBatchGroup Outputs => new(this); + + /// + /// Requests in the record category. + /// + public RecordBatchGroup Record => new(this); + + /// + /// Requests in the scene items category. + /// + public SceneItemsBatchGroup SceneItems => new(this); + + /// + /// Requests in the scenes category. + /// + public ScenesBatchGroup Scenes => new(this); + + /// + /// Requests in the sources category. + /// + public SourcesBatchGroup Sources => new(this); + + /// + /// Requests in the stream category. + /// + public StreamBatchGroup Stream => new(this); + + /// + /// Requests in the transitions category. + /// + public TransitionsBatchGroup Transitions => new(this); + + /// + /// Requests in the ui category. + /// + public UiBatchGroup Ui => new(this); + +} diff --git a/ObsWebSocket.Core/ObsBatchBuilder.cs b/ObsWebSocket.Core/ObsBatchBuilder.cs index 7840b62..92bcf93 100644 --- a/ObsWebSocket.Core/ObsBatchBuilder.cs +++ b/ObsWebSocket.Core/ObsBatchBuilder.cs @@ -12,6 +12,7 @@ namespace ObsWebSocket.Core; /// The generated methods are conveniences over . Anything they do /// not cover can still be added with , and /// still accepts a plain list. +/// Not thread safe. Build a batch on one thread, or give each thread its own builder. /// public sealed partial class ObsBatchBuilder { @@ -74,8 +75,23 @@ public ObsBatchBuilder Add(string requestType, T requestData, JsonTypeInfo return this; } + /// + /// Appends a request and returns its position, which the generated group methods wrap in a + /// . + /// + /// The OBS request type string. + /// The request payload, or . + /// The position of the appended request. + public int AddRequest(string requestType, object? requestData) + { + ArgumentException.ThrowIfNullOrEmpty(requestType); + _items.Add(new BatchRequestItem(requestType, requestData)); + return _items.Count - 1; + } + /// /// Returns the accumulated items as the list takes. /// public List Build() => [.. _items]; + } diff --git a/ObsWebSocket.Core/ObsWebSocket.Core.csproj b/ObsWebSocket.Core/ObsWebSocket.Core.csproj index 4cd0a12..d3f8113 100644 --- a/ObsWebSocket.Core/ObsWebSocket.Core.csproj +++ b/ObsWebSocket.Core/ObsWebSocket.Core.csproj @@ -1,15 +1,4 @@  - - - $(NoWarn);LOGGEN036 - -