From d1d4b0ed95b4ffbd62e6ab00648302789505dd43 Mon Sep 17 00:00:00 2001 From: IoeCmcomc <53734763+IoeCmcomc@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:55:05 +0700 Subject: [PATCH] feat: Add tool to apply layer properties to notes --- main.py | 32 +++++++++++++++++++++++++++++--- ui/toplevel.ui | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index bcd348f..642d637 100644 --- a/main.py +++ b/main.py @@ -42,6 +42,7 @@ from typing import (Any, Callable, Coroutine, Deque, Iterable, List, Literal, Optional, Union) import uuid +from itertools import repeat import pygubu import pygubu.widgets.combobox @@ -410,6 +411,8 @@ def initVarsAndCallbacksFrom(self, builder: Builder): self.arrangeMode: StringVar self.flipHorizontallyCheckVar: BooleanVar self.flipVerticallyCheckVar: BooleanVar + self.applyLayerVolCheckVar: BooleanVar + self.applyLayerPanCheckVar: BooleanVar self.groupPerc: BooleanVar builder.import_variables(self) @@ -844,7 +847,6 @@ async def work(dialog: ProgressDialog): songData: NbsSong = deepcopy(self.songsData[index]) dialog.setCurrentPercentage(randint(20, 25)) await sleep(0.001) - dialog.currentMax = len(songData.notes)*2 length = songData.header.length maxLayer = songData.maxLayer @@ -862,14 +864,38 @@ async def work(dialog: ProgressDialog): note.tick = length - note.tick if self.flipVerticallyCheckVar.get(): note.layer = maxLayer - note.layer - dialog.currentProgress.set( - dialog.currentProgress.get()+1) songData.sortNotes() + dialog.setCurrentPercentage(45) + await sleep(0.001) if self.arrangeMode.get() == 'collapse': self.collapseNotes(songData.notes) elif self.arrangeMode.get() == 'instruments': compactNotes(songData, self.groupPerc.get()) + songData.sortNotes() + dialog.setCurrentPercentage(60) + await sleep(0.001) + + if self.applyLayerVolCheckVar.get() or self.applyLayerPanCheckVar.get(): + applyVol: bool = self.applyLayerVolCheckVar.get() + applyPan: bool = self.applyLayerPanCheckVar.get() + + default_layer = Layer("") + if (songData.maxLayer >= songData.header.height): + songData.layers.extend(repeat(default_layer, songData.maxLayer+1 - songData.header.height)) + + for note in songData.notes: + layer = songData.layers[note.layer] + if applyVol: + note.vel = (note.vel * layer.volume) // 100 + if applyPan and (layer.pan != 0): + note.pan = (note.pan + layer.pan) // 2 + + for layer in songData.layers: + if applyVol: + layer.volume = 100 + if applyPan: + layer.pan = 0 dialog.setCurrentPercentage(randint(75, 85)) await sleep(0.001) diff --git a/ui/toplevel.ui b/ui/toplevel.ui index fc6afe0..60f2533 100644 --- a/ui/toplevel.ui +++ b/ui/toplevel.ui @@ -1,5 +1,5 @@ - + icon.ico 256x256.png @@ -706,6 +706,48 @@ + + + Apply layers + + + 200 + 5 + 5 + 200 + + top + + + + Apply the following properties of each layers to their notes: + + top + + + + + + Velocity (or volume) + boolean:applyLayerVolCheckVar + + top + + + + + + Panning + boolean:applyLayerPanCheckVar + + top + + + + + + +