diff --git a/OBS.cs b/OBS.cs new file mode 100644 index 0000000..e82d390 --- /dev/null +++ b/OBS.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/PowerPointToOBSSceneSwitcher.csproj b/PowerPointToOBSSceneSwitcher.csproj new file mode 100644 index 0000000..75b9f85 --- /dev/null +++ b/PowerPointToOBSSceneSwitcher.csproj @@ -0,0 +1,24 @@ + + + + Exe + netcoreapp3.1 + + + + + {91493440-5a91-11cf-8700-00aa0060263b} + 2 + 12 + primary + 0 + false + True + + + + + + + + diff --git a/PowerPointToOBSSceneSwitcher.sln b/PowerPointToOBSSceneSwitcher.sln new file mode 100644 index 0000000..e2cad97 --- /dev/null +++ b/PowerPointToOBSSceneSwitcher.sln @@ -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 diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..bd69277 --- /dev/null +++ b/Program.cs @@ -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); + } + } + } + } +} \ No newline at end of file