diff --git a/Program.cs b/Program.cs index 57f17a1..cb96ef8 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Office.Interop.PowerPoint; //Thanks to CSharpFritz and EngstromJimmy for their gists, snippets, and thoughts. @@ -10,17 +11,21 @@ class Program { private static Application ppt = new Microsoft.Office.Interop.PowerPoint.Application(); private static OscLocal OSC; + private static List OSCCommands = new List(); // List of OSC commands in a slide + private static int slideClick; // hold the nb of clicks in a given slide static async Task Main(string[] args) { Console.Write("Connecting to PowerPoint..."); ppt.SlideShowNextSlide += App_SlideShowNextSlide; ppt.SlideShowNextClick += App_SlideShowNextClick; + ppt.SlideShowOnNext += App_SlideShowOnNext; + ppt.SlideShowOnPrevious += App_SlideShowOnPrevious; Console.WriteLine("Connected. Ready to send OSC commands."); OSC = new OscLocal(); Console.ReadLine(); } - // Future use: multiple OSC command, associated to Animations in a single slide + // Future use async static void App_SlideShowNextClick(SlideShowWindow Wn, Effect effect) { if (Wn != null) @@ -33,6 +38,37 @@ async static void App_SlideShowNextClick(SlideShowWindow Wn, Effect effect) } } + // Clicked next on current slide + async static void App_SlideShowOnNext(SlideShowWindow Wn) + { + if (Wn != null) + { + Console.WriteLine($" Next click on current slide"); + slideClick++; + if (OSCCommands.Count > slideClick) + { + OSC.sendOSC(OSCCommands[slideClick]); + } + + } + } + + // Clicked previous on current slide + async static void App_SlideShowOnPrevious(SlideShowWindow Wn) + { + if (Wn != null) + { + Console.WriteLine($" Prev click on current slide"); + if (slideClick>0) slideClick--; + if (OSCCommands.Count > slideClick) + { + OSC.sendOSC(OSCCommands[slideClick]); + } + + } + } + + // Next slide async static void App_SlideShowNextSlide(SlideShowWindow Wn) { if (Wn != null) @@ -40,11 +76,12 @@ async static void App_SlideShowNextSlide(SlideShowWindow Wn) Console.WriteLine($"Moved to Slide Number {Wn.View.Slide.SlideNumber}"); //Text starts at Index 2 ¯\_(ツ)_/¯ var note = String.Empty; + OSCCommands.Clear(); // Start with a fresh list of commands on new slide + slideClick = 0; try { note = Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text; } catch { /*no notes*/ } - bool oscCommandHandled = false; - + bool oscCommandHandled = false; // Only handle the 1st command on slide change var notereader = new StringReader(note); string line; @@ -53,10 +90,9 @@ async static void App_SlideShowNextSlide(SlideShowWindow Wn) if (line.StartsWith("OSC:")) { line = line.Substring(4).Trim(); - + OSCCommands.Add(line); // Add OSC command to the list of commands in that slide if (!oscCommandHandled) { - // Console.WriteLine($"Found OSC command in slide: \"{line}\""); try { oscCommandHandled = OSC.sendOSC(line); @@ -66,10 +102,6 @@ async static void App_SlideShowNextSlide(SlideShowWindow Wn) Console.WriteLine($" ERROR: {ex.Message.ToString()}"); } } - else - { - Console.WriteLine($" WARNING: Multiple OSC commands found. I used the first and have ignored \"{line}\""); - } } if (line.StartsWith("OSCHOST:"))