mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Implement Novation device detection (at start only Launchpad S supported) and implement updating of leds
This commit is contained in:
parent
f654f825f7
commit
8ecaff8722
21
RGB.NET.Core/Extensions/EnumExtensions.cs
Normal file
21
RGB.NET.Core/Extensions/EnumExtensions.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
namespace RGB.NET.Core.Extensions
|
||||||
|
{
|
||||||
|
public static class EnumExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A generic extension method that aids in reflecting
|
||||||
|
/// and retrieving any attribute that is applied to an `Enum`.
|
||||||
|
/// </summary>
|
||||||
|
public static TAttribute GetAttribute<TAttribute>(this Enum enumValue)
|
||||||
|
where TAttribute : Attribute
|
||||||
|
{
|
||||||
|
return enumValue.GetType()
|
||||||
|
.GetMember(enumValue.ToString())
|
||||||
|
.First()
|
||||||
|
.GetCustomAttribute<TAttribute>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -54,6 +54,7 @@
|
|||||||
<Compile Include="Devices\Layout\LedImage.cs" />
|
<Compile Include="Devices\Layout\LedImage.cs" />
|
||||||
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
||||||
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
||||||
|
<Compile Include="Extensions\EnumExtensions.cs" />
|
||||||
<Compile Include="Helper\CultureHelper.cs" />
|
<Compile Include="Helper\CultureHelper.cs" />
|
||||||
<Compile Include="Helper\PathHelper.cs" />
|
<Compile Include="Helper\PathHelper.cs" />
|
||||||
<Compile Include="Positioning\Shape.cs" />
|
<Compile Include="Positioning\Shape.cs" />
|
||||||
|
|||||||
10
RGB.NET.Devices.Novation/Enum/NovationDevices.cs
Normal file
10
RGB.NET.Devices.Novation/Enum/NovationDevices.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Novation
|
||||||
|
{
|
||||||
|
public enum NovationDevices
|
||||||
|
{
|
||||||
|
[Display(Name = "Launchpad S")]
|
||||||
|
LaunchpadS
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Core.Layout;
|
using RGB.NET.Core.Layout;
|
||||||
|
using Sanford.Multimedia.Midi;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Novation
|
namespace RGB.NET.Devices.Novation
|
||||||
{
|
{
|
||||||
@ -13,6 +14,9 @@ namespace RGB.NET.Devices.Novation
|
|||||||
public abstract class NovationRGBDevice : AbstractRGBDevice
|
public abstract class NovationRGBDevice : AbstractRGBDevice
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly OutputDevice _outputDevice;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets information about the <see cref="NovationRGBDevice"/>.
|
/// Gets information about the <see cref="NovationRGBDevice"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -29,6 +33,7 @@ namespace RGB.NET.Devices.Novation
|
|||||||
protected NovationRGBDevice(IRGBDeviceInfo info)
|
protected NovationRGBDevice(IRGBDeviceInfo info)
|
||||||
{
|
{
|
||||||
this.DeviceInfo = info;
|
this.DeviceInfo = info;
|
||||||
|
_outputDevice = new OutputDevice(((NovationRGBDeviceInfo)DeviceInfo).DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -104,14 +109,57 @@ namespace RGB.NET.Devices.Novation
|
|||||||
|
|
||||||
if (leds.Count > 0)
|
if (leds.Count > 0)
|
||||||
{
|
{
|
||||||
//TODO DarthAffe 15.08.2017: Update Leds
|
foreach (Led led in leds)
|
||||||
|
{
|
||||||
|
NovationLedId ledId = (NovationLedId)led.Id;
|
||||||
|
|
||||||
|
int color = 0;
|
||||||
|
|
||||||
|
if (led.Color.R > 0)
|
||||||
|
{
|
||||||
|
color = 1;
|
||||||
|
|
||||||
|
if (led.Color.R > 127)
|
||||||
|
color = 2;
|
||||||
|
if (led.Color.R == 255)
|
||||||
|
color = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (led.Color.G > 0)
|
||||||
|
{
|
||||||
|
color = 16;
|
||||||
|
|
||||||
|
if (led.Color.G > 127)
|
||||||
|
color = 32;
|
||||||
|
if (led.Color.G == 255)
|
||||||
|
color = 48;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((led.Color.R > 0) && (led.Color.G > 0))
|
||||||
|
{
|
||||||
|
color = 17;
|
||||||
|
|
||||||
|
if(((led.Color.R > 127) && (led.Color.G < 127)) || ((led.Color.R < 127) && (led.Color.G > 127)))
|
||||||
|
color = 34;
|
||||||
|
if((led.Color.R > 127) && (led.Color.G > 127))
|
||||||
|
color = 51;
|
||||||
|
}
|
||||||
|
|
||||||
|
SendMessage(ledId.LedId.GetStatus(), ledId.LedId.GetId(), color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendMessage(int status, int data1, int data2)
|
||||||
|
{
|
||||||
|
ShortMessage shortMessage = new ShortMessage(Convert.ToByte(status), Convert.ToByte(data1), Convert.ToByte(data2));
|
||||||
|
_outputDevice.SendShort(shortMessage.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
//TODO DarthAffe 15.08.2017: Dispose
|
_outputDevice.Dispose();
|
||||||
|
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,9 @@ namespace RGB.NET.Devices.Novation
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public int DeviceId { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -34,10 +37,11 @@ namespace RGB.NET.Devices.Novation
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||||
/// <param name="model">The represented device model.</param>
|
/// <param name="model">The represented device model.</param>
|
||||||
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model)
|
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model, int deviceId)
|
||||||
{
|
{
|
||||||
this.DeviceType = deviceType;
|
this.DeviceType = deviceType;
|
||||||
this.Model = model;
|
this.Model = model;
|
||||||
|
this.DeviceId = deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
using Sanford.Multimedia.Midi;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Novation
|
namespace RGB.NET.Devices.Novation
|
||||||
{
|
{
|
||||||
|
|||||||
@ -14,8 +14,9 @@ namespace RGB.NET.Devices.Novation
|
|||||||
/// Internal constructor of managed <see cref="NovationLaunchpadRGBDeviceInfo"/>.
|
/// Internal constructor of managed <see cref="NovationLaunchpadRGBDeviceInfo"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model">The represented device model.</param>
|
/// <param name="model">The represented device model.</param>
|
||||||
internal NovationLaunchpadRGBDeviceInfo(string model)
|
/// <param name="deviceId"></param>
|
||||||
: base(RGBDeviceType.LedMatrix, model)
|
internal NovationLaunchpadRGBDeviceInfo(string model, int deviceId)
|
||||||
|
: base(RGBDeviceType.LedMatrix, model, deviceId)
|
||||||
{
|
{
|
||||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Novation\Launchpads\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
|
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Novation\Launchpads\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
using RGB.NET.Core.Extensions;
|
||||||
|
using Sanford.Multimedia.Midi;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Novation
|
namespace RGB.NET.Devices.Novation
|
||||||
{
|
{
|
||||||
@ -46,6 +49,7 @@ namespace RGB.NET.Devices.Novation
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||||
{
|
{
|
||||||
IsInitialized = false;
|
IsInitialized = false;
|
||||||
@ -54,21 +58,24 @@ namespace RGB.NET.Devices.Novation
|
|||||||
{
|
{
|
||||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||||
|
|
||||||
//TODO DarthAffe 15.08.2017: Get devices
|
|
||||||
// foreach ...
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NovationRGBDevice device = null;
|
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
|
||||||
device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo("Launchpad S"));
|
{
|
||||||
|
MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
|
||||||
|
|
||||||
|
if (outCaps.name.Equals(NovationDevices.LaunchpadS.GetAttribute<DisplayAttribute>().Name))
|
||||||
|
{
|
||||||
|
NovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index));
|
||||||
device.Initialize();
|
device.Initialize();
|
||||||
devices.Add(device);
|
devices.Add(device);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
if (throwExceptions)
|
if (throwExceptions)
|
||||||
throw;
|
throw;
|
||||||
//else
|
|
||||||
//continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||||
@ -86,9 +93,15 @@ namespace RGB.NET.Devices.Novation
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public void ResetDevices()
|
public void ResetDevices()
|
||||||
{
|
{
|
||||||
//TODO DarthAffe 15.08.2017: Is this possible?
|
foreach (IRGBDevice device in Devices)
|
||||||
|
{
|
||||||
|
NovationLaunchpadRGBDeviceInfo deviceInfo = (NovationLaunchpadRGBDeviceInfo)device.DeviceInfo;
|
||||||
|
OutputDevice outputDevice = new OutputDevice(deviceInfo.DeviceId);
|
||||||
|
outputDevice.Reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -32,7 +32,11 @@
|
|||||||
<DocumentationFile>..\bin\RGB.NET.Devices.Novation.XML</DocumentationFile>
|
<DocumentationFile>..\bin\RGB.NET.Devices.Novation.XML</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Sanford.Multimedia.Midi, Version=6.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Sanford.Multimedia.Midi.6.4.1\lib\net20\Sanford.Multimedia.Midi.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||||
@ -45,6 +49,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Enum\NovationDevices.cs" />
|
||||||
<Compile Include="Enum\NovationLedIds.cs" />
|
<Compile Include="Enum\NovationLedIds.cs" />
|
||||||
<Compile Include="Generic\NovationLedId.cs" />
|
<Compile Include="Generic\NovationLedId.cs" />
|
||||||
<Compile Include="Generic\NovationRGBDevice.cs" />
|
<Compile Include="Generic\NovationRGBDevice.cs" />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="Sanford.Multimedia.Midi" version="6.4.1" targetFramework="net45" />
|
||||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
|
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
x
Reference in New Issue
Block a user