Răsfoiți Sursa

Handle double play (#97)

* handle double play

* update FE

* add logging
Tuan Nguyen 1 lună în urmă
părinte
comite
53290cad98
5 a modificat fișierele cu 28 adăugiri și 4 ștergeri
  1. 2 2
      main.py
  2. 2 2
      modules/core/playlist_manager.py
  3. 13 0
      static/js/base.js
  4. 6 0
      static/js/index.js
  5. 5 0
      static/js/playlists.js

+ 2 - 2
main.py

@@ -1173,8 +1173,8 @@ async def run_theta_rho(request: ThetaRhoRequest, background_tasks: BackgroundTa
             raise HTTPException(status_code=400, detail="Connection not established")
         
         if pattern_manager.pattern_lock.locked():
-            logger.warning("Attempted to run a pattern while another is already running")
-            raise HTTPException(status_code=409, detail="Another pattern is already running")
+            logger.info("Another pattern is running, stopping it first...")
+            await pattern_manager.stop_actions()
             
         files_to_run = [file_path]
         logger.info(f'Running theta-rho file: {request.file_name} with pre_execution={request.pre_execution}')

+ 2 - 2
modules/core/playlist_manager.py

@@ -116,8 +116,8 @@ def rename_playlist(old_name, new_name):
 async def run_playlist(playlist_name, pause_time=0, clear_pattern=None, run_mode="single", shuffle=False):
     """Run a playlist with the given options."""
     if pattern_manager.pattern_lock.locked():
-        logger.warning("Cannot start playlist: Another pattern is already running")
-        return False, "Cannot start playlist: Another pattern is already running"
+        logger.info("Another pattern is running, stopping it first...")
+        await pattern_manager.stop_actions()
 
     playlists = load_playlists()
     if playlist_name not in playlists:

+ 13 - 0
static/js/base.js

@@ -155,6 +155,12 @@ function setModalVisibility(show, userAction = false) {
 }
 let currentPreviewFile = null; // Track the current file for preview data
 
+// Global playback status for cross-file access
+window.currentPlaybackStatus = {
+    is_running: false,
+    current_file: null
+};
+
 function connectWebSocket() {
     if (ws) {
         ws.close();
@@ -183,6 +189,13 @@ function connectWebSocket() {
         try {
             const data = JSON.parse(event.data);
             if (data.type === 'status_update') {
+                // Always update global playback status (not throttled)
+                // This ensures play button always has current state
+                window.currentPlaybackStatus = {
+                    is_running: data.data.is_running || false,
+                    current_file: data.data.current_file || null
+                };
+
                 // Throttle UI updates for better Pi performance
                 const now = Date.now();
                 if (now - lastUIUpdate < UI_UPDATE_INTERVAL) {

+ 6 - 0
static/js/index.js

@@ -1054,6 +1054,12 @@ function setupPreviewPanelEvents(pattern) {
                 window.openPlayerPreviewModal();
             }
 
+            // Check if a pattern is currently running and show stopping message
+            console.log('Play clicked, currentPlaybackStatus:', window.currentPlaybackStatus);
+            if (window.currentPlaybackStatus?.is_running) {
+                showStatusMessage('Stopping current pattern...', 'info');
+            }
+
             // Get the selected pre-execution action
             const preExecutionInput = document.querySelector('input[name="preExecutionAction"]:checked');
             const preExecution = preExecutionInput ? preExecutionInput.value : 'none';

+ 5 - 0
static/js/playlists.js

@@ -1375,6 +1375,11 @@ async function runPlaylist() {
     const clearPattern = document.getElementById('clearPatternSelect').value;
     const shuffle = document.getElementById('shuffleCheckbox')?.checked || false;
 
+    // Check if a pattern is currently running and show stopping message
+    if (window.currentPlaybackStatus?.is_running) {
+        showStatusMessage('Stopping current pattern...', 'info');
+    }
+
     try {
         const response = await fetch('/run_playlist', {
             method: 'POST',