Compare commits
3
Commits
f12db080c5
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2665d8eee1 | ||
|
|
e0e9cf8d73 | ||
|
|
f4e48a4a96 |
@@ -1,10 +1,11 @@
|
|||||||
import sys
|
import sys
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QMenuBar, QMenu, QWidget, QVBoxLayout, QPushButton, QHBoxLayout, QGraphicsView, QGraphicsScene, QGraphicsLineItem, QFileDialog
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QMenuBar, QMenu, QWidget, QVBoxLayout, QPushButton, QHBoxLayout, QGraphicsView, QGraphicsScene, QGraphicsLineItem, QFileDialog, QLabel
|
||||||
from PyQt6.QtGui import QAction, QPen
|
|
||||||
from PyQt6.QtCore import Qt, QTimer
|
from PyQt6.QtCore import Qt, QTimer
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import time
|
||||||
|
from PyQt6.QtGui import QAction, QPen
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -52,6 +53,11 @@ class MainWindow(QMainWindow):
|
|||||||
button_layout.addWidget(self.pause_button)
|
button_layout.addWidget(self.pause_button)
|
||||||
self.pause_button.clicked.connect(self.pause)
|
self.pause_button.clicked.connect(self.pause)
|
||||||
|
|
||||||
|
# Zeitanzeige hinzufügen
|
||||||
|
self.time_label = QLabel("00:00 / 00:00", self)
|
||||||
|
self.time_label.setStyleSheet("color: white;")
|
||||||
|
button_layout.addWidget(self.time_label)
|
||||||
|
|
||||||
# Arbeitsbereich für Audio-Spuren
|
# Arbeitsbereich für Audio-Spuren
|
||||||
self.track_area = QGraphicsView(self)
|
self.track_area = QGraphicsView(self)
|
||||||
self.track_area.setStyleSheet("background-color: #222222; border: 1px solid #333333;")
|
self.track_area.setStyleSheet("background-color: #222222; border: 1px solid #333333;")
|
||||||
@@ -95,6 +101,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.playhead.setX(self.current_x)
|
self.playhead.setX(self.current_x)
|
||||||
self.draw_waveform()
|
self.draw_waveform()
|
||||||
self.scene.addItem(self.playhead) # Playhead nach der Waveform hinzufügen
|
self.scene.addItem(self.playhead) # Playhead nach der Waveform hinzufügen
|
||||||
|
self.update_time_label()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Fehler beim Laden der WAV-Datei: {e}")
|
print(f"Fehler beim Laden der WAV-Datei: {e}")
|
||||||
self.audio_data = None
|
self.audio_data = None
|
||||||
@@ -167,13 +174,20 @@ class MainWindow(QMainWindow):
|
|||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
|
|
||||||
def move_playhead(self):
|
def move_playhead(self):
|
||||||
self.current_x += 1.5 # Geschwindigkeit des Playheads
|
if self.audio_data is None or self.audio_stream is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Berechne die aktuelle Position des Playheads basierend auf der Abspielposition
|
||||||
|
self.current_x = (self.playback_pos / len(self.audio_data)) * self.timeline_length
|
||||||
if self.current_x <= self.timeline_length:
|
if self.current_x <= self.timeline_length:
|
||||||
self.playhead.setX(self.current_x)
|
self.playhead.setX(self.current_x)
|
||||||
else:
|
else:
|
||||||
self.pause()
|
self.pause()
|
||||||
self.current_x = 0.0
|
self.current_x = 0.0
|
||||||
self.playhead.setX(self.current_x)
|
self.playhead.setX(self.current_x)
|
||||||
|
self.playback_pos = 0
|
||||||
|
|
||||||
|
self.update_time_label()
|
||||||
|
|
||||||
def audio_callback(self, outdata, frames, time, status):
|
def audio_callback(self, outdata, frames, time, status):
|
||||||
if status:
|
if status:
|
||||||
@@ -193,6 +207,24 @@ class MainWindow(QMainWindow):
|
|||||||
outdata[chunksize:].fill(0)
|
outdata[chunksize:].fill(0)
|
||||||
self.playback_pos += chunksize
|
self.playback_pos += chunksize
|
||||||
|
|
||||||
|
def update_time_label(self):
|
||||||
|
if self.audio_data is None:
|
||||||
|
self.time_label.setText("00:00 / 00:00")
|
||||||
|
return
|
||||||
|
|
||||||
|
current_time = self.playback_pos / self.sample_rate
|
||||||
|
total_time = len(self.audio_data) / self.sample_rate
|
||||||
|
|
||||||
|
current_time_str = self.format_time(current_time)
|
||||||
|
total_time_str = self.format_time(total_time)
|
||||||
|
|
||||||
|
self.time_label.setText(f"{current_time_str} / {total_time_str}")
|
||||||
|
|
||||||
|
def format_time(self, time_seconds):
|
||||||
|
minutes = int(time_seconds // 60)
|
||||||
|
seconds = int(time_seconds % 60)
|
||||||
|
return f"{minutes:02}:{seconds:02}"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
|
|||||||
Reference in new issue
Block a user