Skip to content

Commit 9ea4b5f

Browse files
authored
Merge pull request #6 from coraxx/avalonia11
Avalonia11
2 parents b040409 + 9027298 commit 9ea4b5f

21 files changed

+1110
-1559
lines changed

Libs/ScottPlot.Avalonia.deps.json

Lines changed: 0 additions & 765 deletions
This file was deleted.

Libs/ScottPlot.Avalonia.dll

-512 Bytes
Binary file not shown.

Libs/ScottPlot.deps.json

Lines changed: 0 additions & 183 deletions
This file was deleted.

Libs/ScottPlot.dll

0 Bytes
Binary file not shown.

MergeSynced.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.5.33502.453
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MergeSync", "MergeSynced\MergeSynced.csproj", "{C40C709A-CA51-4A72-891B-54C1EA72758C}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MergeSynced", "MergeSynced\MergeSynced.csproj", "{C40C709A-CA51-4A72-891B-54C1EA72758C}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

MergeSynced/App.axaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
<Application xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:local="using:MergeSynced"
4-
x:Class="MergeSynced.App" Name="MergeSynced">
4+
x:Class="MergeSynced.App"
5+
Name="MergeSynced"
6+
RequestedThemeVariant="Default">
57

68
<NativeMenu.Menu>
79
<NativeMenu>
8-
<NativeMenuItem Header="About Merge Synced" Click="AboutMenuItem_OnClick" />
10+
<NativeMenuItem Header="About MergeSynced" Click="AboutMenuItem_OnClick" />
911
</NativeMenu>
1012
</NativeMenu.Menu>
1113

1214
<Application.Styles>
13-
<FluentTheme Mode="Light"/>
14-
<!--<StyleInclude Source="/Controls/CustomCheckBox.axaml" />-->
15+
<FluentTheme>
16+
<FluentTheme.Palettes>
17+
<ColorPaletteResources x:Key="Dark"
18+
RegionColor="#FF232323"
19+
AltHigh="#FF232323"
20+
AltLow="#FF232323"
21+
AltMedium="#FF232323"
22+
AltMediumHigh="#FF232323"
23+
AltMediumLow="#FF232323" />
24+
</FluentTheme.Palettes>
25+
</FluentTheme>
1526
</Application.Styles>
1627

1728
<Application.Resources>

MergeSynced/App.axaml.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
22
using Avalonia;
33
using Avalonia.Controls.ApplicationLifetimes;
4+
using Avalonia.Data.Core.Plugins;
45
using Avalonia.Markup.Xaml;
5-
using MergeSynced.ViewModels;
6+
using MergeSynced.Views;
67

78
namespace MergeSynced
89
{
@@ -17,7 +18,10 @@ public override void OnFrameworkInitializationCompleted()
1718
{
1819
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
1920
{
20-
desktop.MainWindow = new Views.MainWindow();
21+
// Line below is needed to remove Avalonia data validation.
22+
// Without this line you will get duplicate validations from both Avalonia and CT
23+
BindingPlugins.DataValidators.RemoveAt(0);
24+
desktop.MainWindow = new MainWindow();
2125
}
2226

2327
base.OnFrameworkInitializationCompleted();

MergeSynced/Audio/WavTools.cs

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class WavTools
1717
/// <param name="l">Output of left channel</param>
1818
/// <param name="r">Output of right channel</param>
1919
/// <returns>Details of wav file</returns>
20-
public WavHeader? ReadWav(string filename, out float[]? l, out float[]? r)
20+
public static WavHeader? ReadWav(string filename, out float[]? l, out float[]? r)
2121
{
2222
l = r = null;
2323

@@ -161,7 +161,7 @@ public class WavTools
161161
/// <param name="filename">Path to file name</param>
162162
/// <param name="m">Output of left channel</param>
163163
/// <returns>Details of wav file</returns>
164-
public WavHeader? ReadWav(string filename, out float[]? m)
164+
public static WavHeader? ReadWav(string filename, out float[]? m)
165165
{
166166
m = null;
167167

@@ -290,5 +290,86 @@ public class WavTools
290290
return null;
291291
}
292292
}
293+
294+
/// <summary>
295+
/// Source: https://gist.github.com/adrianseeley/264417d295ccd006e7fd
296+
/// </summary>
297+
/// <param name="array">Input data</param>
298+
/// <param name="length">Length of return array</param>
299+
/// <returns></returns>
300+
public static float[] Downsample(float[] array, int length)
301+
{
302+
int insert = 0;
303+
float[] window = new float[length];
304+
float[] windowX = new float[length];
305+
int bucketSizeLessStartAndEnd = length - 2;
306+
307+
float bucketSize = (float)(array.Length - 2) / bucketSizeLessStartAndEnd;
308+
int a = 0;
309+
int nextA = 0;
310+
int maxAreaPointX = 0;
311+
float maxAreaPointY = 0f;
312+
window[insert] = array[a]; // Always add the first point
313+
windowX[insert] = 0;
314+
insert++;
315+
for (int i = 0; i < bucketSizeLessStartAndEnd; i++)
316+
{
317+
// Calculate point average for next bucket (containing c)
318+
float avgX = 0;
319+
float avgY = 0;
320+
int start = (int)(Math.Floor((i + 1) * bucketSize) + 1);
321+
int end = (int)(Math.Floor((i + 2) * bucketSize) + 1);
322+
if (end >= array.Length)
323+
{
324+
end = array.Length;
325+
}
326+
int span = end - start;
327+
for (; start < end; start++)
328+
{
329+
avgX += start;
330+
avgY += array[start];
331+
}
332+
avgX /= span;
333+
avgY /= span;
334+
335+
// Get the range for this bucket
336+
int bucketStart = (int)(Math.Floor((i + 0) * bucketSize) + 1);
337+
int bucketEnd = (int)(Math.Floor((i + 1) * bucketSize) + 1);
338+
bucketEnd = bucketEnd > array.Length ? array.Length : bucketEnd;
339+
340+
// Point a
341+
float aX = a;
342+
float aY = array[a];
343+
float maxArea = -1;
344+
for (; bucketStart < bucketEnd; bucketStart++)
345+
{
346+
// Calculate triangle area over three buckets
347+
if (bucketStart >= array.Length)
348+
{
349+
continue;
350+
};
351+
float area = Math.Abs((aX - avgX) * (array[bucketStart] - aY) - (aX - (float)bucketStart) * (avgY - aY)) * 0.5f;
352+
if (area > maxArea)
353+
{
354+
maxArea = area;
355+
maxAreaPointX = bucketStart;
356+
maxAreaPointY = array[bucketStart];
357+
nextA = bucketStart; // Next a is this b
358+
}
359+
}
360+
// Pick this point from the Bucket
361+
window[insert] = maxAreaPointY;
362+
windowX[insert] = maxAreaPointX;
363+
insert++;
364+
365+
// Current a becomes the next_a (chosen b)
366+
a = nextA;
367+
}
368+
369+
window[insert] = array[^1]; // Always add last
370+
windowX[insert] = array.Length;
371+
372+
return window;
373+
}
293374
}
294375
}

0 commit comments

Comments
 (0)