Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to net60 solution #68

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MidiControl/AudioControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public class AudioControl : IExternalControl
[DllImport("user32.dll")]
private static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);

private readonly Dictionary<KeyBindEntry, List<WaveOut>> WaveOuts = new Dictionary<KeyBindEntry, List<WaveOut>>();
private readonly Dictionary<KeyBindEntry, List<WaveOut>> WaveOuts = new();

public void MediaKey(MediaType type)
public static void MediaKey(MediaType type)
{
byte key;
switch (type)
Expand Down
10 changes: 5 additions & 5 deletions MidiControl/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Configuration
public string CurrentProfile;
public bool Unsaved = false;
private readonly MIDIControlGUI gui;
private static readonly Regex removeInvalidChars = new Regex($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()))}]",
private static readonly Regex removeInvalidChars = new($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()))}]",
RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant);

public Configuration(MIDIControlGUI gui, string initialProfile)
Expand Down Expand Up @@ -61,7 +61,7 @@ public string[] GetAllProfiles()
var filesEndingIn = Directory.EnumerateFiles(ConfFolder).Where(f => f.EndsWith(".json") && f.Contains("keybinds-"));
foreach(var item in filesEndingIn)
{
string test = Path.GetFileNameWithoutExtension(item).Substring("keybinds-".Length);
string test = Path.GetFileNameWithoutExtension(item)["keybinds-".Length..];
output.Add(test);
}

Expand Down Expand Up @@ -170,9 +170,9 @@ public class KeyBindEntry
public int Channel { get; set; }
public Event Input { get; set; }

public List<OBSCallBack> OBSCallBacksON = new List<OBSCallBack>();
public List<OBSCallBack> OBSCallBacksOFF = new List<OBSCallBack>();
public List<OBSCallBack> OBSCallBacksSlider = new List<OBSCallBack>();
public List<OBSCallBack> OBSCallBacksON = new();
public List<OBSCallBack> OBSCallBacksOFF = new();
public List<OBSCallBack> OBSCallBacksSlider = new();
public SoundCallBack SoundCallBack;
public MediaCallBack MediaCallBack;
public MediaCallBack MediaCallBackOFF;
Expand Down
6 changes: 3 additions & 3 deletions MidiControl/GoXLRControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class GoXLRControl : IExternalControl
{
private bool isConnected;
private IWebSocketConnection socket;
public static List<string> inputs = new List<string>(new string[] { "Mic", "Chat", "Music", "Game", "Console", "Line In", "System", "Samples" });
public static List<string> outputs = new List<string>(new string[] { "Headphones", "Broadcast Mix", "Line Out", "Chat Mic", "Sampler"});
private readonly Dictionary<string, MIDIFeedback> feedbackToggle = new Dictionary<string, MIDIFeedback>();
public static List<string> inputs = new(new string[] { "Mic", "Chat", "Music", "Game", "Console", "Line In", "System", "Samples" });
public static List<string> outputs = new(new string[] { "Headphones", "Broadcast Mix", "Line Out", "Chat Mic", "Sampler"});
private readonly Dictionary<string, MIDIFeedback> feedbackToggle = new();

public enum Action : int
{
Expand Down
21 changes: 10 additions & 11 deletions MidiControl/MIDIListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace MidiControl
{
class MIDIListener
{
public List<string> midiInStringOptions = new List<string>();
public List<string> midiInStringOptions = new();
private MidiInCustom MidiInForward;
private MidiOutCustom MidiOutForward;
public Dictionary<string, MidiInCustom> midiInInterface = new Dictionary<string, MidiInCustom>();
public Dictionary<string, MidiOutCustom> midiOutInterface = new Dictionary<string, MidiOutCustom>();
public Dictionary<string, MidiInCustom> midiInInterface = new();
public Dictionary<string, MidiOutCustom> midiOutInterface = new();

private static MIDIListener _instance;
private readonly Configuration conf;
Expand All @@ -23,7 +23,7 @@ class MIDIListener

public MIDIListener(Configuration conf)
{
new OBSControl();
_ = new OBSControl();
audioControl = new AudioControl();
goXLRControl = new GoXLRControl();
twitchControl = new TwitchChatControl(options.options, conf.Config);
Expand Down Expand Up @@ -56,7 +56,7 @@ public void RefeshMIDIDevices()
}
else if (!options.options.MIDIInterfaces.Contains(MidiIn.DeviceInfo(device).ProductName))
{
MidiInCustom MidiIndevice = new MidiInCustom(device);
MidiInCustom MidiIndevice = new(device);
midiInInterface.Add(MidiIn.DeviceInfo(device).ProductName, MidiIndevice);
MidiIndevice.Start();
}
Expand Down Expand Up @@ -194,12 +194,11 @@ private void MidiIn_MessageReceivedForwardBack(object sender, MidiInMessageEvent
}
}

private int ValidateSenderDeviceInt(MidiInCustom dev) {
private static int ValidateSenderDeviceInt(MidiInCustom dev) {
var device = dev.device;
var assumed = device;
var adjusted = false;
var correct = false;
var devName = "null";
string devName;

while(!correct && device >= 0) {
try {
Expand Down Expand Up @@ -227,7 +226,7 @@ private int ValidateSenderDeviceInt(MidiInCustom dev) {
// ((MidiInCustom)sender).device = int: numeric device index
private void MidiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
{
int deviceId = this.ValidateSenderDeviceInt((MidiInCustom)sender);
int deviceId = MIDIListener.ValidateSenderDeviceInt((MidiInCustom)sender);
MidiOutForward?.Send(e.RawMessage);

foreach (var entry in conf.Config)
Expand Down Expand Up @@ -270,7 +269,7 @@ private void MidiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
}
if(entry.Value.MediaCallBack != null)
{
audioControl.MediaKey(entry.Value.MediaCallBack.MediaType);
AudioControl.MediaKey(entry.Value.MediaCallBack.MediaType);
}
if (entry.Value.TwitchCallBackON != null)
{
Expand Down Expand Up @@ -312,7 +311,7 @@ private void MidiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
}
if (entry.Value.MediaCallBackOFF != null)
{
audioControl.MediaKey(entry.Value.MediaCallBackOFF.MediaType);
AudioControl.MediaKey(entry.Value.MediaCallBackOFF.MediaType);
}
if (entry.Value.SoundCallBack != null && entry.Value.SoundCallBack.StopWhenReleased)
{
Expand Down
12 changes: 2 additions & 10 deletions MidiControl/MidiControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net472</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>net6.0-windows</TargetFramework>
<LangVersion>10.0</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
Expand All @@ -13,7 +13,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Common.CheckComboBox" Version="1.0.0" />
<PackageReference Include="Fleck" Version="1.2.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
Expand Down Expand Up @@ -44,13 +43,6 @@
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Configuration" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
36 changes: 18 additions & 18 deletions MidiControl/Models/OBS/SceneItemTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,57 @@ namespace MidiControl.Models.OBS
public class SceneItemTransform
{
[JsonProperty("alignment")]
public int alignment { get; set; }
public int Alignment { get; set; }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[JsonProperty("width")]
public double width { get; set; }
public double Width { get; set; }
}
}
20 changes: 10 additions & 10 deletions MidiControl/Models/OBS/Source.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ namespace MidiControl.Models.OBS
public class Source
{
[JsonProperty("inputKind")]
public string inputKind { get; set; }
public string InputKind { get; set; }

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

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

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

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

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

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

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

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

[JsonProperty("sourceType")]
public string sourceType { get; set; }
public string SourceType { get; set; }
}
}
22 changes: 11 additions & 11 deletions MidiControl/OBSControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class OBSControl : IExternalControl {
private readonly OBSWebsocket obs;
private readonly MIDIControlGUI gui;
private static OBSControl _instance;
private readonly Dictionary<string, float[]> FiltersMinMaxValues = new Dictionary<string, float[]>();
public readonly Dictionary<string, string> Hotkeys = new Dictionary<string, string>();
private readonly Dictionary<string, float[]> FiltersMinMaxValues = new();
public readonly Dictionary<string, string> Hotkeys = new();
public readonly OptionsManagment options;
private Timer timer;
private readonly Dictionary<string, MIDIFeedback> feedbackScenes = new Dictionary<string, MIDIFeedback>();
private readonly Dictionary<string, MIDIFeedback> feedbackScenes = new();
private List<FilterSettingsScene> filterSettings;
private bool isConnected = true;
private readonly string FilterLog;
Expand All @@ -43,7 +43,7 @@ public OBSControl() {

var pathFilters = Path.Combine(ConfFolder, Path.GetFileName("filterminmax.csv"));
try {
using TextFieldParser csvParser = new TextFieldParser(pathFilters);
using var csvParser = new TextFieldParser(pathFilters);
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
Expand All @@ -58,7 +58,7 @@ public OBSControl() {

string pathHotkeys = Path.Combine(ConfFolder, Path.GetFileName("hotkeys.csv"));
try {
using TextFieldParser csvParser = new TextFieldParser(pathHotkeys);
using var csvParser = new TextFieldParser(pathHotkeys);
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
Expand Down Expand Up @@ -428,9 +428,9 @@ private void ToggleSources(MIDIFeedback feedback, List<string> sources) {
};
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)))
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);
sourcesName.Add(new SourceScene() { Source = groupElement.SourceName, Scene = group }, obs.GetSourceActive(groupElement.SourceName).VideoShowing);
}
}

Expand Down Expand Up @@ -486,9 +486,9 @@ private void ShowSources(List<string> sources, bool show) {
};
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)))
foreach (var groupElement in groupElements.Where(element => sources.Contains(element.SourceName)))
{
sourcesName.Add(new SourceScene() { Source = groupElement.sourceName, Scene = group });
sourcesName.Add(new SourceScene() { Source = groupElement.SourceName, Scene = group });
}
}

Expand Down Expand Up @@ -522,7 +522,7 @@ private void SetFilterProperties(string filterName, string property, float value
value = value * (max - min) + min;

if(filterSetting.FilterSettings.Name == filterName) {
JObject o = new JObject(new JProperty(property, value));
var o = new JObject(new JProperty(property, value));
obs.SetSourceFilterSettings(filterSetting.Scene, filterName, o);
}
} else if(filterSetting.FilterSettings.Name == filterName) {
Expand Down Expand Up @@ -626,7 +626,7 @@ public List<string> GetSources() {
var groupElements = JsonConvert.DeserializeObject<List<Source>>(result);
foreach (var groupElement in groupElements)
{
sourceString.Add(groupElement.sourceName);
sourceString.Add(groupElement.SourceName);
}
}

Expand Down
7 changes: 3 additions & 4 deletions MidiControl/OptionsManagment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ private void Load() {
try {
var json = File.ReadAllText(OptionFile);
options = JsonConvert.DeserializeObject<Options>(json);
if(options == null) {
if (options == null)
{
throw new FileNotFoundException();
}
if(options.MIDIInterfaces == null) {
options.MIDIInterfaces = new List<string>();
}
options.MIDIInterfaces ??= new List<string>();
} catch(FileNotFoundException) {
options = new Options {
Ip = "127.0.0.1:4444",
Expand Down
Loading