Skip to content

Commit

Permalink
Start filling in more of the AE-10 schema
Browse files Browse the repository at this point in the history
At the moment there are some very odd fields - this is all very experimental at the moment.
  • Loading branch information
jskeet committed Aug 11, 2020
1 parent ff3d3e9 commit adf6869
Show file tree
Hide file tree
Showing 11 changed files with 773 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public int RawValue
{
if (!TrySetRawValue(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
throw new ArgumentOutOfRangeException(nameof(value), $"Invalid raw value {value} for field {SchemaField.Path}");
}
}
}
Expand Down
24 changes: 10 additions & 14 deletions Drums/VDrumExplorer.Model/Schema/Fields/BooleanField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by the Apache License 2.0,
// as found in the LICENSE.txt file.

using System;
using System.Collections.Concurrent;
using VDrumExplorer.Model.Schema.Physical;

namespace VDrumExplorer.Model.Schema.Fields
Expand All @@ -12,25 +12,21 @@ namespace VDrumExplorer.Model.Schema.Fields
/// </summary>
public sealed class BooleanField : NumericFieldBase
{
private static readonly NumericFieldBaseParameters Boolean8Parameters =
new NumericFieldBaseParameters(min: 0, max: 1, @default: 0, NumericCodec.Range8);
private static ConcurrentDictionary<NumericCodec, NumericFieldBaseParameters> parameterCache =
new ConcurrentDictionary<NumericCodec, NumericFieldBaseParameters>();

private static readonly NumericFieldBaseParameters Boolean32Parameters =
new NumericFieldBaseParameters(min: 0, max: 1, @default: 0, NumericCodec.Range32);

internal BooleanField(FieldContainer? parent, FieldParameters common)
: base(parent, common, GetBaseParametersForSize(common.Size))
private BooleanField(FieldContainer? parent, FieldParameters common, NumericFieldBaseParameters numericBaseParameters)
: base(parent, common, numericBaseParameters)
{
}

private static NumericFieldBaseParameters GetBaseParametersForSize(int size) => size switch
internal BooleanField(FieldContainer? parent, FieldParameters common, NumericCodec codec)
: this(parent, common,
parameterCache.GetOrAdd(codec, c => new NumericFieldBaseParameters(min: 0, max: 1, @default: 0, c)))
{
1 => Boolean8Parameters,
4 => Boolean32Parameters,
_ => throw new ArgumentOutOfRangeException($"Invalid size: {size}")
};
}

internal override FieldBase WithParent(FieldContainer parent) =>
new BooleanField(parent, Parameters);
new BooleanField(parent, Parameters, NumericBaseParameters);
}
}
20 changes: 20 additions & 0 deletions Drums/VDrumExplorer.Model/Schema/Fields/NumericCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ internal sealed class NumericCodec
internal static NumericCodec Full24 { get; } = new NumericCodec(3, ReadFull24, WriteFull24, 0, (1 << 21) - 1);
internal static NumericCodec Range32 { get; } = new NumericCodec(4, ReadRange32, WriteRange32, short.MinValue, short.MaxValue);

internal static NumericCodec Fixme32 { get; } = new NumericCodec(4, ReadFixme32, WriteFixme32, -20000, 2000);

private delegate void Int32Writer(Span<byte> data, int value);
private delegate int Int32Reader(ReadOnlySpan<byte> data);

Expand Down Expand Up @@ -82,5 +84,23 @@ private static void WriteRange32(Span<byte> data, int value)
data[2] = (byte) ((value >> 4) & 0xf);
data[3] = (byte) ((value >> 0) & 0xf);
}

// FIXME: I don't really understand these, but they're the reverb values on the AE-10

private static int ReadFixme32(ReadOnlySpan<byte> data) =>
(short)
((data[0] & 0x0700_0000 << 12) |
(data[1] << 8) |
(data[2] << 4) |
(data[3] << 0));

private static void WriteFixme32(Span<byte> data, int value)
{
value = value | 0x0800_0000;
data[0] = (byte) ((value >> 12) & 0xf);
data[1] = (byte) ((value >> 8) & 0xf);
data[2] = (byte) ((value >> 4) & 0xf);
data[3] = (byte) ((value >> 0) & 0xf);
}
}
}
2 changes: 1 addition & 1 deletion Drums/VDrumExplorer.Model/Schema/Fields/TempoField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal TempoField(FieldContainer? parent, FieldParameters common, int min, int
int? divisor, int? multiplier, int? valueOffset, string? suffix, (int value, string text)? customValueFormatting)
: this(
parent, common,
new BooleanField(parent, new FieldParameters(common.Name + "Sync", common.Description + " Sync", common.Offset, 4)),
new BooleanField(parent, new FieldParameters(common.Name + "Sync", common.Description + " Sync", common.Offset, 4), NumericCodec.Range32),
new NumericField(parent, new FieldParameters(common.Name + "Numeric", common.Description + " FIXME", common.Offset + 4, 4), min, max, @default, NumericCodec.Range32, divisor, multiplier, valueOffset, suffix, customValueFormatting),
new EnumField(parent, new FieldParameters(common.Name + "Note", common.Description + " FIXME", common.Offset + 8, 4), MusicalNoteValues, 0, NumericCodec.Range32))
{
Expand Down
7 changes: 5 additions & 2 deletions Drums/VDrumExplorer.Model/Schema/Json/FieldJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ internal FieldBase ToField(ModuleJson module, string name, string description, M
{
return Type switch
{
"boolean" => new BooleanField(null, BuildCommon(1)),
"boolean32" => new BooleanField(null, BuildCommon(4)),
"boolean" => new BooleanField(null, BuildCommon(1), NumericCodec.Range8),
"boolean32" => new BooleanField(null, BuildCommon(4), NumericCodec.Range32),
string ph when ph.StartsWith("placeholder") => new PlaceholderField(null, BuildCommon(int.Parse(ph.Substring("placeholder".Length)) / 8)),
"enum" => BuildEnumField(NumericCodec.Range8),
"enum16" => BuildEnumField(NumericCodec.Range16),
Expand All @@ -154,6 +154,9 @@ internal FieldBase ToField(ModuleJson module, string name, string description, M
"string16" => BuildStringField(2),
"tempo" => BuildTempoField(),
"volume32" => new NumericField(null, BuildCommon(4), -601, 60, 0, NumericCodec.Range32, 10, null, 0, "dB", (-601, "-INF")),
"fixme_enum32" => BuildEnumField(NumericCodec.Fixme32),
"fixme_range32" => BuildNumericField(NumericCodec.Fixme32),
"fixme_boolean32" => new BooleanField(null, BuildCommon(4), NumericCodec.Fixme32),
_ => throw new InvalidOperationException($"Invalid field type: '{Type}'")
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,73 @@
{
"description": "Off",
"fields": [
{
"description": "Pre delay",
"type": "fixme_range32",
// FIXME: This has variable-sensitivity
"min": 0,
"max": 100
},
{
"description": "Rate",
"type": "fixme_range32",
"min": 0,
"max": 199,
"valueOffset": 1,
"divisor": 20
},
{
"description": "Depth",
"type": "fixme_range32",
"min": 0,
"max": 127
},
{
"description": "Feedback",
"type": "fixme_range32",
"min": 0,
"max": 127
},
{
"description": "Filter type",
"type": "fixme_enum32",
"valuesByNumber": [
[0, "Off"],
[5, "LPF"],
[10, "HPF"]
]
},
{
"description": "Filter cutoff",
"type": "fixme_enum32",
"values": [
"200Hz",
"250Hz",
"315Hz",
"400Hz",
"500Hz",
"630Hz",
"800Hz",
"1000Hz",
"1250Hz",
"1600Hz",
"2000Hz",
"2500Hz",
"3150Hz",
"4000Hz",
"5000Hz",
"6300Hz",
"8000Hz",
"FIXME",
"FIXME 2"
]
},
{
"description": "Phase",
"type": "fixme_range32",
"min": 0,
"max": 180,
"suffix": "deg"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
{
"description": "Off",
"description": "GM2 Reverb",
"fields": [
{
"description": "Character",
"type": "fixme_range32",
"min": 0,
"max": 7
},
{
"description": "Pre-LPF",
"type": "fixme_range32",
"min": 0,
"max": 7
},
{
"description": "Time",
"type": "fixme_range32",
"min": 0,
"max": 127,
"default": 64
},
{
"description": "Delay Feedback",
"type": "fixme_range32",
"min": 0,
"max": 127,
"default": 64
},
{
"description": "Level",
"type": "fixme_range32",
"min": 0,
"max": 127,
"default": 64
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
{
"description": "Off",
"description": "Reverb",
"fields": [
{
"description": "Type",
"type": "fixme_enum32",
"values": [
"Room 1",
"Room 2",
"Stage 1",
"Stage 2",
"Hall 1",
"Hall 2",
"Delay",
"Pan-Delay"
]
},
{
"description": "Time",
"type": "fixme_range32",
"min": 0,
"max": 127
},
{
"description": "HF Damp",
"type": "fixme_enum32",
"values": [
"160Hz",
"200Hz",
"250Hz",
"320Hz",
"400Hz",
"500Hz",
"640Hz",
"800Hz",
"1000Hz",
"1250Hz",
"1600Hz",
"2000Hz",
"2500Hz",
"3200Hz",
"4000Hz",
"5000Hz",
"6400Hz",
"8000Hz"
]
},
{
"description": "Delay Feedback",
"type": "fixme_range32",
"min": 0,
"max": 127
}
]
}
Loading

0 comments on commit adf6869

Please sign in to comment.