mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Don't render device types that aren't usable
This commit is contained in:
parent
039593c6fe
commit
d7bf26a738
@ -52,8 +52,8 @@ namespace Artemis.Managers
|
|||||||
//TODO DarthAffe 14.01.2017: A stop-condition and a real cleanup instead of just aborting might be better
|
//TODO DarthAffe 14.01.2017: A stop-condition and a real cleanup instead of just aborting might be better
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
long preUpdateTicks = DateTime.Now.Ticks;
|
long preUpdateTicks = DateTime.Now.Ticks;
|
||||||
|
|
||||||
Render();
|
Render();
|
||||||
@ -61,11 +61,11 @@ namespace Artemis.Managers
|
|||||||
int sleep = (int)(40f - ((DateTime.Now.Ticks - preUpdateTicks) / 10000f));
|
int sleep = (int)(40f - ((DateTime.Now.Ticks - preUpdateTicks) / 10000f));
|
||||||
if (sleep > 0)
|
if (sleep > 0)
|
||||||
Thread.Sleep(sleep);
|
Thread.Sleep(sleep);
|
||||||
// }
|
}
|
||||||
// catch (Exception e)
|
catch (Exception e)
|
||||||
// {
|
{
|
||||||
// _logger.Warn(e, "Exception in render loop");
|
_logger.Warn(e, "Exception in render loop");
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
// ReSharper disable once FunctionNeverReturns
|
// ReSharper disable once FunctionNeverReturns
|
||||||
}
|
}
|
||||||
@ -157,10 +157,11 @@ namespace Artemis.Managers
|
|||||||
var headsets = _deviceManager.HeadsetProviders.Where(m => m.CanUse).ToList();
|
var headsets = _deviceManager.HeadsetProviders.Where(m => m.CanUse).ToList();
|
||||||
var generics = _deviceManager.GenericProviders.Where(m => m.CanUse).ToList();
|
var generics = _deviceManager.GenericProviders.Where(m => m.CanUse).ToList();
|
||||||
var mousemats = _deviceManager.MousematProviders.Where(m => m.CanUse).ToList();
|
var mousemats = _deviceManager.MousematProviders.Where(m => m.CanUse).ToList();
|
||||||
|
|
||||||
var keyboardOnly = !mice.Any() && !headsets.Any() && !generics.Any() && !mousemats.Any();
|
var keyboardOnly = !mice.Any() && !headsets.Any() && !generics.Any() && !mousemats.Any();
|
||||||
|
|
||||||
// Setup the frame for this tick
|
// Setup the frame for this tick
|
||||||
using (var frame = new RenderFrame(_deviceManager.ActiveKeyboard))
|
using (var frame = new RenderFrame(_deviceManager.ActiveKeyboard, mice.Any(), headsets.Any(), generics.Any(), mousemats.Any()))
|
||||||
{
|
{
|
||||||
if (renderModule.IsInitialized)
|
if (renderModule.IsInitialized)
|
||||||
renderModule.Render(frame, keyboardOnly);
|
renderModule.Render(frame, keyboardOnly);
|
||||||
@ -202,45 +203,53 @@ namespace Artemis.Managers
|
|||||||
|
|
||||||
public class RenderFrame : IDisposable
|
public class RenderFrame : IDisposable
|
||||||
{
|
{
|
||||||
public RenderFrame(KeyboardProvider keyboard)
|
public RenderFrame(KeyboardProvider keyboard, bool renderMice, bool renderHeadsets, bool renderGenerics, bool renderMousemats)
|
||||||
{
|
{
|
||||||
if (keyboard == null)
|
if (keyboard == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
KeyboardBitmap = keyboard.KeyboardBitmap();
|
KeyboardBitmap = keyboard.KeyboardBitmap();
|
||||||
KeyboardBitmap.SetResolution(96, 96);
|
KeyboardBitmap.SetResolution(96, 96);
|
||||||
|
|
||||||
MouseBitmap = new Bitmap(10, 10);
|
|
||||||
MouseBitmap.SetResolution(96, 96);
|
|
||||||
|
|
||||||
HeadsetBitmap = new Bitmap(10, 10);
|
|
||||||
HeadsetBitmap.SetResolution(96, 96);
|
|
||||||
|
|
||||||
GenericBitmap = new Bitmap(10, 10);
|
|
||||||
GenericBitmap.SetResolution(96, 96);
|
|
||||||
|
|
||||||
MousematBitmap = new Bitmap(10, 10);
|
|
||||||
MousematBitmap.SetResolution(96, 96);
|
|
||||||
|
|
||||||
using (var g = Graphics.FromImage(KeyboardBitmap))
|
using (var g = Graphics.FromImage(KeyboardBitmap))
|
||||||
{
|
{
|
||||||
g.Clear(Color.Black);
|
g.Clear(Color.Black);
|
||||||
}
|
}
|
||||||
using (var g = Graphics.FromImage(MouseBitmap))
|
|
||||||
|
if (renderMice)
|
||||||
{
|
{
|
||||||
g.Clear(Color.Black);
|
MouseBitmap = new Bitmap(10, 10);
|
||||||
|
MouseBitmap.SetResolution(96, 96);
|
||||||
|
using (var g = Graphics.FromImage(MouseBitmap))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Black);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
using (var g = Graphics.FromImage(HeadsetBitmap))
|
if (renderHeadsets)
|
||||||
{
|
{
|
||||||
g.Clear(Color.Black);
|
HeadsetBitmap = new Bitmap(10, 10);
|
||||||
|
HeadsetBitmap.SetResolution(96, 96);
|
||||||
|
using (var g = Graphics.FromImage(HeadsetBitmap))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Black);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
using (var g = Graphics.FromImage(GenericBitmap))
|
if (renderGenerics)
|
||||||
{
|
{
|
||||||
g.Clear(Color.Black);
|
GenericBitmap = new Bitmap(10, 10);
|
||||||
|
GenericBitmap.SetResolution(96, 96);
|
||||||
|
using (var g = Graphics.FromImage(GenericBitmap))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Black);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
using (var g = Graphics.FromImage(MousematBitmap))
|
if (renderMousemats)
|
||||||
{
|
{
|
||||||
g.Clear(Color.Black);
|
MousematBitmap = new Bitmap(10, 10);
|
||||||
|
MousematBitmap.SetResolution(96, 96);
|
||||||
|
using (var g = Graphics.FromImage(MousematBitmap))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Black);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -164,26 +164,38 @@ namespace Artemis.Modules.Abstract
|
|||||||
}
|
}
|
||||||
// Render mice layer-by-layer
|
// Render mice layer-by-layer
|
||||||
var devRec = new Rect(0, 0, 10, 10);
|
var devRec = new Rect(0, 0, 10, 10);
|
||||||
using (var g = Graphics.FromImage(frame.MouseBitmap))
|
if (frame.MouseBitmap != null)
|
||||||
{
|
{
|
||||||
ProfileModel?.DrawLayers(g, layers, DrawType.Mouse, DataModel, devRec, preview);
|
using (var g = Graphics.FromImage(frame.MouseBitmap))
|
||||||
|
{
|
||||||
|
ProfileModel?.DrawLayers(g, layers, DrawType.Mouse, DataModel, devRec, preview);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Render headsets layer-by-layer
|
// Render headsets layer-by-layer
|
||||||
using (var g = Graphics.FromImage(frame.HeadsetBitmap))
|
if (frame.HeadsetBitmap != null)
|
||||||
{
|
{
|
||||||
ProfileModel?.DrawLayers(g, layers, DrawType.Headset, DataModel, devRec, preview);
|
using (var g = Graphics.FromImage(frame.HeadsetBitmap))
|
||||||
|
{
|
||||||
|
ProfileModel?.DrawLayers(g, layers, DrawType.Headset, DataModel, devRec, preview);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Render generic devices layer-by-layer
|
// Render generic devices layer-by-layer
|
||||||
using (var g = Graphics.FromImage(frame.GenericBitmap))
|
if (frame.GenericBitmap != null)
|
||||||
{
|
{
|
||||||
ProfileModel?.DrawLayers(g, layers, DrawType.Generic, DataModel, devRec, preview);
|
using (var g = Graphics.FromImage(frame.GenericBitmap))
|
||||||
|
{
|
||||||
|
ProfileModel?.DrawLayers(g, layers, DrawType.Generic, DataModel, devRec, preview);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Render mousemats layer-by-layer
|
// Render mousemats layer-by-layer
|
||||||
using (var g = Graphics.FromImage(frame.MousematBitmap))
|
if (frame.MousematBitmap != null)
|
||||||
{
|
{
|
||||||
ProfileModel?.DrawLayers(g, layers, DrawType.Mousemat, DataModel, devRec, preview);
|
using (var g = Graphics.FromImage(frame.MousematBitmap))
|
||||||
|
{
|
||||||
|
ProfileModel?.DrawLayers(g, layers, DrawType.Mousemat, DataModel, devRec, preview);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trace debugging
|
// Trace debugging
|
||||||
if (DateTime.Now.AddSeconds(-2) <= _lastTrace || Logger == null)
|
if (DateTime.Now.AddSeconds(-2) <= _lastTrace || Logger == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -75,17 +75,23 @@ namespace Artemis.Modules.General.GeneralProfile
|
|||||||
|
|
||||||
private MMDevice _defaultRecording;
|
private MMDevice _defaultRecording;
|
||||||
private MMDevice _defaultPlayback;
|
private MMDevice _defaultPlayback;
|
||||||
|
private AudioMeterInformation _recordingInfo;
|
||||||
|
private AudioMeterInformation _playbackInfo;
|
||||||
|
|
||||||
private void SetupAudio()
|
private void SetupAudio()
|
||||||
{
|
{
|
||||||
_defaultPlayback = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
|
||||||
_defaultRecording = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);
|
_defaultRecording = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);
|
||||||
|
_recordingInfo = AudioMeterInformation.FromDevice(_defaultRecording);
|
||||||
|
_defaultPlayback = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
||||||
|
_playbackInfo = AudioMeterInformation.FromDevice(_defaultPlayback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AudioDeviceChanged(object sender, AudioDeviceChangedEventArgs e)
|
private void AudioDeviceChanged(object sender, AudioDeviceChangedEventArgs e)
|
||||||
{
|
{
|
||||||
_defaultRecording = e.DefaultRecording;
|
_defaultRecording = e.DefaultRecording;
|
||||||
|
_recordingInfo = AudioMeterInformation.FromDevice(_defaultRecording);
|
||||||
_defaultPlayback = e.DefaultPlayback;
|
_defaultPlayback = e.DefaultPlayback;
|
||||||
|
_playbackInfo = AudioMeterInformation.FromDevice(_defaultPlayback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAudio(GeneralProfileDataModel dataModel)
|
private void UpdateAudio(GeneralProfileDataModel dataModel)
|
||||||
@ -93,8 +99,8 @@ namespace Artemis.Modules.General.GeneralProfile
|
|||||||
// Update microphone, only bother with OverallPeak
|
// Update microphone, only bother with OverallPeak
|
||||||
if (_defaultRecording != null)
|
if (_defaultRecording != null)
|
||||||
{
|
{
|
||||||
var recording = AudioMeterInformation.FromDevice(_defaultRecording);
|
|
||||||
dataModel.Audio.Recording.OverallPeak = recording.PeakValue;
|
dataModel.Audio.Recording.OverallPeak = _recordingInfo.PeakValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_defaultPlayback == null)
|
if (_defaultPlayback == null)
|
||||||
@ -105,9 +111,8 @@ namespace Artemis.Modules.General.GeneralProfile
|
|||||||
|
|
||||||
// Update speakers, only do overall, left and right for now
|
// Update speakers, only do overall, left and right for now
|
||||||
// TODO: When adding list support lets do all channels
|
// TODO: When adding list support lets do all channels
|
||||||
var playback = AudioMeterInformation.FromDevice(_defaultPlayback);
|
var peakValues = _playbackInfo.GetChannelsPeakValues();
|
||||||
var peakValues = playback.GetChannelsPeakValues();
|
dataModel.Audio.Playback.OverallPeak = _playbackInfo.PeakValue;
|
||||||
dataModel.Audio.Playback.OverallPeak = playback.PeakValue;
|
|
||||||
dataModel.Audio.Playback.LeftPeak = peakValues[0];
|
dataModel.Audio.Playback.LeftPeak = peakValues[0];
|
||||||
dataModel.Audio.Playback.LeftPeak = peakValues[1];
|
dataModel.Audio.Playback.LeftPeak = peakValues[1];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,202 +1,202 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Events;
|
using Artemis.Events;
|
||||||
using Artemis.Managers;
|
using Artemis.Managers;
|
||||||
using Artemis.Modules.Abstract;
|
using Artemis.Modules.Abstract;
|
||||||
using Artemis.Profiles.Layers.Abstract;
|
using Artemis.Profiles.Layers.Abstract;
|
||||||
using Artemis.Profiles.Layers.Animations;
|
using Artemis.Profiles.Layers.Animations;
|
||||||
using Artemis.Profiles.Layers.Interfaces;
|
using Artemis.Profiles.Layers.Interfaces;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
using Artemis.Profiles.Layers.Types.Audio.AudioCapturing;
|
using Artemis.Profiles.Layers.Types.Audio.AudioCapturing;
|
||||||
using Artemis.Properties;
|
using Artemis.Properties;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
using Artemis.ViewModels;
|
using Artemis.ViewModels;
|
||||||
using Artemis.ViewModels.Profiles;
|
using Artemis.ViewModels.Profiles;
|
||||||
using CSCore.CoreAudioAPI;
|
using CSCore.CoreAudioAPI;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Types.Audio
|
namespace Artemis.Profiles.Layers.Types.Audio
|
||||||
{
|
{
|
||||||
public class AudioType : ILayerType
|
public class AudioType : ILayerType
|
||||||
{
|
{
|
||||||
private readonly AudioCaptureManager _audioCaptureManager;
|
private readonly AudioCaptureManager _audioCaptureManager;
|
||||||
private const GeometryCombineMode CombineMode = GeometryCombineMode.Union;
|
private const GeometryCombineMode CombineMode = GeometryCombineMode.Union;
|
||||||
private AudioCapture _audioCapture;
|
private AudioCapture _audioCapture;
|
||||||
private int _lines;
|
private int _lines;
|
||||||
private LineSpectrum _lineSpectrum;
|
private LineSpectrum _lineSpectrum;
|
||||||
private List<double> _lineValues;
|
private List<double> _lineValues;
|
||||||
private int _drawCount;
|
private int _drawCount;
|
||||||
|
|
||||||
public AudioType(AudioCaptureManager audioCaptureManager)
|
public AudioType(AudioCaptureManager audioCaptureManager)
|
||||||
{
|
{
|
||||||
_audioCaptureManager = audioCaptureManager;
|
_audioCaptureManager = audioCaptureManager;
|
||||||
|
|
||||||
// TODO: Setup according to settings
|
// TODO: Setup according to settings
|
||||||
_audioCapture = _audioCaptureManager.GetAudioCapture(MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Multimedia));
|
_audioCapture = _audioCaptureManager.GetAudioCapture(MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Multimedia));
|
||||||
_audioCaptureManager.AudioDeviceChanged += OnAudioDeviceChanged;
|
_audioCaptureManager.AudioDeviceChanged += OnAudioDeviceChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAudioDeviceChanged(object sender, AudioDeviceChangedEventArgs e)
|
private void OnAudioDeviceChanged(object sender, AudioDeviceChangedEventArgs e)
|
||||||
{
|
{
|
||||||
// TODO: Check if layer must use default
|
// TODO: Check if layer must use default
|
||||||
// TODO: Check recording type
|
// TODO: Check recording type
|
||||||
_audioCapture = _audioCaptureManager.GetAudioCapture(e.DefaultPlayback);
|
_audioCapture = _audioCaptureManager.GetAudioCapture(e.DefaultPlayback);
|
||||||
_lines = 0;
|
_lines = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => "Keyboard - Audio visualization";
|
public string Name => "Keyboard - Audio visualization";
|
||||||
public bool ShowInEdtor => true;
|
public bool ShowInEdtor => true;
|
||||||
public DrawType DrawType => DrawType.Keyboard;
|
public DrawType DrawType => DrawType.Keyboard;
|
||||||
|
|
||||||
public ImageSource DrawThumbnail(LayerModel layer)
|
public ImageSource DrawThumbnail(LayerModel layer)
|
||||||
{
|
{
|
||||||
var thumbnailRect = new Rect(0, 0, 18, 18);
|
var thumbnailRect = new Rect(0, 0, 18, 18);
|
||||||
var visual = new DrawingVisual();
|
var visual = new DrawingVisual();
|
||||||
using (var c = visual.RenderOpen())
|
using (var c = visual.RenderOpen())
|
||||||
{
|
{
|
||||||
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.audio), thumbnailRect);
|
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.audio), thumbnailRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
var image = new DrawingImage(visual.Drawing);
|
var image = new DrawingImage(visual.Drawing);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(LayerModel layerModel, DrawingContext c)
|
public void Draw(LayerModel layerModel, DrawingContext c)
|
||||||
{
|
{
|
||||||
_drawCount++;
|
_drawCount++;
|
||||||
if (_lineValues == null)
|
if (_lineValues == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var parentX = layerModel.X;
|
var parentX = layerModel.X;
|
||||||
var parentY = layerModel.Y;
|
var parentY = layerModel.Y;
|
||||||
var direction = ((AudioPropertiesModel) layerModel.Properties).Direction;
|
var direction = ((AudioPropertiesModel) layerModel.Properties).Direction;
|
||||||
|
|
||||||
// Create a geometry that will be formed by all the bars
|
// Create a geometry that will be formed by all the bars
|
||||||
Geometry barGeometry = new RectangleGeometry();
|
GeometryGroup barGeometry = new GeometryGroup();
|
||||||
|
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case Direction.TopToBottom:
|
case Direction.TopToBottom:
|
||||||
for (var index = 0; index < _lineValues.Count; index++)
|
for (var index = 0; index < _lineValues.Count; index++)
|
||||||
{
|
{
|
||||||
var clipRect = new Rect((parentX + index)*4, parentY*4, 4, _lineValues[index]*4);
|
var clipRect = new Rect((parentX + index) * 4, parentY * 4, 4, _lineValues[index] * 4);
|
||||||
var barRect = new RectangleGeometry(clipRect);
|
var barRect = new RectangleGeometry(clipRect);
|
||||||
barGeometry = Geometry.Combine(barGeometry, barRect, CombineMode, Transform.Identity);
|
barGeometry.Children.Add(barRect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Direction.BottomToTop:
|
case Direction.BottomToTop:
|
||||||
for (var index = 0; index < _lineValues.Count; index++)
|
for (var index = 0; index < _lineValues.Count; index++)
|
||||||
{
|
{
|
||||||
var clipRect = new Rect((parentX + index)*4, parentY*4, 4, _lineValues[index]*4);
|
var clipRect = new Rect((parentX + index) * 4, parentY * 4, 4, _lineValues[index] * 4);
|
||||||
clipRect.Y = clipRect.Y + layerModel.Height*4 - clipRect.Height;
|
clipRect.Y = clipRect.Y + layerModel.Height * 4 - clipRect.Height;
|
||||||
var barRect = new RectangleGeometry(clipRect);
|
var barRect = new RectangleGeometry(clipRect);
|
||||||
barGeometry = Geometry.Combine(barGeometry, barRect, CombineMode, Transform.Identity);
|
barGeometry.Children.Add(barRect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Direction.LeftToRight:
|
case Direction.LeftToRight:
|
||||||
for (var index = 0; index < _lineValues.Count; index++)
|
for (var index = 0; index < _lineValues.Count; index++)
|
||||||
{
|
{
|
||||||
var clipRect = new Rect((parentX + index)*4, parentY*4, 4, _lineValues[index]*4);
|
var clipRect = new Rect((parentX + index) * 4, parentY * 4, 4, _lineValues[index] * 4);
|
||||||
var barRect = new RectangleGeometry(clipRect);
|
var barRect = new RectangleGeometry(clipRect);
|
||||||
barGeometry = Geometry.Combine(barGeometry, barRect, CombineMode, Transform.Identity);
|
barGeometry.Children.Add(barRect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for (var index = 0; index < _lineValues.Count; index++)
|
for (var index = 0; index < _lineValues.Count; index++)
|
||||||
{
|
{
|
||||||
var clipRect = new Rect((parentX + index)*4, parentY*4, 4, _lineValues[index]*4);
|
var clipRect = new Rect((parentX + index) * 4, parentY * 4, 4, _lineValues[index] * 4);
|
||||||
var barRect = new RectangleGeometry(clipRect);
|
var barRect = new RectangleGeometry(clipRect);
|
||||||
barGeometry = Geometry.Combine(barGeometry, barRect, CombineMode, Transform.Identity);
|
barGeometry.Children.Add(barRect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push the created geometry
|
// Push the created geometry
|
||||||
c.PushClip(barGeometry);
|
c.PushClip(barGeometry);
|
||||||
BrushDraw(layerModel, c);
|
BrushDraw(layerModel, c);
|
||||||
c.Pop();
|
c.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
|
public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
|
||||||
{
|
{
|
||||||
layerModel.ApplyProperties(true);
|
layerModel.ApplyProperties(true);
|
||||||
_audioCapture.Pulse();
|
_audioCapture.Pulse();
|
||||||
|
|
||||||
var direction = ((AudioPropertiesModel) layerModel.Properties).Direction;
|
var direction = ((AudioPropertiesModel) layerModel.Properties).Direction;
|
||||||
|
|
||||||
int currentLines;
|
int currentLines;
|
||||||
double currentHeight;
|
double currentHeight;
|
||||||
if (direction == Direction.BottomToTop || direction == Direction.TopToBottom)
|
if (direction == Direction.BottomToTop || direction == Direction.TopToBottom)
|
||||||
{
|
{
|
||||||
currentLines = (int) layerModel.Width;
|
currentLines = (int) layerModel.Width;
|
||||||
currentHeight = layerModel.Height;
|
currentHeight = layerModel.Height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentLines = (int) layerModel.Height;
|
currentLines = (int) layerModel.Height;
|
||||||
currentHeight = layerModel.Width;
|
currentHeight = layerModel.Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lines != currentLines || _lineSpectrum == null)
|
if (_lines != currentLines || _lineSpectrum == null)
|
||||||
{
|
{
|
||||||
_lines = currentLines;
|
_lines = currentLines;
|
||||||
_lineSpectrum = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel);
|
_lineSpectrum = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newLineValues = _lineSpectrum?.GetLineValues(currentHeight);
|
var newLineValues = _lineSpectrum?.GetLineValues(currentHeight);
|
||||||
if (newLineValues != null)
|
if (newLineValues != null)
|
||||||
_lineValues = newLineValues;
|
_lineValues = newLineValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetupProperties(LayerModel layerModel)
|
public void SetupProperties(LayerModel layerModel)
|
||||||
{
|
{
|
||||||
if (layerModel.Properties is AudioPropertiesModel)
|
if (layerModel.Properties is AudioPropertiesModel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
layerModel.Properties = new AudioPropertiesModel(layerModel.Properties)
|
layerModel.Properties = new AudioPropertiesModel(layerModel.Properties)
|
||||||
{
|
{
|
||||||
DeviceType = MmDeviceType.Ouput,
|
DeviceType = MmDeviceType.Ouput,
|
||||||
Device = "Default",
|
Device = "Default",
|
||||||
Direction = Direction.BottomToTop,
|
Direction = Direction.BottomToTop,
|
||||||
ScalingStrategy = ScalingStrategy.Decibel
|
ScalingStrategy = ScalingStrategy.Decibel
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
|
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel,
|
||||||
LayerPropertiesViewModel layerPropertiesViewModel)
|
LayerPropertiesViewModel layerPropertiesViewModel)
|
||||||
{
|
{
|
||||||
if (layerPropertiesViewModel is AudioPropertiesViewModel)
|
if (layerPropertiesViewModel is AudioPropertiesViewModel)
|
||||||
return layerPropertiesViewModel;
|
return layerPropertiesViewModel;
|
||||||
return new AudioPropertiesViewModel(layerEditorViewModel);
|
return new AudioPropertiesViewModel(layerEditorViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BrushDraw(LayerModel layerModel, DrawingContext c)
|
public void BrushDraw(LayerModel layerModel, DrawingContext c)
|
||||||
{
|
{
|
||||||
// If an animation is present, let it handle the drawing
|
// If an animation is present, let it handle the drawing
|
||||||
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
|
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
|
||||||
{
|
{
|
||||||
layerModel.LayerAnimation.Draw(layerModel, c);
|
layerModel.LayerAnimation.Draw(layerModel, c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush
|
// Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush
|
||||||
var rect = layerModel.Properties.Contain
|
var rect = layerModel.Properties.Contain
|
||||||
? layerModel.LayerRect()
|
? layerModel.LayerRect()
|
||||||
: new Rect(layerModel.Properties.X*4, layerModel.Properties.Y*4,
|
: new Rect(layerModel.Properties.X*4, layerModel.Properties.Y*4,
|
||||||
layerModel.Properties.Width*4, layerModel.Properties.Height*4);
|
layerModel.Properties.Width*4, layerModel.Properties.Height*4);
|
||||||
|
|
||||||
var clip = layerModel.LayerRect();
|
var clip = layerModel.LayerRect();
|
||||||
|
|
||||||
// Can't meddle with the original brush because it's frozen.
|
// Can't meddle with the original brush because it's frozen.
|
||||||
var brush = layerModel.Brush.Clone();
|
var brush = layerModel.Brush.Clone();
|
||||||
brush.Opacity = layerModel.Opacity;
|
brush.Opacity = layerModel.Opacity;
|
||||||
|
|
||||||
c.PushClip(new RectangleGeometry(clip));
|
c.PushClip(new RectangleGeometry(clip));
|
||||||
c.DrawRectangle(brush, null, rect);
|
c.DrawRectangle(brush, null, rect);
|
||||||
c.Pop();
|
c.Pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,20 +6,19 @@ using System.Windows.Media;
|
|||||||
using Artemis.Managers;
|
using Artemis.Managers;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using Action = System.Action;
|
|
||||||
|
|
||||||
namespace Artemis.ViewModels
|
namespace Artemis.ViewModels
|
||||||
{
|
{
|
||||||
public class DebugViewModel : Screen
|
public class DebugViewModel : Screen
|
||||||
{
|
{
|
||||||
private readonly DeviceManager _deviceManager;
|
private readonly DeviceManager _deviceManager;
|
||||||
|
private DrawingImage _generic;
|
||||||
private DrawingImage _razerDisplay;
|
private DrawingImage _headset;
|
||||||
private DrawingImage _keyboard;
|
private DrawingImage _keyboard;
|
||||||
private DrawingImage _mouse;
|
private DrawingImage _mouse;
|
||||||
private DrawingImage _headset;
|
|
||||||
private DrawingImage _mousemat;
|
private DrawingImage _mousemat;
|
||||||
private DrawingImage _generic;
|
|
||||||
|
private DrawingImage _razerDisplay;
|
||||||
|
|
||||||
public DebugViewModel(DeviceManager deviceManager)
|
public DebugViewModel(DeviceManager deviceManager)
|
||||||
{
|
{
|
||||||
@ -116,8 +115,8 @@ namespace Artemis.ViewModels
|
|||||||
{
|
{
|
||||||
dc.PushClip(new RectangleGeometry(new Rect(0, 0, 22, 6)));
|
dc.PushClip(new RectangleGeometry(new Rect(0, 0, 22, 6)));
|
||||||
for (var y = 0; y < 6; y++)
|
for (var y = 0; y < 6; y++)
|
||||||
for (var x = 0; x < 22; x++)
|
for (var x = 0; x < 22; x++)
|
||||||
dc.DrawRectangle(new SolidColorBrush(colors[y, x]), null, new Rect(x, y, 1, 1));
|
dc.DrawRectangle(new SolidColorBrush(colors[y, x]), null, new Rect(x, y, 1, 1));
|
||||||
}
|
}
|
||||||
var drawnDisplay = new DrawingImage(visual.Drawing);
|
var drawnDisplay = new DrawingImage(visual.Drawing);
|
||||||
drawnDisplay.Freeze();
|
drawnDisplay.Freeze();
|
||||||
@ -137,10 +136,14 @@ namespace Artemis.ViewModels
|
|||||||
Keyboard = ImageUtilities.BitmapToDrawingImage(frame.KeyboardBitmap, rect);
|
Keyboard = ImageUtilities.BitmapToDrawingImage(frame.KeyboardBitmap, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mouse = ImageUtilities.BitmapToDrawingImage(frame.MouseBitmap, new Rect(0, 0, 10, 10));
|
if (frame.MouseBitmap != null)
|
||||||
Headset = ImageUtilities.BitmapToDrawingImage(frame.HeadsetBitmap, new Rect(0, 0, 10, 10));
|
Mouse = ImageUtilities.BitmapToDrawingImage(frame.MouseBitmap, new Rect(0, 0, 10, 10));
|
||||||
Mousemat = ImageUtilities.BitmapToDrawingImage(frame.MousematBitmap, new Rect(0, 0, 10, 10));
|
if (frame.HeadsetBitmap != null)
|
||||||
Generic = ImageUtilities.BitmapToDrawingImage(frame.GenericBitmap, new Rect(0, 0, 10, 10));
|
Headset = ImageUtilities.BitmapToDrawingImage(frame.HeadsetBitmap, new Rect(0, 0, 10, 10));
|
||||||
|
if (frame.MousematBitmap != null)
|
||||||
|
Mousemat = ImageUtilities.BitmapToDrawingImage(frame.MousematBitmap, new Rect(0, 0, 10, 10));
|
||||||
|
if (frame.GenericBitmap != null)
|
||||||
|
Generic = ImageUtilities.BitmapToDrawingImage(frame.GenericBitmap, new Rect(0, 0, 10, 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user