diff --git a/src/main.py b/src/main.py index 9daed67..c7a4c61 100644 --- a/src/main.py +++ b/src/main.py @@ -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" - )) - - test_project.channels.append(drum_channel) - test_project.channels.append(piano_channel) + screams.chunks.append(sample) - test_project.write_to_file("test_project.tdp")""" + test_project.channels.append(screams) + + test_project.write_to_file("test_project.tdp") #test_project = Project.from_file("test_project.tdp") # start the ui diff --git a/src/test_project.tdp b/src/test_project.tdp index 95f18c8..188de2d 100644 Binary files a/src/test_project.tdp and b/src/test_project.tdp differ diff --git a/src/ui/widgets/chunk_types/audio.py b/src/ui/widgets/chunk_types/audio.py index f282043..59cf456 100644 --- a/src/ui/widgets/chunk_types/audio.py +++ b/src/ui/widgets/chunk_types/audio.py @@ -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: @@ -112,8 +112,9 @@ 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) \ No newline at end of file + #yield PlotWidget(allow_pan_and_zoom=False) + yield Sparkline() \ No newline at end of file