Skip to content

Commit

Permalink
add autoclose and autoremove options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelmerro committed Jan 27, 2022
1 parent d669a0c commit 199afcf
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 22 deletions.
7 changes: 3 additions & 4 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
- without ctrl it will scroll the list, with ctrl it will move the selection
- make ctrl-f4 open a text editor for the lyrics
- have a search box to do a custom search on the genius api
- implement fullscreen interface with large cover art
- add options to change the playlist VIEW automatically, such as:
- auto delete older than x
- auto close rules that are not playing
- refactor keyboard input file
- fix key holding not working when textarea is focused
- remove repetition in the code with large amount for queries and returns
- after this, make ctrl tab switch between playlist and search section
- implement fullscreen interface with large cover art
- might want to refactor the input file before picking this up (as it requires a new "mode"/layer)
- setting cog/gear somewhere that will write a config file for you
41 changes: 36 additions & 5 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const processStartupArgs = () => {
console.info(
"Garlmap - Gapless Almighty Rule-based Logical Mpv Audio Player")
let config = {
"autoClose": isTruthyArg(process.env.GARLMAP_AUTO_CLOSE) || undefined,
"autoLyrics": isTruthyArg(process.env.GARLMAP_AUTO_LYRICS) || undefined,
"autoRemove": isTruthyArg(process.env.GARLMAP_AUTO_REMOVE) || undefined,
"autoScroll": isTruthyArg(process.env.GARLMAP_AUTO_SCROLL) || undefined,
"cache": process.env.GARLMAP_CACHE?.trim().toLowerCase(),
"customTheme": readFile(joinPath(configDir, "theme.css")),
Expand Down Expand Up @@ -150,6 +152,12 @@ const processStartupArgs = () => {
} else if (name === "--auto-scroll") {
config.autoScroll = isTruthyArg(value)
|| arg === "--auto-scroll"
} else if (name === "--auto-close") {
config.autoClose = isTruthyArg(value)
|| arg === "--auto-close"
} else if (name === "--auto-remove") {
config.autoRemove = isTruthyArg(value)
|| arg === "--auto-remove"
} else {
console.warn(`Error, unsupported argument '${arg}'`)
app.exit(1)
Expand Down Expand Up @@ -200,6 +208,7 @@ Garlmap can be started without any arguments, but it supports the following:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_CACHE env will be read,
or this setting will by default fallback to using "all".
This setting cannot be changed once Garlmap is started.
--auto-lyrics Enable the automatic downloading of lyrics when songs play.
If disabled, you can download them per song by pressing F4.
Expand All @@ -211,6 +220,7 @@ Garlmap can be started without any arguments, but it supports the following:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_AUTO_LYRICS env will be read,
or this setting will by default be disabled from auto fetch.
This setting cannot be changed once Garlmap is started.
--auto-scroll Enable automatic scrolling to the current song in the list.
If disabled, no automatic scrolling will happen.
Expand All @@ -219,7 +229,29 @@ Garlmap can be started without any arguments, but it supports the following:
If no arg is found, it will read the "autoScroll" field from:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_AUTO_SCROLL env will be read,
or this setting will by default be disabled from auto scroll.
or this setting will by default be disabled.
Change this setting in the playlist with "a" or the mouse.
--auto-close Enable automatic closing and opening of rules when played.
The current rule will be opened, all others will be closed.
If disabled, no automatic open or closing will happen.
The argument can optionally be provided with value:
"--auto-close=true", "--auto-close=0, "--auto-close=no".
If no arg is found, it will read the "autoClose" field from:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_AUTO_CLOSE env will be read,
or this setting will by default be disabled.
Change this setting in the playlist with "c" or the mouse.
--auto-remove Enable automatic removal of old rules and tracks after play.
If disabled, no automatic removal of songs/rules will happen.
The argument can optionally be provided with value:
"--auto-remove=true", "--auto-remove=0, "--auto-remove=no".
If no arg is found, it will read the "autoRemove" field from:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_AUTO_REMOVE env will be read,
or this setting will by default be disabled.
Change this setting in the playlist with "r" or the mouse.
--font-size=14 Define a custom font size, without requiring a custom theme.
Accepted values are between 8-100, and the unit is in pixels.
Expand All @@ -230,16 +262,15 @@ Garlmap can be started without any arguments, but it supports the following:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_FONT_SIZE env will be read,
or this setting will by default set to 14 pixels.
This setting cannot be changed once Garlmap is started.
folder Provide a folder to load the songs from for this instance.
If no arg is found, it will read the "folder" field from:
${joinPath(configDir, "settings.json")}
If also absent, the GARLMAP_FOLDER env will be read,
or no default folder is opened on startup,
which means that you need to open one manually with Ctrl-o.
or no default folder is opened on startup.
This is a positional argument, of which only one is allowed.
Though I would recommend to set this to your root music dir,
especially if you have a single dir to store all your music.
You can change the folder after starting with "Ctrl-o".
You can also customize the look and feel of Garlmap using a custom theme file:
${joinPath(configDir, "theme.css")}
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ input[type="range"].muted {background: var(--tertiary);}
#playlist-container .song img:first-child {opacity: 0;cursor: pointer;}
#playlist-container .song:not(.current):not(.selected) img, body[focus-el="search"] #playlist-container .song.selected img {filter: invert(.46) sepia(100%) hue-rotate(135deg) contrast(3.5);}
#playlist-container .song:hover img, #playlist-container .song.current img {opacity: 1;}
#playlist-controls {padding: .5em;}
#playlist-controls {display: flex;padding: .5em;}
#main-playlist {flex: 1;overflow: auto;}
#main-playlist * {flex: 1;}
.rule {display: flex;border: .2em solid var(--fg);}
Expand Down
8 changes: 8 additions & 0 deletions app/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
<input type="checkbox" id="toggle-autoscroll">
<span class="checkbox-mark" />
</label>
<label class="checkbox-container">Autoclose
<input type="checkbox" id="toggle-autoclose">
<span class="checkbox-mark" />
</label>
<label class="checkbox-container">Autoremove
<input type="checkbox" id="toggle-autoremove">
<span class="checkbox-mark" />
</label>
</div>
<div id="main-playlist"></div>
<div id="fallback-rule">order:shuffle</div>
Expand Down
22 changes: 18 additions & 4 deletions app/renderer/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ const init = () => {
const {toggleAutoScroll} = require("./playlist")
toggleAutoScroll()
})
document.getElementById("toggle-autoclose").parentNode
.addEventListener("click", () => {
const {toggleAutoClose} = require("./playlist")
toggleAutoClose()
})
document.getElementById("toggle-autoremove").parentNode
.addEventListener("click", () => {
const {toggleAutoRemove} = require("./playlist")
toggleAutoRemove()
})
resetWelcome()
}

Expand Down Expand Up @@ -278,16 +288,20 @@ const handleKeyboard = async e => {
const {toggleAutoScroll} = require("./playlist")
toggleAutoScroll()
}
if (keyMatch(e, {"key": "c"})) {
const {toggleAutoClose} = require("./playlist")
toggleAutoClose()
}
if (keyMatch(e, {"key": "r"})) {
const {toggleAutoRemove} = require("./playlist")
toggleAutoRemove()
}
if (keyMatch(e, {"ctrl": true, "key": "e"})) {
document.getElementById("main-playlist").scrollBy(0, 100)
}
if (keyMatch(e, {"ctrl": true, "key": "y"})) {
document.getElementById("main-playlist").scrollBy(0, -100)
}
if (keyMatch(e, {"key": "c"})) {
[...document.querySelectorAll("#playlist-container .current")].pop()
?.scrollIntoView({"behavior": "smooth", "block": "center"})
}
if (keyMatch(e, {"key": "s"})) {
const {stopAfterTrack} = require("./playlist")
stopAfterTrack("selected")
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const init = () => {
await increment(false)
document.getElementById("status-scan").textContent = ""
const {showLyrics} = require("./songs")
const {currentAndNext, autoScrollTrack} = require("./playlist")
const {currentAndNext, autoPlayOpts} = require("./playlist")
const {current} = currentAndNext()
showLyrics(current.id)
autoScrollTrack()
autoPlayOpts()
}
if (info.property === "playlist-pos" && info.value === -1) {
const {currentAndNext, playFromPlaylist} = require("./playlist")
Expand Down
55 changes: 51 additions & 4 deletions app/renderer/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let selectedRuleIdx = null
let selectedPathIdx = null
let pathIdx = 0
let shouldAutoScrollTrack = false
let shouldAutoClose = false
let shouldAutoRemove = false

const {formatTime, queryMatch} = require("../util")

Expand Down Expand Up @@ -282,7 +284,7 @@ const playFromPlaylist = async(switchNow = true) => {
await displayCurrentSong(current)
generatePlaylistView()
if (switchNow) {
autoScrollTrack()
autoPlayOpts()
}
}
}
Expand Down Expand Up @@ -403,18 +405,61 @@ const setFallbackRule = rule => {
const toggleAutoScroll = () => {
shouldAutoScrollTrack = !shouldAutoScrollTrack
document.getElementById("toggle-autoscroll").checked = shouldAutoScrollTrack
if (shouldAutoScrollTrack) {
autoPlayOpts("scroll")
}
}

const autoScrollTrack = () => {
if (shouldAutoScrollTrack) {
const toggleAutoClose = () => {
shouldAutoClose = !shouldAutoClose
document.getElementById("toggle-autoclose").checked = shouldAutoClose
if (shouldAutoClose) {
autoPlayOpts("close")
}
}

const toggleAutoRemove = () => {
shouldAutoRemove = !shouldAutoRemove
document.getElementById("toggle-autoremove").checked = shouldAutoRemove
if (shouldAutoRemove) {
autoPlayOpts("remove")
}
}

const autoPlayOpts = (singleOpt = false) => {
if (shouldAutoRemove && [false, "remove"].includes(singleOpt)) {
rulelist = rulelist.filter((_, index) => index >= ruleIdx)
if (selectedRuleIdx) {
selectedRuleIdx -= ruleIdx
if (selectedRuleIdx < 0) {
selectedRuleIdx = null
selectedPathIdx = null
}
if (!rulelist[selectedRuleIdx]?.open) {
selectedPathIdx = null
}
}
ruleIdx = 0
generatePlaylistView()
}
if (shouldAutoClose && [false, "close"].includes(singleOpt)) {
rulelist.forEach((rule, index) => {
rule.open = index === ruleIdx
})
if (rulelist[selectedRuleIdx] !== rulelist[ruleIdx]) {
selectedPathIdx = null
}
generatePlaylistView()
}
if (shouldAutoScrollTrack && [false, "scroll"].includes(singleOpt)) {
[...document.querySelectorAll("#playlist-container .current")].pop()
?.scrollIntoView({"behavior": "smooth", "block": "center"})
}
}

module.exports = {
append,
autoScrollTrack,
autoPlayOpts,
closeSelectedRule,
currentAndNext,
decrement,
Expand All @@ -427,5 +472,7 @@ module.exports = {
playSelectedSong,
setFallbackRule,
stopAfterTrack,
toggleAutoClose,
toggleAutoRemove,
toggleAutoScroll
}
10 changes: 9 additions & 1 deletion app/renderer/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Garlmap - Gapless Almighty Rule-based Logcal Mpv Audio Player
* Copyright (C) 2021 Jelmer van Arnhem
* Copyright (C) 2021-2022 Jelmer van Arnhem
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -42,6 +42,14 @@ const init = () => {
const {toggleAutoScroll} = require("./playlist")
toggleAutoScroll()
}
if (config.autoClose) {
const {toggleAutoClose} = require("./playlist")
toggleAutoClose()
}
if (config.autoRemove) {
const {toggleAutoRemove} = require("./playlist")
toggleAutoRemove()
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ Stop after selected song can be toggled with "s", for which an icon will appear.
Middle-clicking on a song or rule will remove it from the playlist.
While in the playlist, you can also use PageUp, PageDown, Home and End.
You can also play the selected track right away with "Enter".
Using "c" you can scroll the playlist to the song that is currently playing,
Using "a" you can toggle auto scrolling the playlist to the current song,
though it will not move the selection, similar to scrolling with Ctrl-e/Ctrl-y.
You can also toggle automatic opening and closing of the rules with "c",
or toggle automatic removal of old rules and songs using "r".
Caching
Expand Down

0 comments on commit 199afcf

Please sign in to comment.