1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Implemented BottomToTop again

This commit is contained in:
SpoinkyNL 2017-01-12 19:50:56 +01:00
parent de0ff1ebad
commit 15275c83a0
13 changed files with 77 additions and 111 deletions

View File

@ -355,7 +355,7 @@
<Compile Include="Managers\LoopManager.cs" />
<Compile Include="Managers\LuaManager.cs" />
<Compile Include="Managers\MainManager.cs" />
<Compile Include="Managers\ProfileManager.cs" />
<Compile Include="Managers\PreviewManager.cs" />
<Compile Include="Modules\Abstract\ModuleDataModel.cs" />
<Compile Include="Modules\Abstract\ModuleModel.cs" />
<Compile Include="Modules\Abstract\ModuleSettings.cs" />
@ -622,6 +622,7 @@
<Compile Include="Utilities\Converters\NinjectCustomConverter.cs" />
<Compile Include="Utilities\Converters\ValueConverters.cs" />
<Compile Include="Utilities\DataReaders\DllManager.cs" />
<Compile Include="Utilities\EditorHelper.cs" />
<Compile Include="Utilities\ExtensionMethods.cs" />
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />

View File

@ -11,7 +11,7 @@ namespace Artemis.InjectionModules
Bind<LoopManager>().ToSelf().InSingletonScope();
Bind<DeviceManager>().ToSelf().InSingletonScope();
Bind<ModuleManager>().ToSelf().InSingletonScope();
Bind<ProfileManager>().ToSelf().InSingletonScope();
Bind<PreviewManager>().ToSelf().InSingletonScope();
Bind<LuaManager>().ToSelf().InSingletonScope();
}
}

View File

@ -22,14 +22,14 @@ namespace Artemis.Managers
private readonly Timer _processTimer;
public MainManager(ILogger logger, LoopManager loopManager, DeviceManager deviceManager,
ModuleManager moduleManager, ProfileManager profileManager, PipeServer pipeServer,
ModuleManager moduleManager, PreviewManager previewManager, PipeServer pipeServer,
GameStateWebServer gameStateWebServer)
{
Logger = logger;
LoopManager = loopManager;
DeviceManager = deviceManager;
ModuleManager = moduleManager;
ProfileManager = profileManager;
PreviewManager = previewManager;
PipeServer = pipeServer;
_processTimer = new Timer(1000);
@ -64,7 +64,7 @@ namespace Artemis.Managers
public LoopManager LoopManager { get; }
public DeviceManager DeviceManager { get; set; }
public ModuleManager ModuleManager { get; set; }
public ProfileManager ProfileManager { get; set; }
public PreviewManager PreviewManager { get; set; }
public PipeServer PipeServer { get; set; }
public GameStateWebServer GameStateWebServer { get; set; }

View File

@ -9,7 +9,7 @@ using Ninject.Extensions.Logging;
namespace Artemis.Managers
{
public class ProfileManager
public class PreviewManager
{
private readonly DeviceManager _deviceManager;
private readonly GeneralSettings _generalSettings;
@ -17,7 +17,7 @@ namespace Artemis.Managers
private readonly LoopManager _loopManager;
private readonly ModuleManager _moduleManager;
public ProfileManager(ILogger logger, ModuleManager moduleManager, DeviceManager deviceManager,
public PreviewManager(ILogger logger, ModuleManager moduleManager, DeviceManager deviceManager,
LoopManager loopManager)
{
_logger = logger;
@ -32,7 +32,7 @@ namespace Artemis.Managers
profilePreviewTimer.Elapsed += SetupProfilePreview;
profilePreviewTimer.Start();
_logger.Info("Intialized ProfileManager");
_logger.Info("Intialized PreviewManager");
}
public List<ModuleViewModel> PreviewViewModules { get; set; }

View File

@ -26,7 +26,6 @@ namespace Artemis.Modules.Abstract
_generalSettings = DAL.SettingsProvider.Load<GeneralSettings>();
ModuleModel = moduleModel;
Settings = moduleModel.Settings;
_mainManager.EnabledChanged += MainManagerOnEnabledChanged;
_moduleManager.EffectChanged += ModuleManagerOnModuleChanged;

View File

@ -13,7 +13,6 @@ namespace Artemis.Profiles.Layers.Types.Audio.AudioCapturing
public class AudioCapture
{
private const FftSize FftSize = CSCore.DSP.FftSize.Fft4096;
private readonly Timer _activityTimer;
private readonly Timer _volumeTimer;
private readonly double[] _volumeValues;
private SingleSpectrum _singleSpectrum;
@ -31,17 +30,15 @@ namespace Artemis.Profiles.Layers.Types.Audio.AudioCapturing
_volumeValues = new double[5];
_volumeIndex = 0;
_activityTimer = new Timer(1000);
_activityTimer.Elapsed += ActivityTimerOnElapsed;
_volumeTimer = new Timer(200);
_volumeTimer.Elapsed += VolumeTimerOnElapsed;
Start();
}
public double DesiredAverage { get; set; }
public bool MayStop { get; set; }
public ILogger Logger { get; }
public MMDevice Device { get; }
public double DesiredAverage { get; set; }
public float Volume
{
@ -49,9 +46,6 @@ namespace Artemis.Profiles.Layers.Types.Audio.AudioCapturing
set { _volume.Volume = value; }
}
public MMDevice Device { get; }
public bool Running { get; set; }
private void VolumeTimerOnElapsed(object sender, ElapsedEventArgs e)
{
if (Volume <= 0)
@ -95,20 +89,6 @@ namespace Artemis.Profiles.Layers.Types.Audio.AudioCapturing
}
}
private void ActivityTimerOnElapsed(object sender, ElapsedEventArgs e)
{
// If MayStop is true for longer than a second, this will stop the audio capture
if (MayStop)
{
Stop();
MayStop = false;
}
else
{
MayStop = true;
}
}
public LineSpectrum GetLineSpectrum(int barCount, ScalingStrategy scalingStrategy)
{
return new LineSpectrum(FftSize)
@ -121,39 +101,8 @@ namespace Artemis.Profiles.Layers.Types.Audio.AudioCapturing
};
}
public void Stop()
private void Start()
{
if (!Running)
return;
Logger.Debug("Stopping audio capture for device: {0}", Device?.FriendlyName ?? "default");
try
{
_activityTimer.Stop();
_volumeTimer.Stop();
_soundIn.Stop();
_soundIn.Dispose();
_source.Dispose();
_soundIn = null;
_source = null;
Running = false;
}
catch (Exception e)
{
Logger.Warn(e, "Failed to stop WASAPI audio capture");
}
}
public void Pulse()
{
MayStop = false;
if (Running)
return;
Logger.Debug("Starting audio capture for device: {0}", Device?.FriendlyName ?? "default");
try
@ -188,12 +137,8 @@ namespace Artemis.Profiles.Layers.Types.Audio.AudioCapturing
_singleSpectrum = new SingleSpectrum(FftSize, _spectrumProvider);
_activityTimer.Start();
_volumeTimer.Start();
_soundIn.Start();
Running = true;
MayStop = false;
}
catch (Exception e)
{

View File

@ -57,7 +57,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
switch (direction)
{
case Direction.BottomToTop:
case Direction.TopToBottom:
for (var index = 0; index < _lineValues.Count; index++)
{
var clipRect = new Rect((parentX + index)*4, parentY*4, 4, _lineValues[index]*4);
@ -65,10 +65,11 @@ namespace Artemis.Profiles.Layers.Types.Audio
barGeometry = Geometry.Combine(barGeometry, barRect, CombineMode, Transform.Identity);
}
break;
case Direction.TopToBottom:
case Direction.BottomToTop:
for (var index = 0; index < _lineValues.Count; index++)
{
var clipRect = new Rect((parentX + index)*4, parentY*4, 4, _lineValues[index]*4);
clipRect.Y = clipRect.Y + layerModel.Height*4 - clipRect.Height;
var barRect = new RectangleGeometry(clipRect);
barGeometry = Geometry.Combine(barGeometry, barRect, CombineMode, Transform.Identity);
}
@ -116,9 +117,6 @@ namespace Artemis.Profiles.Layers.Types.Audio
currentHeight = layerModel.Width;
}
// Let audio capture know it is being listened to
_audioCapture.Pulse();
if (_lines != currentLines || _lineSpectrum == null)
{
_lines = currentLines;

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artemis.Utilities
{
public static class EditorHelper
{
}
}

View File

@ -10,14 +10,14 @@ namespace Artemis.ViewModels
{
private readonly List<ModuleViewModel> _vms;
public GeneralViewModel(List<ModuleViewModel> moduleViewModels, ProfileManager profileManager)
public GeneralViewModel(List<ModuleViewModel> moduleViewModels, PreviewManager previewManager)
{
DisplayName = "General";
_vms = moduleViewModels.Where(m => !m.ModuleModel.IsOverlay && !m.ModuleModel.IsBoundToProcess)
.OrderBy(m => m.DisplayName).ToList();
profileManager.PreviewViewModules.Clear();
profileManager.PreviewViewModules.AddRange(moduleViewModels.Where(m => m.UsesProfileEditor));
previewManager.PreviewViewModules.Clear();
previewManager.PreviewViewModules.AddRange(moduleViewModels.Where(m => m.UsesProfileEditor));
}
protected override void OnActivate()

View File

@ -45,6 +45,8 @@ namespace Artemis.ViewModels.Profiles
private ObservableCollection<string> _profileNames;
private bool _saving;
private FileSystemWatcher _watcher;
private ProfileViewModel _profileViewModel;
private LayerModel _selectedLayer;
public ProfileEditorViewModel(DeviceManager deviceManager, LuaManager luaManager, ModuleModel moduleModel,
ProfileViewModel profileViewModel, MetroDialogService dialogService, WindowService windowService)
@ -62,13 +64,22 @@ namespace Artemis.ViewModels.Profiles
ProfileViewModel.ModuleModel = _moduleModel;
PropertyChanged += EditorStateHandler;
ProfileViewModel.PropertyChanged += LayerSelectedHandler;
_deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
_moduleModel.ProfileChanged += ModuleModelOnProfileChanged;
LoadProfiles();
}
public ProfileViewModel ProfileViewModel { get; set; }
public ProfileViewModel ProfileViewModel
{
get { return _profileViewModel; }
set
{
if (Equals(value, _profileViewModel)) return;
_profileViewModel = value;
NotifyOfPropertyChange();
NotifyOfPropertyChange(nameof(LayerSelected));
}
}
public bool EditorEnabled
=>
@ -76,6 +87,21 @@ namespace Artemis.ViewModels.Profiles
_deviceManager.ActiveKeyboard != null;
public ProfileModel SelectedProfile => _moduleModel?.ProfileModel;
public LayerModel SelectedLayer
{
get { return _selectedLayer; }
set
{
if (_profileViewModel != null)
_profileViewModel.SelectedLayer = value;
if (Equals(value, _selectedLayer))
return;
_selectedLayer = value;
NotifyOfPropertyChange(() => SelectedLayer);
NotifyOfPropertyChange(() => LayerSelected);
}
}
public ObservableCollection<string> ProfileNames
{
@ -126,7 +152,7 @@ namespace Artemis.ViewModels.Profiles
public PreviewSettings? PreviewSettings => _deviceManager.ActiveKeyboard?.PreviewSettings;
public bool ProfileSelected => SelectedProfile != null;
public bool LayerSelected => SelectedProfile != null && ProfileViewModel.SelectedLayer != null;
public bool LayerSelected => SelectedProfile != null && SelectedLayer != null;
public void DragOver(IDropInfo dropInfo)
{
@ -230,7 +256,7 @@ namespace Artemis.ViewModels.Profiles
public void EditLayerFromDoubleClick()
{
if (ProfileViewModel.SelectedLayer?.LayerType is FolderType)
if (SelectedLayer?.LayerType is FolderType)
return;
EditLayer();
@ -238,10 +264,10 @@ namespace Artemis.ViewModels.Profiles
public void EditLayer()
{
if (ProfileViewModel.SelectedLayer == null)
if (SelectedLayer == null)
return;
var selectedLayer = ProfileViewModel.SelectedLayer;
var selectedLayer = SelectedLayer;
EditLayer(selectedLayer);
}
@ -290,7 +316,7 @@ namespace Artemis.ViewModels.Profiles
if (SelectedProfile == null)
return null;
var layer = SelectedProfile.AddLayer(ProfileViewModel.SelectedLayer);
var layer = SelectedProfile.AddLayer(SelectedLayer);
UpdateLayerList(layer);
return layer;
@ -314,7 +340,7 @@ namespace Artemis.ViewModels.Profiles
/// </summary>
public void RemoveLayer()
{
RemoveLayer(ProfileViewModel.SelectedLayer);
RemoveLayer(SelectedLayer);
}
/// <summary>
@ -368,10 +394,10 @@ namespace Artemis.ViewModels.Profiles
/// </summary>
public void CloneLayer()
{
if (ProfileViewModel.SelectedLayer == null)
if (SelectedLayer == null)
return;
CloneLayer(ProfileViewModel.SelectedLayer);
CloneLayer(SelectedLayer);
}
/// <summary>
@ -390,7 +416,7 @@ namespace Artemis.ViewModels.Profiles
{
// Update the UI
Layers.Clear();
ProfileViewModel.SelectedLayer = null;
SelectedLayer = null;
if (SelectedProfile != null)
Layers.AddRange(SelectedProfile.Layers);
@ -402,7 +428,7 @@ namespace Artemis.ViewModels.Profiles
Task.Factory.StartNew(() =>
{
Thread.Sleep(100);
ProfileViewModel.SelectedLayer = selectModel;
SelectedLayer = selectModel;
});
}
@ -680,14 +706,6 @@ namespace Artemis.ViewModels.Profiles
NotifyOfPropertyChange(() => ProfileSelected);
}
private void LayerSelectedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != "SelectedLayer")
return;
NotifyOfPropertyChange(() => LayerSelected);
}
public void SaveSelectedProfile()
{
if (_saving || SelectedProfile == null || _deviceManager.ChangingKeyboard)

View File

@ -32,7 +32,6 @@ namespace Artemis.ViewModels.Profiles
private DrawingImage _keyboardPreview;
private Cursor _keyboardPreviewCursor;
private bool _resizing;
private LayerModel _selectedLayer;
private bool _showAll;
public ProfileViewModel(DeviceManager deviceManager, LoopManager loopManager)
@ -47,18 +46,9 @@ namespace Artemis.ViewModels.Profiles
}
public ModuleModel ModuleModel { get; set; }
public ProfileModel SelectedProfile => ModuleModel?.ProfileModel;
public LayerModel SelectedLayer { get; set; }
public LayerModel SelectedLayer
{
get { return _selectedLayer; }
set
{
if (Equals(value, _selectedLayer)) return;
_selectedLayer = value;
NotifyOfPropertyChange(() => SelectedLayer);
}
}
public ProfileModel SelectedProfile => ModuleModel?.ProfileModel;
public DrawingImage KeyboardPreview
{
@ -380,10 +370,13 @@ namespace Artemis.ViewModels.Profiles
public void Dispose()
{
Disposed = true;
_loopManager.RenderCompleted -= LoopManagerOnRenderCompleted;
_deviceManager.OnKeyboardChanged -= DeviceManagerOnOnKeyboardChanged;
}
public bool Disposed { get; set; }
#endregion
}
}

View File

@ -216,7 +216,7 @@ namespace Artemis.ViewModels
dialog.SetIndeterminate();
while (MainManager.DeviceManager.ChangingKeyboard)
await Task.Delay(10);
await Task.Delay(1000);
try
{

View File

@ -185,7 +185,7 @@
cal:Message.Attach="[Event MouseDoubleClick] = [Action EditLayerFromDoubleClick]">
<i:Interaction.Behaviors>
<itemBehaviours:BindableSelectedItemBehavior
SelectedItem="{Binding ProfileViewModel.SelectedLayer, Mode=TwoWay}" />
SelectedItem="{Binding SelectedLayer, Mode=TwoWay}" />
</i:Interaction.Behaviors>
<TreeView.Resources>
<ResourceDictionary