Skip to content

Commit

Permalink
Add WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Aug 13, 2023
1 parent 7c3b3d0 commit 79b8bed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
30 changes: 16 additions & 14 deletions client/src/main/Player.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -150,10 +156,6 @@
items[0].skip()
}
if ($config.WAIT_INTERVAL) {
items.push(new Wait(doneWaiting, updateUI))
}
processItem(0)
db.subscribe(() => {
Expand Down
6 changes: 2 additions & 4 deletions client/src/stores/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -381,7 +380,6 @@ export class Wait {
}

config.subscribe(($config) => {
Wait.currentWaitInterval = $config.WAIT_INTERVAL || 1
Wait.currentStopsetOverdueTime = $config.STOPSET_OVERDUE_TIME || 0
})

Expand Down
2 changes: 1 addition & 1 deletion docs/docs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

_django_settings = None
TYPES_TO_STRING = {
int: "Numerica",
int: "Numeric",
decimal.Decimal: "Numeric",
bool: "Boolean (true or false)",
str: "String",
Expand Down
14 changes: 12 additions & 2 deletions server/tomato/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>WAIT_INTERVAL_SUBTRACTS_FROM_STOPSET_PLAYTIME</code> 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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 79b8bed

Please sign in to comment.