Skip to content

Commit

Permalink
Merge pull request #1 from sll552/dev-fix-lightbar
Browse files Browse the repository at this point in the history
Dev fix lightbar
  • Loading branch information
sll552 authored Apr 30, 2017
2 parents 84f33a7 + 6d7db2a commit fda34c7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
70 changes: 46 additions & 24 deletions CL_DeviceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class ClDeviceController
private ClProgressBrush _progressBrush;
private ClSettings _settings;
private bool _initAble = true;
private CorsairLedId[] _lightbarLeds = new CorsairLedId []

private readonly CorsairLedId[] _lightbarLeds = new CorsairLedId[]
{
CorsairLedId.Lightbar1,
CorsairLedId.Lightbar2,
Expand All @@ -53,16 +54,18 @@ public class ClDeviceController
CorsairLedId.Lightbar18,
CorsairLedId.Lightbar19
};

public static bool IsInitialized => CueSDK.IsInitialized;
public float TrackProgress { get; set; }

public ClDeviceController(Plugin plugin)
{
_plugin = plugin;
_brushFactory = new ClSpectrumBrushFactory(this);
CueSDK.PossibleX64NativePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\x64\CUESDK_2015.dll");
CueSDK.PossibleX86NativePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\x86\CUESDK_2015.dll");
CueSDK.PossibleX64NativePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
@"\x64\CUESDK_2015.dll");
CueSDK.PossibleX86NativePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
@"\x86\CUESDK_2015.dll");
}

public float[] Curbardata
Expand All @@ -71,7 +74,7 @@ public float[] Curbardata
set => _curbardata = value;
}

public void Init(bool force=false)
public void Init(bool force = false)
{
if (!CueSDK.IsSDKAvailable(null))
{
Expand Down Expand Up @@ -148,56 +151,75 @@ public void StartEffect()
}
if (_keyboard == null)
{
Init(force:true);
Init(force: true);
}
if (_keyboard == null) return;

_keyboard.Brush = new SolidColorBrush(_settings?.EffectSettingBackgroundColor ?? Color.Black);

if (_spectrumGroup != null)
{
_spectrumGroup.Detach();
_keyboard.DetachLedGroup(_spectrumGroup);
}
_spectrumGroup = new ListLedGroup(_keyboard, false, _keyboard)
{
Brush = _brushFactory.GetSpectrumBrush(
_settings?.EffectSettingColorMode ?? ClSpectrumBrushFactory.ColoringMode.Solid,
_settings?.EffectSettingPrimaryColor ?? Color.Red)
};


if (_settings?.EffectSettingLightbarProgress ?? false)
{
_spectrumGroup = _spectrumGroup.Exclude(_lightbarLeds);
if (_progressBrush == null)
{
_progressBrush = new ClProgressBrush(_settings?.EffectSettingPrimaryColor ?? Color.Red);
}

if (_progressGroup != null)
{
_progressGroup.Detach();
_keyboard.DetachLedGroup(_progressGroup);
}

_progressGroup = new ListLedGroup(_keyboard, _lightbarLeds)
{
Brush = _progressBrush
};
}
else if (_progressGroup != null)
{
_progressGroup.Brush = new SolidColorBrush(Color.Transparent);
_keyboard.Update(true);
_keyboard.DetachLedGroup(_progressGroup);
_keyboard.Update(true);
}

_spectrumGroup.Attach();
}

public void StopEffect()
{
if (_keyboard == null || _spectrumGroup == null) return;
void RemoveGroup(ILedGroup group)
{
if (group == null) return;
group.Brush = new SolidColorBrush(Color.Transparent);
_keyboard.Update(true);
_keyboard.DetachLedGroup(group);
_keyboard.Update(true);
}

_spectrumGroup.Brush = new SolidColorBrush(Color.Black);
_keyboard.Update();
_keyboard.DetachLedGroup(_spectrumGroup);
_keyboard.Brush = null;
_keyboard.Update(true);
if (_keyboard == null) return;

_spectrumGroup.RemoveLeds(_keyboard);
_spectrumGroup.Detach();
RemoveGroup(_spectrumGroup);
_spectrumGroup = null;
RemoveGroup(_progressGroup);
_progressGroup = null;

if (_progressGroup != null)
{
_progressGroup.Brush = new SolidColorBrush(Color.Black);
_keyboard.Update();
_keyboard.DetachLedGroup(_progressGroup);
_progressGroup.RemoveLeds(_keyboard);
_progressGroup.Detach();
_progressGroup = null;
}
_keyboard.Brush = null;
_keyboard.Update(true);

if (IsInitialized)
{
Expand All @@ -218,7 +240,7 @@ public bool IsInSpectrum(RectangleF rectangle, BrushRenderTarget renderTarget)
bardata[i] = Math.Min(Math.Max(bardata[i], _min), _max);
}

int baridx = (int) Math.Min(Math.Floor((renderTarget.Point.X - rectangle.Left) / barwidth), bardata.Length-1);
int baridx = (int) Math.Min(Math.Floor((renderTarget.Point.X - rectangle.Left) / barwidth), bardata.Length - 1);
return (_max - bardata[baridx]) / _max < renderTarget.Point.Y / rectangle.Height;
}

Expand Down
4 changes: 3 additions & 1 deletion CL_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace MusicBeePlugin
Expand Down Expand Up @@ -122,7 +123,8 @@ string ReadKey(string key)
colorModeComboBox.SelectedItem = EffectSettingColorMode;

bool tmpLightbarProg;
EffectSettingLightbarProgress = Boolean.TryParse(ReadKey(_effectSettingLightbarProgress.Key), out tmpLightbarProg);
Boolean.TryParse(ReadKey(_effectSettingLightbarProgress.Key), out tmpLightbarProg);
EffectSettingLightbarProgress = tmpLightbarProg;
lightbarProgCheckBox.Checked = tmpLightbarProg;

}
Expand Down
2 changes: 1 addition & 1 deletion CorsairLED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PluginInfo Initialise(IntPtr apiInterfacePtr)
_about.Type = PluginType.General;
_about.VersionMajor = 0; // your plugin version
_about.VersionMinor = 1;
_about.Revision = 1;
_about.Revision = 2;
_about.MinInterfaceVersion = MinInterfaceVersion;
_about.MinApiRevision = MinApiRevision;
_about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
Expand Down

0 comments on commit fda34c7

Please sign in to comment.