Skip to content

Commit

Permalink
Merge pull request #67 from Etuldan/feature/show-scene-in-groups
Browse files Browse the repository at this point in the history
Items in groups available to be manipulated
  • Loading branch information
Etuldan authored May 17, 2023
2 parents 932b72f + c49021d commit 962bfb1
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 8 deletions.
61 changes: 61 additions & 0 deletions MidiControl/Models/OBS/SceneItemTransform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Newtonsoft.Json;

namespace MidiControl.Models.OBS
{
public class SceneItemTransform
{
[JsonProperty("alignment")]
public int alignment { get; set; }

[JsonProperty("boundsAlignment")]
public int boundsAlignment { get; set; }

[JsonProperty("boundsHeight")]
public double boundsHeight { get; set; }

[JsonProperty("boundsType")]
public string boundsType { get; set; }

[JsonProperty("boundsWidth")]
public double boundsWidth { get; set; }

[JsonProperty("cropBottom")]
public int cropBottom { get; set; }

[JsonProperty("cropLeft")]
public int cropLeft { get; set; }

[JsonProperty("cropRight")]
public int cropRight { get; set; }

[JsonProperty("cropTop")]
public int cropTop { get; set; }

[JsonProperty("height")]
public double height { get; set; }

[JsonProperty("positionX")]
public double positionX { get; set; }

[JsonProperty("positionY")]
public double positionY { get; set; }

[JsonProperty("rotation")]
public double rotation { get; set; }

[JsonProperty("scaleX")]
public double scaleX { get; set; }

[JsonProperty("scaleY")]
public double scaleY { get; set; }

[JsonProperty("sourceHeight")]
public double sourceHeight { get; set; }

[JsonProperty("sourceWidth")]
public double sourceWidth { get; set; }

[JsonProperty("width")]
public double width { get; set; }
}
}
37 changes: 37 additions & 0 deletions MidiControl/Models/OBS/Source.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Newtonsoft.Json;

namespace MidiControl.Models.OBS
{
public class Source
{
[JsonProperty("inputKind")]
public string inputKind { get; set; }

[JsonProperty("isGroup")]
public object isGroup { get; set; }

[JsonProperty("sceneItemBlendMode")]
public string sceneItemBlendMode { get; set; }

[JsonProperty("sceneItemEnabled")]
public bool sceneItemEnabled { get; set; }

[JsonProperty("sceneItemId")]
public int sceneItemId { get; set; }

[JsonProperty("sceneItemIndex")]
public int sceneItemIndex { get; set; }

[JsonProperty("sceneItemLocked")]
public bool sceneItemLocked { get; set; }

[JsonProperty("sceneItemTransform")]
public SceneItemTransform sceneItemTransform { get; set; }

[JsonProperty("sourceName")]
public string sourceName { get; set; }

[JsonProperty("sourceType")]
public string sourceType { get; set; }
}
}
66 changes: 58 additions & 8 deletions MidiControl/OBSControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.VisualBasic.FileIO;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
using MidiControl.Models.OBS;

namespace MidiControl {
public class OBSControl : IExternalControl {
Expand Down Expand Up @@ -409,13 +411,30 @@ private void ToggleSources(MIDIFeedback feedback, List<string> sources) {
var state = false;

foreach(SceneBasicInfo scene in scenes) {
foreach(var item in obs.GetSceneItemList(scene.Name)) {
foreach(var item in obs.GetSceneItemList(scene.Name)) {
if(sources.Contains(item.SourceName)) {
sourcesName.Add(new SourceScene() { Source = item.SourceName, Scene = scene.Name }, obs.GetSourceActive(item.SourceName).VideoShowing);
}
}
}
foreach(var entry in sourcesName) {
sourcesName.Add(new SourceScene() { Source = item.SourceName, Scene = scene.Name }, obs.GetSourceActive(item.SourceName).VideoShowing);
}
}
}

// Groups
var groups = obs.GetGroupList();
foreach (var group in groups)
{
var request = new JObject
{
{ "sceneName", group}
};
var result = obs.SendRequest("GetGroupSceneItemList", request)["sceneItems"].ToString();
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
foreach (var groupElement in groupElements.Where(element => sources.Contains(element.sourceName)))
{
sourcesName.Add(new SourceScene() { Source = groupElement.sourceName, Scene = group }, obs.GetSourceActive(groupElement.sourceName).VideoShowing);
}
}

foreach(var entry in sourcesName) {
var sceneItemId = obs.GetSceneItemId(entry.Key.Scene, entry.Key.Source, 0);
obs.SetSceneItemEnabled(entry.Key.Scene, sceneItemId, !entry.Value);
if(entry.Value == false) {
Expand Down Expand Up @@ -457,7 +476,23 @@ private void ShowSources(List<string> sources, bool show) {
}
}

foreach(SourceScene sourcescene in sourcesName) {
// Groups
var groups = obs.GetGroupList();
foreach (var group in groups)
{
var request = new JObject
{
{ "sceneName", group}
};
var result = obs.SendRequest("GetGroupSceneItemList", request)["sceneItems"].ToString();
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
foreach (var groupElement in groupElements.Where(element => sources.Contains(element.sourceName)))
{
sourcesName.Add(new SourceScene() { Source = groupElement.sourceName, Scene = group });
}
}

foreach (var sourcescene in sourcesName) {
var sceneItemId = obs.GetSceneItemId(sourcescene.Scene, sourcescene.Source, 0);
obs.SetSceneItemEnabled(sourcescene.Scene, sceneItemId, show);
}
Expand Down Expand Up @@ -580,7 +615,22 @@ public List<string> GetSources() {
}
}

sourceString.Sort((x, y) => string.Compare(x, y));
var groups = obs.GetGroupList();
foreach(var group in groups)
{
var request = new JObject
{
{ "sceneName", group}
};
var result = obs.SendRequest("GetGroupSceneItemList", request)["sceneItems"].ToString();
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
foreach (var groupElement in groupElements)
{
sourceString.Add(groupElement.sourceName);
}
}

sourceString.Sort((x, y) => string.Compare(x, y));
return sourceString.Distinct().ToList();
}
public List<string> GetTransitions() {
Expand Down

0 comments on commit 962bfb1

Please sign in to comment.