using Nonemm.Core; namespace Nonemm.Session; /// Where the operator was last on each band and mode. The band buttons use it, /// so moving to 40 metres and back puts the radio where it was rather than at /// the band edge. N1MM remembers the same thing. public sealed class BandMemory { private readonly Dictionary<(string Band, ModeCategory Mode), Frequency> places = []; public void Remember(Frequency frequency, Mode mode) { if (Bands.ForFrequency(frequency) is { } band) { places[(band.Name, mode.Category)] = frequency; } } /// Where to go for that band and mode: where the operator left it, or the /// start of that part of the band. A band the plan says nothing about /// starts at its bottom edge. public Frequency Where(Band band, ModeCategory mode, BandPlan plan) { if (places.TryGetValue((band.Name, mode), out Frequency remembered)) { return remembered; } BandSegments? segments = plan.For(band); return mode switch { ModeCategory.Phone when segments is { HasPhone: true } => segments.PhoneLow, ModeCategory.Digital when segments is { HasDigital: true } => segments.DigitalLow, _ => band.Low, }; } }