Skip to content

Commit 962bfb1

Browse files
authored
Merge pull request #67 from Etuldan/feature/show-scene-in-groups
Items in groups available to be manipulated
2 parents 932b72f + c49021d commit 962bfb1

File tree

3 files changed

+156
-8
lines changed

3 files changed

+156
-8
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Newtonsoft.Json;
2+
3+
namespace MidiControl.Models.OBS
4+
{
5+
public class SceneItemTransform
6+
{
7+
[JsonProperty("alignment")]
8+
public int alignment { get; set; }
9+
10+
[JsonProperty("boundsAlignment")]
11+
public int boundsAlignment { get; set; }
12+
13+
[JsonProperty("boundsHeight")]
14+
public double boundsHeight { get; set; }
15+
16+
[JsonProperty("boundsType")]
17+
public string boundsType { get; set; }
18+
19+
[JsonProperty("boundsWidth")]
20+
public double boundsWidth { get; set; }
21+
22+
[JsonProperty("cropBottom")]
23+
public int cropBottom { get; set; }
24+
25+
[JsonProperty("cropLeft")]
26+
public int cropLeft { get; set; }
27+
28+
[JsonProperty("cropRight")]
29+
public int cropRight { get; set; }
30+
31+
[JsonProperty("cropTop")]
32+
public int cropTop { get; set; }
33+
34+
[JsonProperty("height")]
35+
public double height { get; set; }
36+
37+
[JsonProperty("positionX")]
38+
public double positionX { get; set; }
39+
40+
[JsonProperty("positionY")]
41+
public double positionY { get; set; }
42+
43+
[JsonProperty("rotation")]
44+
public double rotation { get; set; }
45+
46+
[JsonProperty("scaleX")]
47+
public double scaleX { get; set; }
48+
49+
[JsonProperty("scaleY")]
50+
public double scaleY { get; set; }
51+
52+
[JsonProperty("sourceHeight")]
53+
public double sourceHeight { get; set; }
54+
55+
[JsonProperty("sourceWidth")]
56+
public double sourceWidth { get; set; }
57+
58+
[JsonProperty("width")]
59+
public double width { get; set; }
60+
}
61+
}

MidiControl/Models/OBS/Source.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Newtonsoft.Json;
2+
3+
namespace MidiControl.Models.OBS
4+
{
5+
public class Source
6+
{
7+
[JsonProperty("inputKind")]
8+
public string inputKind { get; set; }
9+
10+
[JsonProperty("isGroup")]
11+
public object isGroup { get; set; }
12+
13+
[JsonProperty("sceneItemBlendMode")]
14+
public string sceneItemBlendMode { get; set; }
15+
16+
[JsonProperty("sceneItemEnabled")]
17+
public bool sceneItemEnabled { get; set; }
18+
19+
[JsonProperty("sceneItemId")]
20+
public int sceneItemId { get; set; }
21+
22+
[JsonProperty("sceneItemIndex")]
23+
public int sceneItemIndex { get; set; }
24+
25+
[JsonProperty("sceneItemLocked")]
26+
public bool sceneItemLocked { get; set; }
27+
28+
[JsonProperty("sceneItemTransform")]
29+
public SceneItemTransform sceneItemTransform { get; set; }
30+
31+
[JsonProperty("sourceName")]
32+
public string sourceName { get; set; }
33+
34+
[JsonProperty("sourceType")]
35+
public string sourceType { get; set; }
36+
}
37+
}

MidiControl/OBSControl.cs

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using Microsoft.VisualBasic.FileIO;
99
using System.Threading.Tasks;
1010
using System.IO;
11+
using Newtonsoft.Json;
12+
using MidiControl.Models.OBS;
1113

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

411413
foreach(SceneBasicInfo scene in scenes) {
412-
foreach(var item in obs.GetSceneItemList(scene.Name)) {
414+
foreach(var item in obs.GetSceneItemList(scene.Name)) {
413415
if(sources.Contains(item.SourceName)) {
414-
sourcesName.Add(new SourceScene() { Source = item.SourceName, Scene = scene.Name }, obs.GetSourceActive(item.SourceName).VideoShowing);
415-
}
416-
}
417-
}
418-
foreach(var entry in sourcesName) {
416+
sourcesName.Add(new SourceScene() { Source = item.SourceName, Scene = scene.Name }, obs.GetSourceActive(item.SourceName).VideoShowing);
417+
}
418+
}
419+
}
420+
421+
// Groups
422+
var groups = obs.GetGroupList();
423+
foreach (var group in groups)
424+
{
425+
var request = new JObject
426+
{
427+
{ "sceneName", group}
428+
};
429+
var result = obs.SendRequest("GetGroupSceneItemList", request)["sceneItems"].ToString();
430+
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
431+
foreach (var groupElement in groupElements.Where(element => sources.Contains(element.sourceName)))
432+
{
433+
sourcesName.Add(new SourceScene() { Source = groupElement.sourceName, Scene = group }, obs.GetSourceActive(groupElement.sourceName).VideoShowing);
434+
}
435+
}
436+
437+
foreach(var entry in sourcesName) {
419438
var sceneItemId = obs.GetSceneItemId(entry.Key.Scene, entry.Key.Source, 0);
420439
obs.SetSceneItemEnabled(entry.Key.Scene, sceneItemId, !entry.Value);
421440
if(entry.Value == false) {
@@ -457,7 +476,23 @@ private void ShowSources(List<string> sources, bool show) {
457476
}
458477
}
459478

460-
foreach(SourceScene sourcescene in sourcesName) {
479+
// Groups
480+
var groups = obs.GetGroupList();
481+
foreach (var group in groups)
482+
{
483+
var request = new JObject
484+
{
485+
{ "sceneName", group}
486+
};
487+
var result = obs.SendRequest("GetGroupSceneItemList", request)["sceneItems"].ToString();
488+
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
489+
foreach (var groupElement in groupElements.Where(element => sources.Contains(element.sourceName)))
490+
{
491+
sourcesName.Add(new SourceScene() { Source = groupElement.sourceName, Scene = group });
492+
}
493+
}
494+
495+
foreach (var sourcescene in sourcesName) {
461496
var sceneItemId = obs.GetSceneItemId(sourcescene.Scene, sourcescene.Source, 0);
462497
obs.SetSceneItemEnabled(sourcescene.Scene, sceneItemId, show);
463498
}
@@ -580,7 +615,22 @@ public List<string> GetSources() {
580615
}
581616
}
582617

583-
sourceString.Sort((x, y) => string.Compare(x, y));
618+
var groups = obs.GetGroupList();
619+
foreach(var group in groups)
620+
{
621+
var request = new JObject
622+
{
623+
{ "sceneName", group}
624+
};
625+
var result = obs.SendRequest("GetGroupSceneItemList", request)["sceneItems"].ToString();
626+
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
627+
foreach (var groupElement in groupElements)
628+
{
629+
sourceString.Add(groupElement.sourceName);
630+
}
631+
}
632+
633+
sourceString.Sort((x, y) => string.Compare(x, y));
584634
return sourceString.Distinct().ToList();
585635
}
586636
public List<string> GetTransitions() {

0 commit comments

Comments
 (0)