Skip to content

Commit 121ddd2

Browse files
committed
chore!: remove "SetAsProgram()"
1 parent f2223b6 commit 121ddd2

9 files changed

Lines changed: 44 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Console.WriteLine($"OBS {Obs.Version} initialized");
2727
using var scene = Obs.Scenes.Create("My Scene");
2828
using var monitor = MonitorCapture.FromPrimary();
2929
scene.AddSource(monitor);
30-
scene.SetAsProgram();
30+
Obs.SetOutputSource(scene);
31+
// Obs.SetOutputSource(1, scene); // ...or assign to a specific channel (0 = program output; 1-63 hold additional global sources)
3132
3233
// Set up and start recording
3334
using var recording = new RecordingOutput("My Recording")

samples/ObsKit.NET.Sample.Recording/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
// Create a scene with monitor capture
6262
using var scene = Obs.Scenes.Create("Recording Scene");
6363
scene.AddSource(monitorSource);
64-
scene.SetAsProgram(); // Set as the output source for recording
64+
Obs.SetOutputSource(scene); // program output
6565

6666
Console.WriteLine($"Scene created with {scene.ItemCount} source(s)");
6767

samples/ObsKit.NET.Sample.ReplayBuffer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
using var scene = Obs.Scenes.Create("Replay Scene");
4848
using var monitor = MonitorCapture.FromPrimary();
4949
scene.AddSource(monitor);
50-
scene.SetAsProgram(); // Set as the output source
50+
Obs.SetOutputSource(scene); // program output
5151

5252
Console.WriteLine($"Scene created with {scene.ItemCount} source(s)");
5353

samples/ObsKit.NET.Sample.Streaming/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
scene.AddSource(monitorSource);
5151
scene.AddSource(audioInput);
5252
scene.AddSource(audioOutput);
53-
scene.SetAsProgram();
53+
Obs.SetOutputSource(scene);
5454

5555
Console.WriteLine($"Scene created with {scene.ItemCount} source(s)\n");
5656

samples/ObsKit.NET.Sample.Webcam/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
// Build a scene with the webcam.
6868
using var scene = Obs.Scenes.Create("Webcam Scene");
6969
scene.AddSource(webcam);
70-
scene.SetAsProgram();
70+
Obs.SetOutputSource(scene);
7171

7272
Console.WriteLine($"Scene has {scene.ItemCount} source(s); canvas {canvasW}x{canvasH}\n");
7373

src/ObsKit.NET/Obs.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,39 @@ public static void SetOutputSource(uint channel, Source? source)
251251
ObsCore.obs_set_output_source(channel, handle);
252252
}
253253

254+
/// <summary>
255+
/// Sets a scene as an output channel's source. Channel 0 is the program output (what
256+
/// gets recorded/streamed). Pass null to clear the channel.
257+
/// </summary>
258+
/// <param name="channel">The output channel (0-63).</param>
259+
/// <param name="scene">The scene to assign, or null to clear the channel.</param>
260+
public static void SetOutputSource(uint channel, Scene? scene)
261+
{
262+
ThrowIfNotInitialized();
263+
264+
lock (_lock)
265+
{
266+
// Drop any plain-source tracking for this channel; scene cleanup is tracked on the scene.
267+
_channelSources.Remove(channel);
268+
}
269+
270+
if (scene != null)
271+
scene.AssignToChannel(channel);
272+
else
273+
ObsCore.obs_set_output_source(channel, ObsSourceHandle.Null);
274+
}
275+
276+
/// <summary>
277+
/// Sets a scene as the program output (channel 0) — what gets recorded and streamed.
278+
/// Shorthand for <see cref="SetOutputSource(uint, Scene?)"/> with channel 0.
279+
/// </summary>
280+
/// <param name="scene">The scene to make the program output.</param>
281+
public static void SetOutputSource(Scene scene)
282+
{
283+
ArgumentNullException.ThrowIfNull(scene);
284+
SetOutputSource(0, scene);
285+
}
286+
254287
/// <summary>
255288
/// Clears a source from an output channel.
256289
/// </summary>

src/ObsKit.NET/Scenes/Canvas.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void MoveScene(Scene scene)
156156

157157
/// <summary>
158158
/// Sets the scene rendered on this canvas (channel 0), like
159-
/// <c>Scene.SetAsProgram</c> does for the main canvas.
159+
/// <c>Obs.SetOutputSource</c> does for the main canvas.
160160
/// </summary>
161161
/// <param name="scene">The scene to render.</param>
162162
/// <param name="channel">The canvas channel (0-63).</param>

src/ObsKit.NET/Scenes/Scene.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,13 @@ public SceneItem this[int index]
347347
#endregion
348348

349349
/// <summary>
350-
/// Sets this scene as the program output (what gets recorded/streamed).
350+
/// Assigns this scene's source to an output channel and records the channel so it is
351+
/// cleared on disposal. Invoked by <see cref="Obs.SetOutputSource(uint, Scene?)"/>.
351352
/// </summary>
352-
/// <param name="channel">Output channel (0 = main, 1-5 = aux).</param>
353-
public void SetAsProgram(uint channel = 0)
353+
internal void AssignToChannel(uint channel)
354354
{
355355
var sourceHandle = ObsScene.obs_scene_get_source(Handle);
356356
ObsCore.obs_set_output_source(channel, sourceHandle);
357-
358-
// Track the channel so we can clear it on disposal
359357
_assignedChannel = channel;
360358
}
361359

src/ObsKit.NET/Sources/Transition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ObsKit.NET.Sources;
1010
///
1111
/// <para>A transition blends between two sub-sources. To use one as the program
1212
/// transition, assign it to an output channel with
13-
/// <see cref="ObsKit.NET.Obs.SetOutputSource"/>, seed the starting scene with
13+
/// <see cref="ObsKit.NET.Obs.SetOutputSource(uint, Source?)"/>, seed the starting scene with
1414
/// <see cref="Set(Scenes.Scene?)"/>, then animate to a new scene with
1515
/// <see cref="Start(Scenes.Scene, System.TimeSpan, Native.Types.ObsTransitionMode)"/>.</para>
1616
/// </summary>

0 commit comments

Comments
 (0)