improved some major lag issues

This commit is contained in:
2026-01-16 08:54:39 +11:00
parent c2db7f6aca
commit 6d5a877cbc
3 changed files with 31 additions and 45 deletions

View File

@@ -9,38 +9,22 @@ import mp3
if __name__ == "__main__":
print("Loading project...")
"""test_project = Project(song_length=64,bpm=120)
test_project = Project(song_length=64,bpm=120)
drum_channel = ProjectChannel(
screams = ProjectChannel(
test_project,
name="Drums",
volume=-5,
pan=-100
name="screams of the damned",
)
drum_channel.chunks.append(AudioChannelChunk(
drum_channel,
position=0,
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate),
name="120 bpm amen break.mp3"
))
piano_channel = ProjectChannel(
test_project,
name="Piano",
volume=-5,
pan=100
sample = AudioChannelChunk(
screams,
*librosa.load("cool sample 2.mp3", sr=None, mono=False),
name="cool sample 2.mp3"
)
piano_channel.chunks.append(AudioChannelChunk(
piano_channel,
position=2,
*librosa.load("piano chords - Bmin 120BPM.wav", mono=False, sr=test_project.sample_rate),
name="piano chords - Bmin 120BPM.wav"
))
screams.chunks.append(sample)
test_project.channels.append(drum_channel)
test_project.channels.append(piano_channel)
test_project.channels.append(screams)
test_project.write_to_file("test_project.tdp")"""
test_project.write_to_file("test_project.tdp")
#test_project = Project.from_file("test_project.tdp")
# start the ui

Binary file not shown.

View File

@@ -5,7 +5,8 @@ import math
import random
from textual.containers import Vertical
from textual_plot import HiResMode, PlotWidget
from textual.widgets import Sparkline
#from textual_plot import HiResMode, PlotWidget
from ui.widgets.chunk_types.chunk import Chunk
@@ -15,13 +16,9 @@ class AudioChunk(Chunk):
DEFAULT_CSS = """
AudioChunk {
border: tab $primary;
PlotWidget {
padding: 1 0;
Sparkline {
height: 1fr;
.plot--axis {
color: transparent;
}
}
}
"""
@@ -49,15 +46,16 @@ class AudioChunk(Chunk):
self.styles.width = round((self.num_samples / self.sample_rate) / self.app.zoom_level)
def on_mount(self):
for plot in self.query(PlotWidget):
plot: PlotWidget = plot # just for type checking
for plot in self.query(Sparkline):
plot: Sparkline = plot
#plot: PlotWidget = plot # just for type checking
plot.margin_top = 0
plot.margin_left = 0
plot.margin_bottom = 0
#plot.margin_top = 0
#plot.margin_left = 0
#plot.margin_bottom = 0
num_values = len(list(range(0, int(self.num_samples), int(self.sample_rate * 0.05))))
x = range(num_values)
#x = range(num_values)
y = []
if self.num_channels == 1:
@@ -86,7 +84,9 @@ class AudioChunk(Chunk):
# get the decibel values from that
y = librosa.amplitude_to_db(rms, ref=np.min)
print(x)
plot.data = list(y)
"""print(x)
plot.bar(
x,
y,
@@ -98,7 +98,7 @@ class AudioChunk(Chunk):
plot.set_xticks([])
plot.set_yticks([])
plot.set_ylimits(ymin=0)
plot.set_ylimits(ymin=0)"""
def compose(self) -> ComposeResult:
@@ -113,7 +113,8 @@ class AudioChunk(Chunk):
for sample in range(0, self.num_samples, int(self.sample_rate*0.1)):
samples.append(self.audio[channel, sample])"""
yield PlotWidget(allow_pan_and_zoom=False, id=f"channel-{channel}")
yield Sparkline(id=f"channel-{channel}")
#yield PlotWidget(allow_pan_and_zoom=False, id=f"channel-{channel}")
else:
@@ -123,4 +124,5 @@ class AudioChunk(Chunk):
for sample in range(0, self.num_samples, int(self.sample_rate*0.1)):
samples.append(self.audio[sample])"""
yield PlotWidget(allow_pan_and_zoom=False)
#yield PlotWidget(allow_pan_and_zoom=False)
yield Sparkline()