Skip to content

Commit

Permalink
Added new automode
Browse files Browse the repository at this point in the history
  • Loading branch information
NodudeWasTaken committed Jul 1, 2024
1 parent ce569eb commit 61c5df6
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 29 deletions.
2 changes: 1 addition & 1 deletion dancer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def cmd(args):

if (args.automap):
print("Automapping...")
pitch,energy = autoval(data, tpi=args.auto_pitch, target_speed=args.auto_speed, v2above=args.auto_per/100.0)
pitch,energy = autoval(data, tpi=args.auto_pitch, target_speed=args.auto_speed, v2above=args.auto_per/100.0, opt=(args.auto_mod-1))
args.pitch = pitch
args.energy = energy

Expand Down
18 changes: 16 additions & 2 deletions dancer/libfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _speed(A, B, smax=400.0):
def speed(A,B, **kwargs):
return max(min(_speed(A,B, **kwargs),1.0),0.0)

def autoval(data, tpi=15, target_speed=300, v2above=0.6):
def autoval(data, tpi=15, target_speed=300, v2above=0.6, opt=1):
def cmean(pitch):
result = create_actions(data, energy_multiplier=0, pitch_range=pitch)
_,Y = map(list, zip(*result))
Expand Down Expand Up @@ -185,7 +185,17 @@ def cemeanv2(energy):
# Ensure at least 20% of speeds are above the target speed
return abs(percentage_above_target - v2above) # Ensure 20% (0.2) are above the target speed

eres = minimize(cemeanv2, (10,), method="Nelder-Mead", bounds=((0,100),))
def celen(energy):
result = create_actions(data, energy_multiplier=energy, pitch_range=pres)
actual_percentage = np.mean([abs(result[i][1] - result[i+1][1])/100 for i in range(len(result) - 1)], dtype=np.float64)
return abs(actual_percentage - v2above)

optimizers = [
cemean,
cemeanv2,
celen
]
eres = minimize(optimizers[opt], (10,), method="Nelder-Mead", bounds=((0,100),), options={'xatol': 1e-10, 'disp': True})
eres = eres.x[0]

return pres, eres
Expand Down Expand Up @@ -232,3 +242,7 @@ def dump_funscript(f, data):
"range": 100,
"version": "1.0",
}, f)

if __name__ == "__main__":
data = load_audio_data("/mnt/newfiles/Video/MBad2/inter_cgi/SUPERNOVA 2 - HMV⧸PMV [COMBOBEAT] [3373395].mp4")
print(data)
45 changes: 38 additions & 7 deletions dancer/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def run(self):
class RenderWorker(ImageWorker):
done = QtCore.pyqtSignal(list, QtGui.QPixmap)

def __init__(self, size, data, energy_mult, pitch_offset, overflow, heatmap):
def __init__(self, size, data, energy_mult, pitch_offset, overflow, heatmap, automode):
super().__init__()
self.w = size[0]
self.h = size[1]
Expand All @@ -128,6 +128,7 @@ def __init__(self, size, data, energy_mult, pitch_offset, overflow, heatmap):
self.pitch_offset = pitch_offset
self.overflow = overflow
self.heatmap = heatmap
self.automode = automode

def run(self):
self.pre()
Expand Down Expand Up @@ -229,6 +230,15 @@ def __init__(self, args):
self.cplp.clicked.connect(self.cplpPressed)
self.cmap = self.findChild(QtWidgets.QCheckBox, "mapOpt")
self.cmap.clicked.connect(self.cmapPressed)

self.bmean = self.findChild(QtWidgets.QRadioButton, "cmeanButton")
self.bmean2 = self.findChild(QtWidgets.QRadioButton, "cmeanv2Button")
self.blen = self.findChild(QtWidgets.QRadioButton, "clenButton")
self.bmean.clicked.connect(self.cmapPressed)
self.bmean2.clicked.connect(self.cmapPressed)
self.blen.clicked.connect(self.cmapPressed)
self.automodegroup = self.findChild(QtWidgets.QGroupBox, "groupBox_automap")

self.stpitch = self.findChild(QtWidgets.QSpinBox, "pitchBox")
self.stspeed = self.findChild(QtWidgets.QSpinBox, "speedBox")
self.stper = self.findChild(QtWidgets.QSpinBox, "perBox")
Expand Down Expand Up @@ -281,6 +291,19 @@ def config_load(self):
self.bcrop.clicked.connect(lambda: cfg.save("OOR", "crop"))
self.bbounce.clicked.connect(lambda: cfg.save("OOR", "bounce"))
self.bfold.clicked.connect(lambda: cfg.save("OOR", "fold"))

# Load
AUTOMODE = cfg.get("automode", "mean2")
if AUTOMODE == "mean":
self.bmean.setChecked(True)
elif AUTOMODE == "mean2":
self.bmean2.setChecked(True)
else:
self.blen.setChecked(True)
# Save
self.bmean.clicked.connect(lambda: cfg.save("automode", "mean"))
self.bmean2.clicked.connect(lambda: cfg.save("automode", "mean2"))
self.blen.clicked.connect(lambda: cfg.save("automode", "len"))

# Load
self.stpitch.setValue(cfg.get("tpitch", self.stpitch.value()))
Expand Down Expand Up @@ -324,7 +347,13 @@ def OOR(self):
return 1
elif (self.bfold.isChecked()):
return 2

def Automode(self):
if self.bmean.isChecked():
return 0
elif self.bmean2.isChecked():
return 1
elif self.blen.isChecked():
return 2
def enableUX(self):
self.bload.setEnabled(True)
self.settingsPanel.setEnabled(True)
Expand Down Expand Up @@ -411,7 +440,8 @@ def __render_thread(self):
self.senergy.value() / 10.0,
self.spitch.value(),
self.OOR(),
self.cheat.isChecked()
self.cheat.isChecked(),
self.Automode(),
)
worker.moveToThread(thread)

Expand Down Expand Up @@ -498,14 +528,15 @@ def cheatPressed(self):

def automap(self):
if (self.cmap.isChecked() and len(self.data) > 0):
pitch, energy = autoval(self.data, tpi=self.stpitch.value(), target_speed=self.stspeed.value(), v2above=self.stper.value()/100.0)
pitch, energy = autoval(self.data, tpi=self.stpitch.value(), target_speed=self.stspeed.value(), v2above=self.stper.value()/100.0, opt=self.Automode())
self.spitch.setValue(int(pitch))
self.senergy.setValue(int(energy * 10.0))

def _cmapPressed(self):
self.stpitch.setEnabled(self.cmap.isChecked())
self.stspeed.setEnabled(self.cmap.isChecked())
self.stper.setEnabled(self.cmap.isChecked())
#self.stpitch.setEnabled(self.cmap.isChecked())
#self.stspeed.setEnabled(self.cmap.isChecked())
#self.stper.setEnabled(self.cmap.isChecked())
self.automodegroup.setEnabled(self.cmap.isChecked())
def cmapPressed(self):
self._cmapPressed()
self.automap()
Expand Down
15 changes: 9 additions & 6 deletions dancer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def cli_args():
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)

def irange(min,max):
return range(min, max+1)
parser.add_argument("audio_path", nargs='?', default=None, help="Path to input media")
parser.add_argument("--out_path", help="Path to export funscript")
parser.add_argument("--csv", help="Export as CSV instead of funscript", action="store_true")
Expand All @@ -45,12 +47,13 @@ def cli_args():
parser.add_argument("-y", "--yes", help="Overwrite funscript", action="store_true")
parser.add_argument("--no_plp", help="Disable PLP", action="store_true")
parser.add_argument("--cli", help="Use commandline", action="store_true")
parser.add_argument("--auto_pitch", type=int, default=20, metavar="[0-100]", choices=range(0,100), help="Where you want the actions to generally lie in percent")
parser.add_argument("--auto_speed", type=int, default=250, metavar="[0-400]", choices=range(0,400), help="The target action speed in units/s")
parser.add_argument("--auto_per", type=int, default=65, metavar="[0-100]", choices=range(0,100), help="The target %\ of actions that should have a speed above the specified speed")
parser.add_argument("--pitch", type=int, default=100, metavar="[-200-200]", choices=range(-200,200), help="The pitch")
parser.add_argument("--energy", type=int, default=10, metavar="[0-100]", choices=range(0,100), help="The energy magnitude")
parser.add_argument("--overflow", type=int, default=0, metavar="[0-2]", choices=range(0,2), help="Overflow type")
parser.add_argument("--auto_pitch", type=int, default=20, metavar="[0-100]", choices=irange(0,100), help="Where you want the actions to generally lie in percent")
parser.add_argument("--auto_speed", type=int, default=250, metavar="[0-400]", choices=irange(0,400), help="The target action speed in units/s")
parser.add_argument("--auto_per", type=int, default=65, metavar="[0-100]", choices=irange(0,100), help="The target percent of actions that should have a speed above the specified speed")
parser.add_argument("--auto_mod", type=int, default=2, metavar="[1-3]", choices=irange(1,3), help="Which optimizer to use (cmean, cmeanv2, clen)")
parser.add_argument("--pitch", type=int, default=100, metavar="[-200-200]", choices=irange(-200,200), help="The pitch")
parser.add_argument("--energy", type=int, default=10, metavar="[0-100]", choices=irange(0,100), help="The energy magnitude")
parser.add_argument("--overflow", type=int, default=0, metavar="[0-2]", choices=irange(0,2), help="Overflow type")

return parser

68 changes: 55 additions & 13 deletions dancerUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,62 @@
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_automap">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Automap settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<widget class="QRadioButton" name="cmeanButton">
<property name="text">
<string>Mean</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="cmeanv2Button">
<property name="text">
<string>MeanV2</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="clenButton">
<property name="text">
<string>Length</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Target Pitch</string>
<string>Target Speed</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="pitchBox">
<widget class="QSpinBox" name="speedBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -317,29 +359,29 @@
</size>
</property>
<property name="maximum">
<number>100</number>
<number>500</number>
</property>
<property name="value">
<number>20</number>
<number>250</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label">
<property name="text">
<string>Target Speed</string>
<string>Target Pitch</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="speedBox">
<widget class="QSpinBox" name="pitchBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -353,10 +395,10 @@
</size>
</property>
<property name="maximum">
<number>500</number>
<number>100</number>
</property>
<property name="value">
<number>250</number>
<number>20</number>
</property>
</widget>
</item>
Expand Down Expand Up @@ -452,7 +494,7 @@
<x>0</x>
<y>0</y>
<width>711</width>
<height>22</height>
<height>21</height>
</rect>
</property>
</widget>
Expand Down

0 comments on commit 61c5df6

Please sign in to comment.