rewind encore
This commit is contained in:
		
							parent
							
								
									10e8782798
								
							
						
					
					
						commit
						82ce27c10d
					
				| @ -43,9 +43,9 @@ | |||||||
|       <button id="forward">10s +</button> |       <button id="forward">10s +</button> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|   <!-- <audio id="audio"  |     <audio id="audio"  | ||||||
|        src="muddy_files.mp3"  |        src="muddy_files.mp3"  | ||||||
|        data-reverse-src="muddy_files_reverse.mp3"></audio> --> |        data-reverse-src="muddy_files_reverse.mp3"></audio> | ||||||
| 
 | 
 | ||||||
|   </main> |   </main> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -19,7 +19,6 @@ const rotationsPerTrack = 3; // tours complets du vinyle sur toute la durée | |||||||
| let currentRotation = 0;     // rotation en degrés actuelle du vinyle
 | let currentRotation = 0;     // rotation en degrés actuelle du vinyle
 | ||||||
| 
 | 
 | ||||||
| // 3. Connexion Socket.io
 | // 3. Connexion Socket.io
 | ||||||
| 
 |  | ||||||
| const socket = io(); | const socket = io(); | ||||||
| 
 | 
 | ||||||
| socket.on('position', (position) => { | socket.on('position', (position) => { | ||||||
| @ -66,7 +65,6 @@ socket.on('position', (position) => { | |||||||
|   }, 300); |   }, 300); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| /* |  | ||||||
| // 4. Fonctions
 | // 4. Fonctions
 | ||||||
| 
 | 
 | ||||||
| function togglePlay() { | function togglePlay() { | ||||||
| @ -149,65 +147,4 @@ audio.addEventListener('ended', () => { | |||||||
|   } else { |   } else { | ||||||
|     isPlaying = false; |     isPlaying = false; | ||||||
|   } |   } | ||||||
| }); */ |  | ||||||
| 
 |  | ||||||
| const socket = io(); |  | ||||||
| 
 |  | ||||||
| let isPlaying = false; |  | ||||||
| 
 |  | ||||||
| const rotationsPerTrack = 3;  |  | ||||||
| let currentRotation = 0;   |  | ||||||
| 
 |  | ||||||
| // Valeurs fictives pour durée, car tu ne peux plus récupérer la durée côté client
 |  | ||||||
| const DURATION = 96; // durée en secondes (1:36)
 |  | ||||||
| 
 |  | ||||||
| // Simulation simple du temps qui passe côté client pour la rotation du vinyle
 |  | ||||||
| let currentTime = 0; |  | ||||||
| let animationFrameId; |  | ||||||
| 
 |  | ||||||
| function playTrack() { |  | ||||||
|   socket.emit('play-sound', 'muddy_files.mp3'); |  | ||||||
|   isPlaying = true; |  | ||||||
|   startVinylRotation(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function stopTrack() { |  | ||||||
|   socket.emit('stop-sound'); |  | ||||||
|   isPlaying = false; |  | ||||||
|   stopVinylRotation(); |  | ||||||
|   currentTime = 0; |  | ||||||
|   updateVinylRotation(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function startVinylRotation() { |  | ||||||
|   function update() { |  | ||||||
|     if (isPlaying) { |  | ||||||
|       currentTime += 0.1; // avance temps fictif
 |  | ||||||
|       if (currentTime > DURATION) { |  | ||||||
|         currentTime = 0; // boucle simple
 |  | ||||||
|       } |  | ||||||
|       updateVinylRotation(); |  | ||||||
|       animationFrameId = requestAnimationFrame(update); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   update(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function stopVinylRotation() { |  | ||||||
|   cancelAnimationFrame(animationFrameId); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function updateVinylRotation() { |  | ||||||
|   currentRotation = (currentTime / DURATION) * 360 * rotationsPerTrack; |  | ||||||
|   vinyl.style.transform = `rotate(${currentRotation}deg)`; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Exemple : lancer / arrêter à chaque clic
 |  | ||||||
| vinyl.addEventListener('click', () => { |  | ||||||
|   if (isPlaying) { |  | ||||||
|     stopTrack(); |  | ||||||
|   } else { |  | ||||||
|     playTrack(); |  | ||||||
|   } |  | ||||||
| }); | }); | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| /* const express = require('express'); | const express = require('express'); | ||||||
| const { createServer } = require('node:http'); | const { createServer } = require('node:http'); | ||||||
| // socket
 | // socket
 | ||||||
| const { Server } = require('socket.io'); | const { Server } = require('socket.io'); | ||||||
| @ -69,78 +69,4 @@ io.on('connection', (socket) => { | |||||||
| 
 | 
 | ||||||
| server.listen(port, () => { | server.listen(port, () => { | ||||||
|   console.log(`Example app listening on port ${port}`) |   console.log(`Example app listening on port ${port}`) | ||||||
| }) */ | }) | ||||||
| 
 |  | ||||||
| const express = require('express'); |  | ||||||
| const http = require('http'); |  | ||||||
| const socketIo = require('socket.io'); |  | ||||||
| const player = require('play-sound')({ player: 'mpg123' }); // forcer mpg123
 |  | ||||||
| 
 |  | ||||||
| const app = express(); |  | ||||||
| const server = http.createServer(app); |  | ||||||
| const io = socketIo(server); |  | ||||||
| 
 |  | ||||||
| const SerialPort = require('serialport'); |  | ||||||
| const ReadlineParser = require('@serialport/parser-readline'); |  | ||||||
| 
 |  | ||||||
| const portName = "/dev/ttyUSB0"; // adapte selon ta config
 |  | ||||||
| const arduinoSerialPort = new SerialPort(portName, { baudRate: 115200 }); |  | ||||||
| 
 |  | ||||||
| const parser = arduinoSerialPort.pipe(new ReadlineParser({ delimiter: '\n' })); |  | ||||||
| 
 |  | ||||||
| parser.on('data', (data) => { |  | ||||||
|   console.log('Données reçues Arduino:', data.trim()); |  | ||||||
|   io.emit('position', data.trim());  // envoi à tous les clients
 |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| io.on('connection', (socket) => { |  | ||||||
|   console.log('Client connecté'); |  | ||||||
|   // Ici tu peux gérer d'autres events socket si besoin
 |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| app.use(express.static('assets')); // dossier public pour fichiers front
 |  | ||||||
| 
 |  | ||||||
| let currentAudioProcess = null; |  | ||||||
| 
 |  | ||||||
| io.on('connection', (socket) => { |  | ||||||
|   console.log('Client connecté'); |  | ||||||
| 
 |  | ||||||
|   socket.on('play-sound', (filename) => { |  | ||||||
|     console.log('Lecture demandée:', filename); |  | ||||||
| 
 |  | ||||||
|     // Stopper si un son est déjà joué
 |  | ||||||
|     if (currentAudioProcess) { |  | ||||||
|       console.log('Arrêt du son précédent'); |  | ||||||
|       currentAudioProcess.kill(); |  | ||||||
|       currentAudioProcess = null; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Lancer la lecture avec mpg123
 |  | ||||||
|     const path = require('path'); |  | ||||||
| const filePath = path.join(__dirname, 'node-server', 'sounds', filename); |  | ||||||
| console.log('Chemin complet du fichier:', filePath); |  | ||||||
| 
 |  | ||||||
| currentAudioProcess = player.play(filePath, (err) => { |  | ||||||
|       if (err && !err.killed) { |  | ||||||
|         console.error('Erreur lecture audio:', err); |  | ||||||
|       } |  | ||||||
|       currentAudioProcess = null; |  | ||||||
|     }); |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
|   socket.on('stop-sound', () => { |  | ||||||
|     if (currentAudioProcess) { |  | ||||||
|       currentAudioProcess.kill(); |  | ||||||
|       currentAudioProcess = null; |  | ||||||
|       console.log('Lecture arrêtée'); |  | ||||||
|     } |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
|   socket.on('disconnect', () => { |  | ||||||
|     console.log('Client déconnecté'); |  | ||||||
|   }); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| server.listen(3000, () => { |  | ||||||
|   console.log('Serveur démarré sur http://localhost:3000'); |  | ||||||
| }); |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user