Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ list.
| Key | Action |
|---|---|
| `e` | Cycle EQ preset, including the saved Custom curve |
| `Alt+E` | Cycle to the previous EQ preset, including the saved Custom curve |
| `t` | Choose theme |
| `v` | Cycle visualizer and save the choice in `config.toml` |
| `Ctrl+V` | Pick visualizer from a list (live preview) |
Expand Down
2 changes: 1 addition & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ <h2>Close the tab. Play the music.</h2>

var KEYS=[
["Space","play / pause"],["> / <","next / prev"],["+ / -","volume"],["← / →","seek 5s"],
["e","EQ preset"],["v / V","visualizer / full screen"],["t","theme, or hide the title in full screen"],["y","lyrics"],
["e / Alt+E","next / previous EQ preset"],["v / V","visualizer / full screen"],["t","theme, or hide the title in full screen"],["y","lyrics"],
["/","filter playlist"],["Ctrl+F","search provider or YouTube"],["z / r","shuffle / repeat"],["a","queue next"],["f","favorite ♥"],
["o","file browser"],["R / O","radio / podcasts"],["? / Ctrl+K","find and run commands"]
];
Expand Down
16 changes: 16 additions & 0 deletions ui/model/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ func (m *Model) cycleEQPreset() {
m.applyEQPreset()
}

func (m *Model) previousEQPreset() {
switch {
case m.eqPresetIdx < 0:
m.eqPresetIdx = len(eqPresets) - 1
case m.eqPresetIdx == 0:
m.eqPresetIdx = -1
default:
m.eqPresetIdx--
}
if m.eqPresetIdx < 0 {
m.applyEQBands(m.eqCustomBands)
return
}
m.applyEQPreset()
}

// saveEQ persists the current EQ state (preset name and band values) to config.
func (m *Model) saveEQ() {
_ = m.saveConfigString("eq_preset", m.EQPresetName())
Expand Down
48 changes: 48 additions & 0 deletions ui/model/audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,54 @@ func TestCycleEQPresetReturnsToCustomCurve(t *testing.T) {
}
}

func TestAltECyclesEQPresetsBackward(t *testing.T) {
custom := [eqBandCount]float64{6, 4, 2, 0, -2, 1, 3, 5, 4, 2}
tests := []struct {
name string
start int
wantIndex int
wantBands [eqBandCount]float64
}{
{name: "previous built-in", start: 1, wantIndex: 0, wantBands: eqPresets[0].Bands},
{name: "first preset returns to custom", start: 0, wantIndex: -1, wantBands: custom},
{name: "custom wraps to final preset", start: -1, wantIndex: len(eqPresets) - 1, wantBands: eqPresets[len(eqPresets)-1].Bands},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := newEQTestModel(custom, &recordingSaver{})
m.eqPresetIdx = tt.start
if tt.start >= 0 {
m.applyEQPreset()
}

m.handleKey(tea.KeyPressMsg{Code: 'e', Mod: tea.ModAlt})

if m.eqPresetIdx != tt.wantIndex {
t.Fatalf("EQ preset index = %d, want %d", m.eqPresetIdx, tt.wantIndex)
}
if got := m.player.EQBands(); got != tt.wantBands {
t.Fatalf("EQ bands = %v, want %v", got, tt.wantBands)
}
})
}
}

func TestAltESchedulesEQSave(t *testing.T) {
m := newEQTestModel([eqBandCount]float64{}, &recordingSaver{})
m.eqPresetIdx = 1
m.applyEQPreset()

m.handleKey(tea.KeyPressMsg{Code: 'e', Mod: tea.ModAlt})

if got := m.eqPresetIdx; got != 0 {
t.Fatalf("EQ preset index = %d, want 0", got)
}
if got := m.eqSaveAfter; got != eqSaveDebounce {
t.Fatalf("EQ save delay = %s, want %s", got, eqSaveDebounce)
}
}

func TestBuiltInPresetSavePreservesCustomCurve(t *testing.T) {
custom := [eqBandCount]float64{6, 4, 2, 0, -2, 1, 3, 5, 4, 2}
saver := &recordingSaver{}
Expand Down
1 change: 1 addition & 0 deletions ui/model/command_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var commandRegistry = []commandSpec{
{Mode: commandModeMain | commandModeVolume | commandModeShuffle | commandModeRepeat, Keys: []string{"r"}, KeyLabel: "r", Label: "Cycle repeat", Keymap: true},
{Mode: commandModeMain, Keys: []string{"m"}, KeyLabel: "m", Label: "Toggle mono", Keymap: true},
{Mode: commandModeMain, Keys: []string{"e"}, KeyLabel: "e", Label: "Cycle EQ preset", Enabled: func(m Model) bool { return !m.simplified }, Keymap: true},
{Mode: commandModeMain, Keys: []string{"alt+e"}, KeyLabel: "Alt+E", Label: "Previous EQ preset", Enabled: func(m Model) bool { return !m.simplified && m.layout.tier != layoutMinimal }, Keymap: true},
{Mode: commandModeMain, Keys: []string{"t"}, KeyLabel: "t", Label: "Choose theme", Keymap: true},
{Mode: commandModeMain, Keys: []string{"v"}, KeyLabel: "v", Label: "Cycle visualizer", Enabled: func(m Model) bool { return !m.simplified }, Keymap: true},
{Mode: commandModeMain, Keys: []string{"ctrl+v"}, KeyLabel: "Ctrl+V", Label: "Choose visualizer", Enabled: func(m Model) bool { return !m.simplified }, Keymap: true},
Expand Down
25 changes: 25 additions & 0 deletions ui/model/command_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ func TestMixcloudShortcutRegistryEntry(t *testing.T) {
t.Fatal("Mixcloud shortcut is missing from the command registry")
}

func TestPreviousEQPresetRegistryEntry(t *testing.T) {
for _, command := range commandRegistry {
if len(command.Keys) == 1 && command.Keys[0] == "alt+e" && command.Mode&commandModeMain != 0 {
if command.KeyLabel != "Alt+E" || command.Label != "Previous EQ preset" || !command.Keymap {
t.Fatalf("previous EQ preset command = %+v", command)
}
m := keybindingTestModel()
if !command.enabled(m) {
t.Fatal("previous EQ preset command is disabled in a full model")
}
m.layout.tier = layoutMinimal
if command.enabled(m) {
t.Fatal("previous EQ preset command is enabled in minimal layout")
}
m.layout.tier = layoutFull
m.simplified = true
if command.enabled(m) {
t.Fatal("previous EQ preset command is enabled in simplified mode")
}
return
}
}
t.Fatal("previous EQ preset command is missing from the command registry")
}

func TestContextHelpAdvertisesProviderBrowsing(t *testing.T) {
browse := trackArtistBrowseProvider{interactionBrowseProvider{commandsTestProvider{name: "Mixcloud"}}}
m := keybindingTestModel()
Expand Down
7 changes: 7 additions & 0 deletions ui/model/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ func (m *Model) handleMainKey(msg tea.KeyPressMsg) tea.Cmd {
m.cycleEQPreset()
m.scheduleEQSave()

case "alt+e":
if m.simplified || m.layout.tier == layoutMinimal {
break
}
m.previousEQPreset()
m.scheduleEQSave()

case "a":
if m.focus == focusPlaylist {
if !m.playlist.Dequeue(m.plCursor) {
Expand Down
15 changes: 15 additions & 0 deletions ui/model/keys_dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ func TestProviderShortcutsSwitchFromEveryFocus(t *testing.T) {
}
}

func TestAltEDoesNotTriggerEmbyShortcut(t *testing.T) {
m := shortcutTestModel()
m.eqPresetIdx = 1
m.applyEQPreset()

m.handleKey(tea.KeyPressMsg{Code: 'e', Mod: tea.ModAlt})

if got := m.provider.Name(); got != "Other" {
t.Fatalf("active provider = %q, want Other", got)
}
if got := m.eqPresetIdx; got != 0 {
t.Fatalf("EQ preset index = %d, want 0", got)
}
}

// quickSwitchProvider takes every key that providerKeyForShortcut maps, so an
// overlay returns after the switch even when the switch has no command. A
// provider that is not configured keeps the overlays open: there is nowhere
Expand Down