-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8289a2d
commit 6933c8d
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using OBS.WebSocket.NET; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace PowerPointToOBSSceneSwitcher | ||
{ | ||
|
||
public class ObsLocal : IDisposable | ||
{ | ||
private bool _DisposedValue; | ||
private ObsWebSocket _OBS; | ||
|
||
public ObsLocal() { } | ||
|
||
public Task Connect() | ||
{ | ||
_OBS = new ObsWebSocket(); | ||
_OBS.Connect($"ws://127.0.0.1:4444", ""); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public bool ChangeScene(string scene) | ||
{ | ||
_OBS.Api.SetCurrentScene(scene); | ||
return true; | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!_DisposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
// TODO: dispose managed state (managed objects) | ||
} | ||
|
||
_OBS.Disconnect(); | ||
_OBS = null; | ||
_DisposedValue = true; | ||
} | ||
} | ||
|
||
~ObsLocal() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: false); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<COMReference Include="Microsoft.Office.Interop.PowerPoint"> | ||
<Guid>{91493440-5a91-11cf-8700-00aa0060263b}</Guid> | ||
<VersionMajor>2</VersionMajor> | ||
<VersionMinor>12</VersionMinor> | ||
<WrapperTool>primary</WrapperTool> | ||
<Lcid>0</Lcid> | ||
<Isolated>false</Isolated> | ||
<EmbedInteropTypes>True</EmbedInteropTypes> | ||
</COMReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OBS.WebSocket.NET" Version="4.7.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30428.66 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerPointToOBSSceneSwitcher", "PowerPointToOBSSceneSwitcher.csproj", "{8A844363-5A92-403B-90CD-BFCB30ED5054}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8A844363-5A92-403B-90CD-BFCB30ED5054}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8A844363-5A92-403B-90CD-BFCB30ED5054}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8A844363-5A92-403B-90CD-BFCB30ED5054}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8A844363-5A92-403B-90CD-BFCB30ED5054}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {515C02C0-0CF2-4890-A1FB-4D6A5F115CD6} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.Office.Interop.PowerPoint; | ||
//Thanks to CSharpFritz and EngstromJimmy for their gists, snippets, and thoughts. | ||
|
||
namespace PowerPointToOBSSceneSwitcher | ||
{ | ||
class Program | ||
{ | ||
private static Application ppt = new Microsoft.Office.Interop.PowerPoint.Application(); | ||
private static ObsLocal OBS; | ||
static async Task Main(string[] args) | ||
{ | ||
Console.Write("Connecting to PowerPoint..."); | ||
ppt.SlideShowNextSlide += App_SlideShowNextSlide; | ||
Console.WriteLine("connected"); | ||
|
||
Console.Write("Connecting to OBS..."); | ||
OBS = new ObsLocal(); | ||
await OBS.Connect(); | ||
Console.WriteLine("connected"); | ||
|
||
Console.ReadLine(); | ||
} | ||
|
||
async static void App_SlideShowNextSlide(SlideShowWindow Wn) | ||
{ | ||
if (Wn != null) | ||
{ | ||
Console.WriteLine($"Moved to Slide Number {Wn.View.Slide.SlideNumber}"); | ||
//Text starts at Index 2 ¯\_(ツ)_/¯ | ||
var note = String.Empty; | ||
try { note = Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text; } | ||
catch { /*no notes*/ } | ||
if (note.StartsWith("OBS:")) { | ||
note = new StringReader(note).ReadLine().Substring(4); | ||
Console.WriteLine($" Switching to OBS Scene named \"{note}\""); | ||
OBS.ChangeScene(note); | ||
} | ||
} | ||
} | ||
} | ||
} |