Skip to content

Commit ca82209

Browse files
Merge pull request #17 from OpenTabletDriver/pipeline-element-port
Port to pipeline elements
2 parents 068abb2 + 9586204 commit ca82209

File tree

12 files changed

+187
-121
lines changed

12 files changed

+187
-121
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[*.{csproj,props,target}]
14+
indent_size = 2

.github/workflows/dotnet.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v2
21-
with:
21+
with:
2222
submodules: true
2323

2424
- name: Setup .NET Core
2525
uses: actions/setup-dotnet@v1
2626
with:
27-
dotnet-version: 5.0.100
27+
dotnet-version: '6.0'
2828

2929
- name: Filters Build
30-
env:
31-
framework: net5
32-
run: dotnet build ${{ matrix.Filters }}/${{ matrix.Filters }}.csproj -f $framework -o ./build
30+
run: dotnet build ${{ matrix.Filters }}/${{ matrix.Filters }}.csproj -o ./build
3331

3432
- name: Upload Filters artifact
3533
uses: actions/upload-artifact@master

.modules/OpenTabletDriver

Submodule OpenTabletDriver updated 722 files
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Numerics;
2+
using OpenTabletDriver.Plugin.Attributes;
3+
using OpenTabletDriver.Plugin.Output;
4+
using OpenTabletDriver.Plugin.Tablet;
5+
6+
namespace TabletDriverFilters
7+
{
8+
public abstract class MillimeterAsyncPositionedPipelineElement : AsyncPositionedPipelineElement<IDeviceReport>
9+
{
10+
[TabletReference]
11+
public TabletReference TabletReference { set => HandleTabletReferenceInternal(value); }
12+
13+
protected Vector2 MillimeterScale;
14+
15+
private void HandleTabletReferenceInternal(TabletReference tabletReference)
16+
{
17+
var digitizer = tabletReference.Properties.Specifications.Digitizer;
18+
MillimeterScale = new Vector2
19+
{
20+
X = digitizer.Width / digitizer.MaxX,
21+
Y = digitizer.Height / digitizer.MaxY
22+
};
23+
HandleTabletReference(tabletReference);
24+
}
25+
26+
protected virtual void HandleTabletReference(TabletReference tabletReference)
27+
{
28+
// Override when needed
29+
}
30+
}
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Numerics;
3+
using OpenTabletDriver.Plugin.Attributes;
4+
using OpenTabletDriver.Plugin.Output;
5+
using OpenTabletDriver.Plugin.Tablet;
6+
7+
namespace TabletDriverFilters
8+
{
9+
public abstract class MillimeterPositionedPipelineElement : IPositionedPipelineElement<IDeviceReport>
10+
{
11+
protected Vector2 MillimeterScale;
12+
13+
[TabletReference]
14+
public TabletReference TabletReference { set => HandleTabletReferenceInternal(value); }
15+
public abstract PipelinePosition Position { get; }
16+
public abstract event Action<IDeviceReport> Emit;
17+
public abstract void Consume(IDeviceReport value);
18+
19+
private void HandleTabletReferenceInternal(TabletReference tabletReference)
20+
{
21+
var digitizer = tabletReference.Properties.Specifications.Digitizer;
22+
MillimeterScale = new Vector2
23+
{
24+
X = digitizer.Width / digitizer.MaxX,
25+
Y = digitizer.Height / digitizer.MaxY
26+
};
27+
HandleTabletReference(tabletReference);
28+
}
29+
30+
protected virtual void HandleTabletReference(TabletReference tabletReference)
31+
{
32+
// Override when needed
33+
}
34+
}
35+
}

DevocubFilters/AntiChatter.cs

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
using System;
22
using System.Numerics;
3-
using OpenTabletDriver.Plugin;
43
using OpenTabletDriver.Plugin.Attributes;
5-
using OpenTabletDriver.Plugin.Tablet.Interpolator;
6-
using OpenTabletDriver.Plugin.Timers;
4+
using OpenTabletDriver.Plugin.Output;
5+
using OpenTabletDriver.Plugin.Tablet;
76

87
namespace TabletDriverFilters.Devocub
98
{
10-
using static MathF;
11-
129
[PluginName("Devocub Antichatter")]
13-
public class Antichatter : Interpolator
10+
public class Antichatter : MillimeterAsyncPositionedPipelineElement
1411
{
1512
private const string LATENCY_TOOLTIP =
1613
"Smoothing latency\n"
@@ -43,7 +40,7 @@ public class Antichatter : Interpolator
4340
+ "\n"
4441
+ " - Smooth: Latency ~10 ms, Strength 3, Multiplier 100, OffsetX 1.5, OffsetY 1.\n"
4542
+ " Change OffsetX between 0-2 to switch between stickiness and smooth.\n"
46-
+ " Increase Strength to 4-10 to get sharper changes in smoothing. Decrease Strength to 1-2 to get more smoothing.\n"
43+
+ " Increase Strength to 4-10 to get harper. Decrease Strength to 1-2 to get more smoothing.\n"
4744
+ "\n"
4845
+ " - Low latency: Set Offset Y to 0 (and potentially set Latency to 1-10 ms. However, with some settings this can break smoothing, usually OffsetY 0 is enough to being able to go to lowest latency).";
4946
private const string PREDICTION_TOOLTIP =
@@ -73,10 +70,7 @@ public class Antichatter : Interpolator
7370
+ " Smoothing: Latency 40ms, Strength 3, Multiplier 10, OffsetX 1, OffsetY 1\n"
7471
+ " Prediction: Strength 4, Sharpness 0.75, Offset 2.5, OffsetY 1";
7572

76-
public Antichatter(ITimer scheduler) : base(scheduler)
77-
{
78-
GetMMScale();
79-
}
73+
public override PipelinePosition Position => PipelinePosition.PreTransform;
8074

8175
[SliderProperty("Latency", 0f, 1000f, 2f), DefaultPropertyValue(2f), ToolTip(LATENCY_TOOLTIP)]
8276
public float Latency
@@ -98,8 +92,8 @@ public float Latency
9892
public float AntichatterOffsetY { set; get; }
9993

10094
[BooleanProperty("Prediction", ""), ToolTip(PREDICTION_TOOLTIP)]
101-
10295
public bool PredictionEnabled { set; get; }
96+
10397
[Property("Prediction Strength"), DefaultPropertyValue(1.1f), ToolTip(PREDICTION_TOOLTIP)]
10498
public float PredictionStrength { set; get; }
10599

@@ -117,45 +111,52 @@ public float Latency
117111
private float timerInterval => 1000 / Frequency;
118112
private float latency = 2.0f;
119113
private float weight;
120-
private Vector2 mmScale;
121114
private Vector2 position;
122115
private Vector2 prevTargetPos, targetPos, calcTarget;
123-
private SyntheticTabletReport report;
124116

125-
public override void UpdateState(SyntheticTabletReport report)
117+
protected override void ConsumeState()
126118
{
127-
this.targetPos = report.Position * mmScale;
128-
129-
if (PredictionEnabled)
119+
if (State is ITabletReport report)
130120
{
131-
// Calculate predicted position onNewPacket
132-
if (this.prevTargetPos.X != this.targetPos.X || this.prevTargetPos.Y != this.targetPos.Y)
133-
{
134-
// Calculate distance between last 2 packets and prediction
135-
var delta = this.targetPos - this.prevTargetPos;
136-
var distance = Vector2.Distance(this.prevTargetPos, this.targetPos);
137-
var predictionModifier = 1 / Cosh((distance - PredictionOffsetX) * PredictionSharpness) * PredictionStrength + PredictionOffsetY;
138-
139-
// Apply prediction
140-
delta *= predictionModifier;
141-
142-
// Update predicted position
143-
this.calcTarget = this.targetPos + delta;
121+
this.targetPos = report.Position * MillimeterScale;
144122

145-
// Update old position for further prediction
146-
this.prevTargetPos = this.targetPos;
123+
if (PredictionEnabled)
124+
{
125+
// Calculate predicted position onNewPacket
126+
if (this.prevTargetPos.X != this.targetPos.X || this.prevTargetPos.Y != this.targetPos.Y)
127+
{
128+
// Calculate distance between last 2 packets and prediction
129+
var delta = this.targetPos - this.prevTargetPos;
130+
var distance = Vector2.Distance(this.prevTargetPos, this.targetPos);
131+
var predictionModifier = 1 / MathF.Cosh((distance - PredictionOffsetX) * PredictionSharpness) * PredictionStrength + PredictionOffsetY;
132+
133+
// Apply prediction
134+
delta *= predictionModifier;
135+
136+
// Update predicted position
137+
this.calcTarget = this.targetPos + delta;
138+
139+
// Update old position for further prediction
140+
this.prevTargetPos = this.targetPos;
141+
}
147142
}
143+
else
144+
calcTarget = targetPos;
148145
}
149-
else
150-
calcTarget = targetPos;
151-
152-
this.report = report;
153146
}
154147

155-
public override SyntheticTabletReport Interpolate()
148+
protected override void UpdateState()
156149
{
157-
this.report.Position = Filter(this.calcTarget) / mmScale;
158-
return this.report;
150+
if (State is ITabletReport report)
151+
{
152+
report.Position = Filter(calcTarget) / MillimeterScale;
153+
State = report;
154+
}
155+
156+
if (PenIsInRange() || State is not ITabletReport)
157+
{
158+
OnEmit();
159+
}
159160
}
160161

161162
public Vector2 Filter(Vector2 calcTarget)
@@ -173,7 +174,7 @@ public Vector2 Filter(Vector2 calcTarget)
173174

174175
// Devocub smoothing
175176
// Increase weight of filter in {formula} times
176-
var weightModifier = (float)(Pow(distance + AntichatterOffsetX, AntichatterStrength * -1) * AntichatterMultiplier);
177+
var weightModifier = (float)(MathF.Pow(distance + AntichatterOffsetX, AntichatterStrength * -1) * AntichatterMultiplier);
177178

178179
// Limit minimum
179180
if (weightModifier + AntichatterOffsetY < 0)
@@ -194,15 +195,5 @@ private void SetWeight(float latency)
194195
float target = 1 - THRESHOLD;
195196
this.weight = 1f - (1f / MathF.Pow(1f / target, 1f / stepCount));
196197
}
197-
198-
private void GetMMScale()
199-
{
200-
var digitizer = Info.Driver.Tablet.Digitizer;
201-
this.mmScale = new Vector2
202-
{
203-
X = digitizer.Width / digitizer.MaxX,
204-
Y = digitizer.Height / digitizer.MaxY
205-
};
206-
}
207198
}
208199
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net5</TargetFramework>
5-
</PropertyGroup>
6-
7-
<ItemGroup>
8-
<ProjectReference Include="../.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
9-
</ItemGroup>
10-
112
</Project>

Directory.Build.props

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="$(MSBuildThisFileDirectory)/.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
9+
<Compile Include="$(MSBuildThisFileDirectory)/Common/*.cs" />
10+
</ItemGroup>
11+
12+
</Project>

HawkuFilters/HawkuFilters.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net5</TargetFramework>
5-
</PropertyGroup>
6-
7-
<ItemGroup>
8-
<ProjectReference Include="../.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
9-
</ItemGroup>
10-
112
</Project>

0 commit comments

Comments
 (0)