Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

3.0 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
// The arm buttons' side of exclusive record-arm (#332, rule in Nota.Presentation.TrackArm):
// every arm button (Arrangement header, Session mixer, Mixer window) goes through here, and
// the views repaint when an arm disarmed other tracks.

using System;
using Nota.Application;
using Nota.Presentation;
using Nota.Application.Localization;

namespace Nota.App;

internal static class TrackArming
{
    /// <summary>Raised after an arm changed tracks other than the button's own (an exclusive arm
    /// disarmed them, or the selection armed one), so every view repaints them.</summary>
    public static event Action? OthersChanged;

    /// <summary>Arms or disarms a track, exclusively unless <paramref name="additive"/> (see TrackArm).</summary>
    public static void Set(IAudioEngine engine, int trackId, bool on, bool additive, bool linked = true)
    {
        if (TrackArm.Set(engine, trackId, on, additive, linked)) OthersChanged?.Invoke();
    }

    /// <summary>An arm click with its modifiers: ⌘ / Ctrl adds to the armed set, ⌥ / Alt arms
    /// one track of a linked group alone (specs/076).</summary>
    public static void Set(IAudioEngine engine, int trackId, bool on, Avalonia.Input.KeyModifiers mods)
        => Set(engine, trackId, on, IsAdditive(mods), linked: !IsBypass(mods));

    private static int _followed = -1;

    /// <summary>Arm-on-select is on (Transport ▸ Auto-arm selected track, a saved preference;
    /// off by default, so a click on a track leaves the arms alone).</summary>
    public static bool ArmOnSelect { get; set; }

    /// <summary>The selection moved to <paramref name="trackId"/>: with <see cref="ArmOnSelect"/>
    /// on, arm it if it's an instrument track (see TrackArm.FollowSelection). Only a move to
    /// another track counts, so a track disarmed by hand stays disarmed while you keep working on it.</summary>
    public static void FollowSelection(IAudioEngine engine, int trackId)
    {
        if (trackId == _followed) return;
        _followed = trackId;
        if (ArmOnSelect && TrackArm.FollowSelection(engine, trackId)) OthersChanged?.Invoke();
    }

    /// <summary>A new or reopened project reuses track ids: its first selection is a move.</summary>
    public static void ForgetSelection() => _followed = -1;

    /// <summary>The arm buttons' tooltip, with the platform's modifier spelled out.</summary>
    public static string Tip => MenuKit.Keys(Loc.T("track_arming.arm_for_recording_click_to"));

    /// <summary>⌘ on macOS, Ctrl elsewhere: the "add to the armed set" modifier.</summary>
    public static bool IsAdditive(Avalonia.Input.KeyModifiers m)
        => (m & (OperatingSystem.IsMacOS() ? Avalonia.Input.KeyModifiers.Meta : Avalonia.Input.KeyModifiers.Control)) != 0;

    /// <summary>⌥ (Alt): act on one track of a linked group, bypassing the link (specs/076).</summary>
    public static bool IsBypass(Avalonia.Input.KeyModifiers m) => (m & Avalonia.Input.KeyModifiers.Alt) != 0;
}