Skip to content

Commit

Permalink
Handle animations within one slide
Browse files Browse the repository at this point in the history
  • Loading branch information
ojacques committed Nov 20, 2021
1 parent 820148e commit 1797b77
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -10,17 +11,21 @@ class Program
{
private static Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
private static OscLocal OSC;
private static List<string> OSCCommands = new List<string>(); // 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)
Expand All @@ -33,18 +38,50 @@ 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)
{
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;
Expand All @@ -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);
Expand All @@ -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:"))
Expand Down

0 comments on commit 1797b77

Please sign in to comment.