static int IntToEnum(IntPtr L) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); EShowMode o = (EShowMode)arg0; ToLua.Push(L, o); return(1); }
/// <summary> /// 设置固定界面的属性 /// </summary> /// <param name="order"></param> /// <param name="mode"></param> /// <param name="collider"></param> public void SetFixPage(int order, EShowMode mode, ECollider collider) { context = new PageContext(); context.pageType = EPageType.Fixed; context.order = order; context.showMode = mode; context.collider = collider; }
static int SetPage(IntPtr L) { try { ToLua.CheckArgsCount(L, 4); UIPage obj = (UIPage)ToLua.CheckObject(L, 1, typeof(UIPage)); EPageType arg0 = (EPageType)ToLua.CheckObject(L, 2, typeof(EPageType)); EShowMode arg1 = (EShowMode)ToLua.CheckObject(L, 3, typeof(EShowMode)); ECollider arg2 = (ECollider)ToLua.CheckObject(L, 4, typeof(ECollider)); obj.SetPage(arg0, arg1, arg2); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static void Main(string[] args) { #if DEBUG // Debugging arguments args = new string[] { "debug" }; #endif // Cancel if no function is given if (args.Length == 0) { Console.Write("No function given. Use -h or help for available functions and usage and make sure Streamlabs OBS is running."); return; } // Read config from IP file string address = null; try { var exeloc = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); XDocument xml = XDocument.Load(Path.Combine(exeloc, "config.xml")); var q = xml.Root.Descendants("ipaddress"); foreach (string ip in q) { address = ip; } } catch (Exception e) { address = "127.0.0.1"; Console.Write(e); } // Control result ControlStatus result; // Connect to SLOBS var connection = new SLOBSConnection(address); var status = connection.Connect(); if (!status.Status) { Console.WriteLine(status.Message); return; } // function switch (args[0].ToLower()) { #region Help case "-h": case "help": Console.WriteLine("STREAMLABS OBS CONTROL BRIDGE APPLICATION."); Console.WriteLine(); Console.WriteLine("function\t\t\t[argument...]"); Console.WriteLine("---------------------------------------------"); Console.WriteLine("change_scene\t\t\tscene_name [delay]"); Console.WriteLine("swap_scenes\t\t\tscene_name delay [scene_name]"); Console.WriteLine(); Console.WriteLine("visibility_source_active\tsource_name [on|off]"); Console.WriteLine("tvisibility_source_active\tsource_name delay [on|onoff|off|offon]"); Console.WriteLine(); Console.WriteLine("visibility_source_scene\t\tsource_name scene_name [on|off]"); Console.WriteLine("tvisibility_source_scene\tsource_name scene_name delay [on|onoff|off|offon]"); Console.WriteLine(); Console.WriteLine("visibility_folder_active\tfolder_name [on|off]"); Console.WriteLine("tvisibility_folder_active\tfolder_name delay [on|onoff|off|offon]"); Console.WriteLine(); Console.WriteLine("visibility_folder_scene\t\tfolder_name scene_name [on|off]"); Console.WriteLine("tvisibility_folder_scene\tfolder_name scene_name delay [on|onoff|off|offon]"); Console.WriteLine(); Console.WriteLine("start_streaming"); Console.WriteLine("stop_streaming"); Console.WriteLine(); Console.WriteLine("start_recording"); Console.WriteLine("stop_recording"); Console.WriteLine(); Console.WriteLine("start_replaybuffer"); Console.WriteLine("stop_replaybuffer"); Console.WriteLine("save_replaybuffer"); Console.WriteLine("save_replaybuffer_swap\t\tscene_name [duration-offset]"); Console.WriteLine(); Console.WriteLine(); break; #endregion #region Scenes /* change_scene scene_name [delay] */ case "change_scene": if (args.Length >= 2) { // Set delay int delay = 0; if (args.Length >= 3) { if (!int.TryParse(args[2], out delay)) { Console.Write("Warning: Delay for function change_scene is not a valid number, defaulting to 0 seconds."); } } // Swap to scene result = Control.ChangeToScene(connection, args[1], delay); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function change_scene."); } } else { Console.Write("Error: Insufficient arguments supplied for function change_scene."); } break; /* swap_scenes scene_name delay [scene_name] */ case "swap_scenes": if (args.Length >= 3) { // Set delay if (!int.TryParse(args[2], out int delay)) { Console.Write("Warning: Delay for function swap_scenes is not a valid number, defaulting to 5 seconds."); delay = 5; } // Set return scene if given string returnscene = (args.Length >= 4) ? args[3] : null; // Swap scene result = Control.SwapScenes(connection, args[1], delay, returnscene); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function swap_scenes."); } } else { Console.Write("Error: Insufficient arguments supplied for swap_scenes."); } break; #endregion #region Visibility Item Active /* visibility_source_active source_name [on|off] */ case "visibility_source_active": if (args.Length >= 2) { // Set visibility mode EShowMode mode = EShowMode.ON; if (args.Length >= 3) { switch (args[2].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; default: Console.Write("Warning: Show argument for function visibility_source_active not correct, use `on`, or `off`, defaulting to on."); break; } } // Set scene item visibility result = Control.VisibilitySceneItem(connection, args[1], mode, 0); if (!result.Success) { Console.Write($"Error: {result.Message} for function visibility_source_active."); } } else { Console.Write("Error: Insufficient arguments supplied for function visibility_source_active."); } break; /* tvisibility_source_active source_name delay [on|onoff|off|offon] */ case "tvisibility_source_active": if (args.Length >= 3) { // Set delay if (!int.TryParse(args[2], out int delay)) { Console.Write("Warning: Delay for function tvisibility_source_active is not a valid number, defaulting to 5 seconds."); delay = 5; } // Set visibility mode EShowMode mode = EShowMode.ONOFF; if (args.Length >= 4) { switch (args[3].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; case "onoff": mode = EShowMode.ONOFF; break; case "offon": mode = EShowMode.OFFON; break; default: Console.Write("Warning: Show argument for function tvisibility_source_active not correct, use `onoff`, `offon`, `on`, or `off`, defaulting to onoff."); break; } } // Set scene item visibility result = Control.VisibilitySceneItem(connection, args[1], mode, delay); if (!result.Success) { Console.Write($"Error: {result.Message} for function tvisibility_source_active"); } } else { Console.Write("Error: Insufficient arguments supplied for function tvisibility_source_active."); } break; #endregion #region Visibility Item Scene /* visibility_source_scene source_name scene_name [on|off] */ case "visibility_source_scene": if (args.Length >= 3) { // Set visibility mode EShowMode mode = EShowMode.ON; if (args.Length >= 4) { switch (args[3].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; default: Console.Write("Warning: Show argument for function visibility_source_scene not correct, use `on` or `off`, defaulting to on."); break; } } // Set scene item visibility result = Control.VisibilitySceneItem(connection, args[1], mode, 0, args[2]); if (!result.Success) { Console.Write($"Error: {result.Message} for function visibility_source_scene."); } } else { Console.Write("Error: Insufficient arguments supplied for function visibility_source_scene."); } break; /* tvisibility_source_scene source_name scene_name delay [on|onoff|off|offon] */ case "tvisibility_source_scene": if (args.Length >= 4) { // Set delay if (!int.TryParse(args[3], out int delay)) { Console.Write("Warning: Delay for function tvisibility_source_scene is not valid, defaulting to 5 seconds."); delay = 5; } // Set visibility mode EShowMode mode = EShowMode.ONOFF; if (args.Length >= 5) { switch (args[4].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; case "onoff": mode = EShowMode.ONOFF; break; case "offon": mode = EShowMode.OFFON; break; default: Console.Write("Warning: Show argument for function tvisibility_source_scene not correct, use `onoff`, `offon`, `on`, or `off`, defaulting to onoff."); break; } } // Set scene item visibility result = Control.VisibilitySceneItem(connection, args[1], mode, delay, args[2]); if (!result.Success) { Console.Write($"Error: {result.Message} for function tvisibility_source_scene."); } } else { Console.Write("Error: Insufficient arguments supplied for function tvisibility_source_scene."); } break; #endregion #region Visibility Folders Active /* visibility_folder_active folder_name [on|off] */ case "visibility_folder_active": if (args.Length >= 2) { // Set visibility mode EShowMode mode = EShowMode.ON; if (args.Length >= 3) { switch (args[2].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; default: Console.Write("Warning: Show argument for visibility_folder_active not correct, use `on`, or `off`, defaulting to on."); break; } } // Set scene folder visibility result = Control.VisibilitySceneFolder(connection, args[1], mode, 0); if (!result.Success) { Console.Write($"Error: {result.Message} for function visibility_folder_active."); } } else { Console.Write("Error: Insufficient arguments supplied for function visibility_folder_active."); } break; /* tvisibility_folder_active folder_name delay [on|onoff|off|offon] */ case "tvisibility_folder_active": if (args.Length >= 3) { // Set delay if (!int.TryParse(args[2], out int delay)) { Console.Write("Warning: Delay for function tvisibility_folder_active is not valid, defaulting to 5 seconds."); delay = 5; } // Set visibility mode EShowMode mode = EShowMode.ONOFF; if (args.Length >= 4) { switch (args[3].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; case "onoff": mode = EShowMode.ONOFF; break; case "offon": mode = EShowMode.OFFON; break; default: Console.Write("Warning: Show argument for function tvisibility_folder_active not correct, use `onoff`, `offon`, `on`, or `off`, defaulting to onoff."); break; } } // Set scene folder visibility result = Control.VisibilitySceneFolder(connection, args[1], mode, delay); if (!result.Success) { Console.Write($"Error: {result.Message} for function tvisibility_folder_active."); } } else { Console.Write("Error: Insufficient arguments supplied for function tvisibility_folder_active."); } break; #endregion #region Visibility Folders Scene /* visibility_folder_scene folder_name scene_name [on|off] */ case "visibility_folder_scene": if (args.Length >= 3) { // Set visibility mode EShowMode mode = EShowMode.ON; if (args.Length >= 4) { switch (args[3].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; default: Console.Write("Warning: Show argument for function visibility_folder_scene not correct, use `on` or `off`, defaulting to on."); break; } } // Set scene folder visibility result = Control.VisibilitySceneFolder(connection, args[1], mode, 0, args[2]); if (!result.Success) { Console.Write($"Error: {result.Message} for function visibility_folder_scene."); } } else { Console.Write("Error: Insufficient arguments supplied for function visibility_folder_scene."); } break; /* tvisibility_folder_scene folder_name scene_name delay [on|onoff|off|offon] */ case "tvisibility_folder_scene": if (args.Length >= 4) { // Set delay if (!int.TryParse(args[3], out int delay)) { Console.Write("Warning: Delay for function tvisibility_folder_scene is invalid, defaulting to 5 seconds."); delay = 5; } // Set visibility mode EShowMode mode = EShowMode.ONOFF; if (args.Length >= 5) { switch (args[4].ToLower()) { case "on": mode = EShowMode.ON; break; case "off": mode = EShowMode.OFF; break; case "onoff": mode = EShowMode.ONOFF; break; case "offon": mode = EShowMode.OFFON; break; default: Console.Write("Warning: Show argument for function tvisibility_folder_scene not correct, use `onoff`, `offon`, `on`, or `off`, defaulting to onoff."); break; } } // Set scene folder visibility result = Control.VisibilitySceneFolder(connection, args[1], mode, delay, args[2]); if (!result.Success) { Console.Write($"Error: {result.Message} for function tvisibility_folder_scene."); } } else { Console.Write("Error: Insufficient arguments supplied for function tvisibility_folder_scene."); } break; #endregion #region StreamlabsOBS States case "start_streaming": result = Control.StartStreaming(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function start_streaming."); } break; case "stop_streaming": result = Control.StopStreaming(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function stop_streaming."); } break; case "start_recording": result = Control.StartRecording(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function start_recording."); } break; case "stop_recording": result = Control.StopRecording(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function stop_recording."); } break; case "start_replaybuffer": result = Control.StartReplayBuffer(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function start_replaybuffer."); } break; case "stop_replaybuffer": result = Control.StopReplayBuffer(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function stop_replaybuffer."); } break; case "save_replaybuffer": result = Control.SaveReplayBuffer(connection); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function save_replaybuffer."); } break; /* save_replaybuffer_swap scene_name [duration-offset] */ case "save_replaybuffer_swap": if (args.Length >= 2) { int offset = 3; if (args.Length >= 3) { // Set duration-offset if (!int.TryParse(args[2], out offset)) { Console.Write("Warning: Duration-offset for function save_replaybuffer_swap is not a valid number, defaulting to 3 seconds."); } } // Save replay and swap to given replay scene result = Control.SaveReplayBufferSwapScenes(connection, args[1], offset); if (!result.Success) { Console.WriteLine($"Error: {result.Message} for function save_replaybuffer_swap."); } } else { Console.Write("Error: Insufficient arguments supplied for function save_replaybuffer_swap."); } break; #endregion #region Debug #if DEBUG case "debug": break; #endif #endregion default: Console.Write("Error: Function does not exist."); break; } // Close connection to SLOBS connection.Close(); }
/// <summary> /// Set the visibility of a folder in a targeted scene or current active scene if not given. /// </summary> /// <param name="con">IConnection connection to Streamlabs OBS.</param> /// <param name="folder">Targeted folder to set the visibility on.</param> /// <param name="mode">Visibility mode with delay between or before.</param> /// <param name="delay">Delay in miliseconds of the visibility mode.</param> /// <param name="scene">Scene name to find the targeted folder in.</param> /// <returns>ControlStatus success</returns> internal static ControlStatus VisibilitySceneFolder(IConnection con, string folder, EShowMode mode, int delay, string scene = null) { // Get targetd Scene or current active scene string sceneResourceId = null; if (scene == null) { // Get current Active scene resourceId sceneResourceId = new Request <SceneAPI>("activeScene", "ScenesService").GetResponse(con).Result.ResourceId; } else { // Get scenes in current active scene collection var scenes = new Request <List <SceneAPI> >("getScenes", "ScenesService").GetResponse(con); foreach (SceneAPI s in scenes.Result) { // Found targeted scene if (s.Name == scene) { sceneResourceId = s.ResourceId; break; } } // Targeted scene not found if (sceneResourceId == null) { SendNotification(con, $"Scene '{scene}' not found."); return(new ControlStatus { Success = false, Message = $"Scene '{scene}' not found" }); } } // Get all sceneItemFolders from targeted scene var folders = new Request <List <SceneItemFolderAPI> >("getFolders", sceneResourceId).GetResponse(con); // Find targeted folder by name foreach (SceneItemFolderAPI f in folders.Result) { // Found targeted folder if (f.Name == folder) { // Select everything in the targeted folder var selection = new Request <Selection>("getSelection", f.ResourceId).GetResponse(con).Result; // Set visibility of the selected items switch (mode) { /* TODO: return is not bool due to a bug in SLOBS external API */ case EShowMode.OFFON: new Request <object>("setVisibility", selection.ResourceId, new object[] { false }).GetResponse(con); Thread.Sleep(delay * 1000); new Request <object>("setVisibility", selection.ResourceId, new object[] { true }).GetResponse(con); break; case EShowMode.ONOFF: new Request <object>("setVisibility", selection.ResourceId, new object[] { true }).GetResponse(con); Thread.Sleep(delay * 1000); new Request <object>("setVisibility", selection.ResourceId, new object[] { false }).GetResponse(con); break; case EShowMode.OFF: if (delay > 0) { Thread.Sleep(delay * 1000); } new Request <object>("setVisibility", selection.ResourceId, new object[] { false }).GetResponse(con); break; case EShowMode.ON: if (delay > 0) { Thread.Sleep(delay * 1000); } new Request <object>("setVisibility", selection.ResourceId, new object[] { true }).GetResponse(con); break; } // Return success return(new ControlStatus { Success = true }); } } // Targeted folder not found if (scene == null) { SendNotification(con, $"Folder '{folder}' not found in current scene."); return(new ControlStatus { Success = false, Message = $"Folder '{folder}' not found in current scene" }); } else { SendNotification(con, $"Folder '{folder}' not found in scene '{scene}'."); return(new ControlStatus { Success = false, Message = $"Folder '{folder}' not found in scene '{scene}'" }); } }
/// <summary> /// Set the visibility of an item (source) in a targeted scene or current active scene if not given. /// </summary> /// <param name="con">IConnection connection to Streamlabs OBS.</param> /// <param name="item">Targeted item (source) to set the visibility on.</param> /// <param name="mode">Visibility mode with delay between or before.</param> /// <param name="delay">Delay in seconds of the visibility mode.</param> /// <param name="scene">Scene name to find the targeted item (source) in.</param> /// <returns>ControlStatus success</returns> internal static ControlStatus VisibilitySceneItem(IConnection con, string item, EShowMode mode, int delay, string scene = null) { // Get targetd Scene or current active scene string sceneResourceId = null; if (scene == null) { // Get current Active scene resourceId sceneResourceId = new Request <SceneAPI>("activeScene", "ScenesService").GetResponse(con).Result.ResourceId; } else { // Get scenes in current active scene collection var scenes = new Request <List <SceneAPI> >("getScenes", "ScenesService").GetResponse(con); foreach (SceneAPI s in scenes.Result) { // Found targeted scene if (s.Name == scene) { sceneResourceId = s.ResourceId; break; } } // Targeted scene not found if (sceneResourceId == null) { SendNotification(con, $"Scene '{scene}' not found."); return(new ControlStatus { Success = false, Message = $"Scene '{scene}' not found" }); } } // Get all sceneItems from targeted scene var items = new Request <List <SceneItemAPI> >("getItems", sceneResourceId).GetResponse(con); // Find targeted item by name // In items list instead using getSourcesByName and matching source id's foreach (SceneItemAPI i in items.Result) { // Found targeted item if (i.Name == item) { // Set visibility of the item switch (mode) { /* TODO: return is not bool due to a bug in SLOBS external API */ case EShowMode.OFFON: new Request <object>("setVisibility", i.ResourceId, new object[] { false }).GetResponse(con); Thread.Sleep(delay * 1000); new Request <object>("setVisibility", i.ResourceId, new object[] { true }).GetResponse(con); break; case EShowMode.ONOFF: new Request <object>("setVisibility", i.ResourceId, new object[] { true }).GetResponse(con); Thread.Sleep(delay * 1000); new Request <object>("setVisibility", i.ResourceId, new object[] { false }).GetResponse(con); break; case EShowMode.OFF: if (delay > 0) { Thread.Sleep(delay * 1000); } new Request <object>("setVisibility", i.ResourceId, new object[] { false }).GetResponse(con); break; case EShowMode.ON: if (delay > 0) { Thread.Sleep(delay * 1000); } new Request <object>("setVisibility", i.ResourceId, new object[] { true }).GetResponse(con); break; } // Return success return(new ControlStatus { Success = true }); } } // Targeted item not found if (scene == null) { SendNotification(con, $"Source '{item}' not found in current scene."); return(new ControlStatus { Success = false, Message = $"Source '{item}' not found in current scene" }); } else { SendNotification(con, $"Source '{item}' not found in scene '{scene}'."); return(new ControlStatus { Success = false, Message = $"Source '{item}' not found in scene '{scene}'" }); } }
/// <summary> /// 设置界面显示配置属性 /// </summary> /// <param name="type">类型</param> /// <param name="mode">显示模式</param> /// <param name="collider">碰撞模式</param> public void SetPage(EPageType type, EShowMode mode, ECollider collider) { context.pageType = type; context.showMode = mode; context.collider = collider; }