From 382d5afc7e2ac24f67b7c891328b8b9bb7e91058 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 13 Jul 2021 23:14:20 -0300 Subject: timestamp files!!! --- backend.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index ad13127..048aec5 100644 --- a/backend.js +++ b/backend.js @@ -368,7 +368,7 @@ class QueuePlayer extends EventEmitter { } - async play(item) { + async play(item, startTime) { if (this.player === null) { throw new Error('Attempted to play before a player was loaded') } @@ -425,7 +425,7 @@ class QueuePlayer extends EventEmitter { } else { this.player.setPause(false) } - await this.player.playFile(downloadFile) + await this.player.playFile(downloadFile, startTime) } // playingThisTrack now means whether the track played through to the end @@ -510,6 +510,15 @@ class QueuePlayer extends EventEmitter { return false } + async playOrSeek(item, time) { + if (item === this.playingTrack) { + this.seekTo(time) + } else { + this.queue(item, this.playingTrack) + this.play(item, time) + } + } + clearPlayingTrack() { if (this.playingTrack !== null) { const oldTrack = this.playingTrack @@ -531,6 +540,10 @@ class QueuePlayer extends EventEmitter { this.player.seekBack(seconds) } + seekTo(seconds) { + this.player.seekTo(seconds) + } + togglePause() { this.player.togglePause() } -- cgit 1.3.0-6-gf8a5 From 7af31d6ccb2d1b0c47c0bbb60a7e51c64bb01bf1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 17 Jul 2021 20:09:09 -0300 Subject: past 3 second threshold, (P) to seek to start --- backend.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 048aec5..51419da 100644 --- a/backend.js +++ b/backend.js @@ -544,6 +544,10 @@ class QueuePlayer extends EventEmitter { this.player.seekTo(seconds) } + seekToStart() { + this.player.seekToStart() + } + togglePause() { this.player.togglePause() } -- cgit 1.3.0-6-gf8a5 From a55e2dda6b7cd2e413445964f44a98a8a07058a7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 17 Jul 2021 20:37:08 -0300 Subject: fix playOrSeek messing with queue order --- backend.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 51419da..e2213d5 100644 --- a/backend.js +++ b/backend.js @@ -511,10 +511,22 @@ class QueuePlayer extends EventEmitter { } async playOrSeek(item, time) { + if (!isTrack(item)) { + // This only makes sense to call with individual tracks! + return + } + if (item === this.playingTrack) { this.seekTo(time) } else { - this.queue(item, this.playingTrack) + // Queue the track, but only if it's not already in the queue, so that we + // respect an existing queue order. + const queue = this.queueGrouplike + const queueIndex = queue.items.indexOf(item) + if (queueIndex === -1) { + this.queue(item, this.playingTrack) + } + this.play(item, time) } } -- cgit 1.3.0-6-gf8a5 From df99d463242a30e863a3c84253549a18e2170d45 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 18 Jul 2021 20:00:24 -0300 Subject: miscellaneous improvements to selection restoring --- backend.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index e2213d5..e38fe2f 100644 --- a/backend.js +++ b/backend.js @@ -85,8 +85,9 @@ class QueuePlayer extends EventEmitter { this.player.on('printStatusLine', data => { if (this.playingTrack) { + const oldTimeData = this.timeData this.timeData = data - this.emit('received time data', data, this) + this.emit('received time data', data, oldTimeData, this) } }) @@ -368,7 +369,7 @@ class QueuePlayer extends EventEmitter { } - async play(item, startTime) { + async play(item, startTime = 0) { if (this.player === null) { throw new Error('Attempted to play before a player was loaded') } @@ -415,7 +416,7 @@ class QueuePlayer extends EventEmitter { this.timeData = null this.playingTrack = item - this.emit('playing', this.playingTrack, oldTrack, this) + this.emit('playing', this.playingTrack, oldTrack, startTime, this) await this.player.kill() if (this.playedTrackToEnd) { @@ -536,7 +537,7 @@ class QueuePlayer extends EventEmitter { const oldTrack = this.playingTrack this.playingTrack = null this.timeData = null - this.emit('playing', null, oldTrack, this) + this.emit('playing', null, oldTrack, 0, this) } } -- cgit 1.3.0-6-gf8a5 From ec0b00d62f5fe02248de71552f5cd3d76589295c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 10 Oct 2021 10:46:23 -0300 Subject: "Loop mode" option: no loop, loop, shuffle This also reorganizes the menubar options a little. --- backend.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index e38fe2f..41107d7 100644 --- a/backend.js +++ b/backend.js @@ -66,7 +66,7 @@ class QueuePlayer extends EventEmitter { this.playingTrack = null this.queueGrouplike = {name: 'Queue', isTheQueue: true, items: []} this.pauseNextTrack = false - this.loopQueueAtEnd = false + this.queueEndMode = 'end' // end, loop, shuffle this.playedTrackToEnd = false this.timeData = null @@ -435,10 +435,18 @@ class QueuePlayer extends EventEmitter { if (playingThisTrack) { this.playedTrackToEnd = true if (!this.playNext(item)) { - if (this.loopQueueAtEnd) { - this.playFirst() - } else { - this.clearPlayingTrack() + switch (this.queueEndMode) { + case 'loop': + this.playFirst() + break + case 'shuffle': + this.clearPlayingTrack() + this.shuffleQueue() + this.playFirst() + break + case 'end': + default: + this.clearPlayingTrack() } } } -- cgit 1.3.0-6-gf8a5 From fc1da6ee8ea604f1f6fcf2d0c82775fc7eeb8e32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 10 Oct 2021 10:58:36 -0300 Subject: update controls to loop queue on last track --- backend.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 41107d7..36344be 100644 --- a/backend.js +++ b/backend.js @@ -434,27 +434,19 @@ class QueuePlayer extends EventEmitter { if (playingThisTrack) { this.playedTrackToEnd = true - if (!this.playNext(item)) { - switch (this.queueEndMode) { - case 'loop': - this.playFirst() - break - case 'shuffle': - this.clearPlayingTrack() - this.shuffleQueue() - this.playFirst() - break - case 'end': - default: - this.clearPlayingTrack() - } - } + this.playNext(item) } } playNext(track, automaticallyQueueNextTrack = false) { if (!track) return false + // Auto-queue is nice but it should only happen when the queue hasn't been + // explicitly set to loop. + automaticallyQueueNextTrack = ( + automaticallyQueueNextTrack && + this.queueEndMode === 'end') + const queue = this.queueGrouplike let queueIndex = queue.items.indexOf(track) if (queueIndex === -1) return false @@ -473,7 +465,7 @@ class QueuePlayer extends EventEmitter { this.queue(nextItem) queueIndex = queue.items.length - 1 } else { - return false + return this.playNextAtQueueEnd() } } @@ -519,6 +511,23 @@ class QueuePlayer extends EventEmitter { return false } + playNextAtQueueEnd() { + switch (this.queueEndMode) { + case 'loop': + this.playFirst() + return true + case 'shuffle': + this.clearPlayingTrack() + this.shuffleQueue() + this.playFirst() + return true + case 'end': + default: + this.clearPlayingTrack() + return false + } + } + async playOrSeek(item, time) { if (!isTrack(item)) { // This only makes sense to call with individual tracks! -- cgit 1.3.0-6-gf8a5 From e8a55f10dd9749ad240b165e318db0a1d2f00a9a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 1 Jun 2022 23:35:03 -0300 Subject: miscellaneous improvements to queue looping --- backend.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 36344be..59c4a48 100644 --- a/backend.js +++ b/backend.js @@ -338,9 +338,11 @@ class QueuePlayer extends EventEmitter { } } - shuffleQueue() { + shuffleQueue(pastPlayingTrackOnly = true) { const queue = this.queueGrouplike - const index = queue.items.indexOf(this.playingTrack) + 1 // This is 0 if no track is playing + const index = (pastPlayingTrackOnly + ? queue.items.indexOf(this.playingTrack) + 1 // This is 0 if no track is playing + : 0) const initialItems = queue.items.slice(0, index) const remainingItems = queue.items.slice(index) const newItems = initialItems.concat(shuffleArray(remainingItems)) @@ -517,8 +519,7 @@ class QueuePlayer extends EventEmitter { this.playFirst() return true case 'shuffle': - this.clearPlayingTrack() - this.shuffleQueue() + this.shuffleQueue(false) this.playFirst() return true case 'end': -- cgit 1.3.0-6-gf8a5 From 43f1a1dd1b44065663a797603012394c52a9baea Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 13 May 2023 13:31:58 -0300 Subject: use ESM module syntax & update tui-lib Exciting update! This doesn't make any substantial changes exactly but does update the most quickly-archaic parts of older Node code. --- backend.js | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 59c4a48..4142026 100644 --- a/backend.js +++ b/backend.js @@ -3,31 +3,27 @@ 'use strict' -const { getDownloaderFor } = require('./downloaders') -const { getMetadataReaderFor } = require('./metadata-readers') -const { getPlayer } = require('./players') -const RecordStore = require('./record-store') -const os = require('os') +import {readFile, writeFile} from 'node:fs/promises' +import EventEmitter from 'node:events' +import os from 'node:os' -const { +import {getDownloaderFor} from './downloaders.js' +import {getMetadataReaderFor} from './metadata-readers.js' +import {getPlayer} from './players.js' +import RecordStore from './record-store.js' + +import { getTimeStringsFromSec, shuffleArray, - throttlePromise -} = require('./general-util') + throttlePromise, +} from './general-util.js' -const { +import { isGroup, isTrack, flattenGrouplike, - getItemPathString, - parentSymbol -} = require('./playlist-utils') - -const { promisify } = require('util') -const EventEmitter = require('events') -const fs = require('fs') -const writeFile = promisify(fs.writeFile) -const readFile = promisify(fs.readFile) + parentSymbol, +} from './playlist-utils.js' async function download(item, record) { if (isGroup(item)) { @@ -206,20 +202,6 @@ class QueuePlayer extends EventEmitter { const distributeSize = distributeEnd - distributeStart - const queueItem = (item, insertIndex) => { - if (items.includes(item)) { - /* - if (!movePlayingTrack && item === this.playingTrack) { - return - } - */ - items.splice(items.indexOf(item), 1) - } else { - offset++ - } - items.splice(insertIndex, 0, item) - } - if (how === 'evenly') { let offset = 0 for (const item of newTracks) { @@ -647,7 +629,7 @@ class QueuePlayer extends EventEmitter { } } -class Backend extends EventEmitter { +export default class Backend extends EventEmitter { constructor({ playerName = null, playerOptions = [] @@ -830,5 +812,3 @@ class Backend extends EventEmitter { return download(item, this.getRecordFor(item)) } } - -module.exports = Backend -- cgit 1.3.0-6-gf8a5