Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/Clickwheel/DataTypes/EQPreset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Clickwheel.Exceptions;
using Clickwheel.Parsers;

namespace Clickwheel.DataTypes
{
public sealed record EQPreset
{
private static readonly Dictionary<int, EQPreset> Presets = new();

public static readonly EQPreset Acoustic = new(100);
public static readonly EQPreset BassBooster = new(101);
public static readonly EQPreset BassReducer = new(102);
public static readonly EQPreset Classical = new(103);
public static readonly EQPreset Dance = new(104);
public static readonly EQPreset Deep = new(105);
public static readonly EQPreset Electronic = new(106);
public static readonly EQPreset Flat = new(107);
public static readonly EQPreset HipHop = new(108);
public static readonly EQPreset Jazz = new(109);
public static readonly EQPreset Latin = new(110);
public static readonly EQPreset Loudness = new(111);
public static readonly EQPreset Lounge = new(112);
public static readonly EQPreset Piano = new(113);
public static readonly EQPreset Pop = new(114);
public static readonly EQPreset RhythmAndBlues = new(115);
public static readonly EQPreset Rock = new(116);
public static readonly EQPreset SmallSpeakers = new(117);
public static readonly EQPreset SpokenWord = new(118);
public static readonly EQPreset TrebleBooster = new(119);
public static readonly EQPreset TrebleReducer = new(120);
public static readonly EQPreset VocalBooster = new(121);

public string Name { get; init; }
public int ID { get; init; }

private EQPreset(int id, [CallerMemberName] string name = "") : this(name, id) {}
private EQPreset(string name, int id)
{
Name = name;
ID = id;
Presets.Add(id, this);
}

private const string _magicString = "#!#";

public static string EncodeAsString(EQPreset preset)
{
if (preset == null)
return "";

return $"{_magicString}{preset.ID}{_magicString}";
}

public static EQPreset DecodeFromString(string input)
{
if (input == "") return null;

if ( input.Length != 9 // three digit code, plus prefix and suffix
|| !input.StartsWith(_magicString)
|| !input.EndsWith(_magicString)
|| !int.TryParse(input.Substring(3, 3), out var id)
) throw new ParseException($"\"{input}\" is not a valid EQ Preset ID.", null);

return Presets.GetValueOrDefault(id) ?? new EQPreset("Unknown EQ Preset", id);
}
}
}
3 changes: 3 additions & 0 deletions src/Clickwheel/NewTrack.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Clickwheel.DataTypes;

namespace Clickwheel
{
/// <summary>
Expand All @@ -11,6 +13,7 @@ public class NewTrack
public string Title;
public string Artist;
public string Album;
public EQPreset EQPreset;
public string Comments;

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Clickwheel/Parsers/iTunesDB/MHOD/BaseMHODElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static class MHODElementType
public const int Artist = 4;
public const int Genre = 5;
public const int FileType = 6;
public const int EQPreset = 7;
public const int Comment = 8;
public const int Composer = 12;
public const int DescriptionText = 14;
Expand Down
1 change: 1 addition & 0 deletions src/Clickwheel/Parsers/iTunesDB/MHOD/MHODFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static BaseMHODElement ReadMHOD(IPod iPod, BinaryReader reader)
case MHODElementType.Artist:
case MHODElementType.Genre:
case MHODElementType.FileType:
case MHODElementType.EQPreset:
case MHODElementType.Comment:
case MHODElementType.Composer:
case MHODElementType.AlbumArtist:
Expand Down
10 changes: 10 additions & 0 deletions src/Clickwheel/Parsers/iTunesDB/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ public string Album
}
}
}

public EQPreset EQPreset {
get => EQPreset.DecodeFromString(GetDataElement(MHODElementType.EQPreset));
set => SetDataElement(MHODElementType.EQPreset, EQPreset.EncodeAsString(value));
}

public string Comment
{
Expand Down Expand Up @@ -766,6 +771,7 @@ private void SetDataElement(int type, string data)
if (string.IsNullOrEmpty(data))
{
_childSections.Remove(mhod);
_isDirty = true;
return;
}
mhod.Data = data;
Expand Down Expand Up @@ -817,6 +823,10 @@ internal void Create(IPod iPod, NewTrack newTrack)
this.Artist = newTrack.Artist;
}

if (newTrack.EQPreset != null) {
this.EQPreset = newTrack.EQPreset;
}

if (!string.IsNullOrEmpty(newTrack.Comments))
{
this.Comment = newTrack.Comments;
Expand Down
Loading