From 79b8bed55230c2027b3dd7bb058e0a282807343c Mon Sep 17 00:00:00 2001 From: David Cooper Date: Sat, 12 Aug 2023 23:34:12 -0700 Subject: [PATCH] Add WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME --- client/src/main/Player.svelte | 30 ++++++++++++++++-------------- client/src/stores/player.js | 6 ++---- docs/docs_macros.py | 2 +- server/tomato/settings.py | 14 ++++++++++++-- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/client/src/main/Player.svelte b/client/src/main/Player.svelte index bf6152aa..3ebd7c56 100644 --- a/client/src/main/Player.svelte +++ b/client/src/main/Player.svelte @@ -41,23 +41,29 @@ } const addStopset = () => { - // If previous item is not a wait interval - let shouldPrependWait = $config.WAIT_INTERVAL > 0 && items.length > 0 && items[items.length - 1].type !== "wait" + // Prepend a full wait interval IF: + // There's nothing in the items list, or the previous item is a stopset + // Happens on app start, and when a wait interval is enabled (having previously been 0) + if ($config.WAIT_INTERVAL > 0 && (items.length === 0 || items[items.length - 1].type === "stopset")) { + items.push(new Wait($config.WAIT_INTERVAL, doneWaiting, updateUI)) + } - const secondsUntilPlay = items.reduce( - (s, item) => s + item.remaining, - shouldPrependWait ? $config.WAIT_INTERVAL : 0 - ) + const secondsUntilPlay = items.reduce((s, item) => s + item.remaining, 0) const likelyPlayTime = dayjs().add(secondsUntilPlay, "seconds") let generatedStopset = $db.generateStopset(likelyPlayTime, processItem, updateUI) if (generatedStopset) { - if (shouldPrependWait) { - items.push(new Wait(doneWaiting, updateUI)) - } + // Always add a stopset AND THEN a wait interval items.push(generatedStopset) if ($config.WAIT_INTERVAL > 0) { - items.push(new Wait(doneWaiting, updateUI)) + let duration = $config.WAIT_INTERVAL + if ($config.WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME) { + duration = Math.max( + duration - generatedStopset.duration, + $config.WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME_MIN_LENGTH + ) + } + items.push(new Wait(duration, doneWaiting, updateUI)) } } else { console.warn("Couldn't generate a stopset!") @@ -150,10 +156,6 @@ items[0].skip() } - if ($config.WAIT_INTERVAL) { - items.push(new Wait(doneWaiting, updateUI)) - } - processItem(0) db.subscribe(() => { diff --git a/client/src/stores/player.js b/client/src/stores/player.js index 55402395..e205d1ad 100644 --- a/client/src/stores/player.js +++ b/client/src/stores/player.js @@ -306,14 +306,13 @@ export class GeneratedStopset { } export class Wait { - static currentWaitInterval = 1 static currentStopsetOverdueTime = 0 - constructor(doneCallback, updateCallback) { + constructor(duration, doneCallback, updateCallback) { this.generatedId = currentGeneratedId++ this.updateCallback = updateCallback || noop this.doneCallback = doneCallback || noop - this.duration = Wait.currentWaitInterval || 1 // Should never get created if it's 0 + this.duration = duration this.name = "Wait" this.elapsed = 0 this.type = "wait" @@ -381,7 +380,6 @@ export class Wait { } config.subscribe(($config) => { - Wait.currentWaitInterval = $config.WAIT_INTERVAL || 1 Wait.currentStopsetOverdueTime = $config.STOPSET_OVERDUE_TIME || 0 }) diff --git a/docs/docs_macros.py b/docs/docs_macros.py index d01ce8a5..fabe6fa2 100644 --- a/docs/docs_macros.py +++ b/docs/docs_macros.py @@ -5,7 +5,7 @@ _django_settings = None TYPES_TO_STRING = { - int: "Numerica", + int: "Numeric", decimal.Decimal: "Numeric", bool: "Boolean (true or false)", str: "String", diff --git a/server/tomato/settings.py b/server/tomato/settings.py index a6825b9f..fcce675a 100644 --- a/server/tomato/settings.py +++ b/server/tomato/settings.py @@ -413,10 +413,19 @@ def validate_no_more_than_eight(value): ), "WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME": ( False, + ( + "Wait time subtracts the playtime of a stop set in minutes. This will provide more even results, ie the" + " number of stop sets played per hour will be more consistent at the expense of a DJs air time." + ), + ), + "WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME_MIN_LENGTH": ( + 600, mark_safe( - "Wait time subtracts the playtime of a stop set in minutes. This will provide more even results, ie the " - f"number of stop sets played per hour will be more consistent at the expense of a DJs air time. {_constance_not_implemented_html}" + "When WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME is set to True, wait intervals are of" + " variable length. A very long stopset might naively result in a negative wait interval. This setting" + " avoids that by setting minimum wait interval length (in seconds)." ), + "seconds", ), "TRIM_SILENCE": ( True, @@ -469,6 +478,7 @@ def validate_no_more_than_eight(value): "BROADCAST_COMPRESSION", "WAIT_INTERVAL", "WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME", + "WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME_MIN_LENGTH", "WARN_ON_EMPTY_ROTATORS", "STOPSET_ENTITY_NAME", "STOPSET_PRELOAD_COUNT",