mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +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\LedImageLayout.cs" />
|
||||
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
||||
<Compile Include="Extensions\EnumExtensions.cs" />
|
||||
<Compile Include="Helper\CultureHelper.cs" />
|
||||
<Compile Include="Helper\PathHelper.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 RGB.NET.Core;
|
||||
using RGB.NET.Core.Layout;
|
||||
using Sanford.Multimedia.Midi;
|
||||
|
||||
namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
@ -13,6 +14,9 @@ namespace RGB.NET.Devices.Novation
|
||||
public abstract class NovationRGBDevice : AbstractRGBDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly OutputDevice _outputDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Gets information about the <see cref="NovationRGBDevice"/>.
|
||||
/// </summary>
|
||||
@ -29,6 +33,7 @@ namespace RGB.NET.Devices.Novation
|
||||
protected NovationRGBDevice(IRGBDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
_outputDevice = new OutputDevice(((NovationRGBDeviceInfo)DeviceInfo).DeviceId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -104,14 +109,57 @@ namespace RGB.NET.Devices.Novation
|
||||
|
||||
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 />
|
||||
public override void Dispose()
|
||||
{
|
||||
//TODO DarthAffe 15.08.2017: Dispose
|
||||
_outputDevice.Dispose();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
@ -25,6 +25,9 @@ namespace RGB.NET.Devices.Novation
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int DeviceId { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -34,10 +37,11 @@ namespace RGB.NET.Devices.Novation
|
||||
/// </summary>
|
||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</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.Model = model;
|
||||
this.DeviceId = deviceId;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
using Sanford.Multimedia.Midi;
|
||||
|
||||
namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
|
||||
@ -14,8 +14,9 @@ namespace RGB.NET.Devices.Novation
|
||||
/// Internal constructor of managed <see cref="NovationLaunchpadRGBDeviceInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="model">The represented device model.</param>
|
||||
internal NovationLaunchpadRGBDeviceInfo(string model)
|
||||
: base(RGBDeviceType.LedMatrix, model)
|
||||
/// <param name="deviceId"></param>
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Core.Extensions;
|
||||
using Sanford.Multimedia.Midi;
|
||||
|
||||
namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
@ -46,6 +49,7 @@ namespace RGB.NET.Devices.Novation
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
@ -54,21 +58,24 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
|
||||
//TODO DarthAffe 15.08.2017: Get devices
|
||||
// foreach ...
|
||||
try
|
||||
{
|
||||
NovationRGBDevice device = null;
|
||||
device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo("Launchpad S"));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
|
||||
{
|
||||
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();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
//else
|
||||
//continue;
|
||||
}
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
@ -86,9 +93,15 @@ namespace RGB.NET.Devices.Novation
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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
|
||||
|
||||
@ -32,7 +32,11 @@
|
||||
<DocumentationFile>..\bin\RGB.NET.Devices.Novation.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<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.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<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>
|
||||
@ -45,6 +49,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Enum\NovationDevices.cs" />
|
||||
<Compile Include="Enum\NovationLedIds.cs" />
|
||||
<Compile Include="Generic\NovationLedId.cs" />
|
||||
<Compile Include="Generic\NovationRGBDevice.cs" />
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Sanford.Multimedia.Midi" version="6.4.1" targetFramework="net45" />
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user