Skip to content

Commit

Permalink
feat: Add tool to apply layer properties to notes
Browse files Browse the repository at this point in the history
  • Loading branch information
IoeCmcomc committed Apr 19, 2024
1 parent 4c5f591 commit d1d4b0e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
32 changes: 29 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
44 changes: 43 additions & 1 deletion ui/toplevel.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<interface version="1.2">
<interface version="1.3">
<object class="tk.Toplevel" id="toplevel">
<property name="iconbitmap">icon.ico</property>
<property name="iconphoto">256x256.png</property>
Expand Down Expand Up @@ -706,6 +706,48 @@
</child>
</object>
</child>
<child>
<object class="ttk.Notebook.Tab" id="applyLayerTab" named="True">
<property name="text" translatable="yes">Apply layers</property>
<child>
<object class="tk.Frame" id="frame1">
<property name="height">200</property>
<property name="padx">5</property>
<property name="pady">5</property>
<property name="width">200</property>
<layout manager="pack">
<property name="side">top</property>
</layout>
<child>
<object class="tk.Label" id="label1">
<property name="text" translatable="yes">Apply the following properties of each layers to their notes:</property>
<layout manager="pack">
<property name="side">top</property>
</layout>
</object>
</child>
<child>
<object class="ttk.Checkbutton" id="applyVolumeCheck" named="True">
<property name="text" translatable="yes">Velocity (or volume)</property>
<property name="variable">boolean:applyLayerVolCheckVar</property>
<layout manager="pack">
<property name="side">top</property>
</layout>
</object>
</child>
<child>
<object class="ttk.Checkbutton" id="applyPanningCheck" named="True">
<property name="text" translatable="yes">Panning</property>
<property name="variable">boolean:applyLayerPanCheckVar</property>
<layout manager="pack">
<property name="side">top</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
Expand Down

0 comments on commit d1d4b0e

Please # to comment.