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__": if __name__ == "__main__":
print("Loading project...") 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, test_project,
name="Drums", name="screams of the damned",
volume=-5,
pan=-100
) )
drum_channel.chunks.append(AudioChannelChunk( sample = AudioChannelChunk(
drum_channel, screams,
position=0, *librosa.load("cool sample 2.mp3", sr=None, mono=False),
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate), name="cool sample 2.mp3"
name="120 bpm amen break.mp3"
))
piano_channel = ProjectChannel(
test_project,
name="Piano",
volume=-5,
pan=100
) )
piano_channel.chunks.append(AudioChannelChunk( screams.chunks.append(sample)
piano_channel,
position=2,
*librosa.load("piano chords - Bmin 120BPM.wav", mono=False, sr=test_project.sample_rate),
name="piano chords - Bmin 120BPM.wav"
))
test_project.channels.append(drum_channel) test_project.channels.append(screams)
test_project.channels.append(piano_channel)
test_project.write_to_file("test_project.tdp")""" test_project.write_to_file("test_project.tdp")
#test_project = Project.from_file("test_project.tdp") #test_project = Project.from_file("test_project.tdp")
# start the ui # start the ui

Binary file not shown.

View File

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