Skip to content

Commit

Permalink
Make saving nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodude committed Apr 16, 2023
1 parent a562085 commit cfc3509
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
22 changes: 22 additions & 0 deletions libfun.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import librosa
import numpy as np
from json import dump

#TODO: Fix action lag that happens sometimes, maybe change hop?
def load_audio_data(audio_file, hop_length=1024, frame_length=1024):
Expand Down Expand Up @@ -139,5 +140,26 @@ def dump_csv(data):
for at, pos in data:
f.write(f"{at*1000},{round(pos)}\n")

def dump_funscript(f, data):
return dump({
"actions": [{"at": int(at*1000), "pos": round(pos)} for at,pos in data],
"inverted": False,
"metadata": {
"creator": "PythonDancer",
"description": "",
"duration": int(data[-1][0]),
"license": "None",
"notes": "",
"performers": [],
"script_url": "",
"tags": [],
"title": "",
"type": "basic",
"video_url": "",
},
"range": 100,
"version": "1.0",
}, f)

if __name__ == "__main__":
dump_csv(create_actions(load_audio_data("STAR.wav"), energy_multiplier=2))
49 changes: 23 additions & 26 deletions qt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys, os
import json
from pathlib import Path
import subprocess

Expand All @@ -15,7 +14,7 @@
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

from libfun import load_audio_data, create_actions
from libfun import load_audio_data, create_actions, dump_funscript

plt.style.use(["ggplot", "dark_background", "fast"])

Expand Down Expand Up @@ -141,6 +140,8 @@ def run(self):
else:
self.plot.plot(X,Y, linewidth=.5)

self.plot.set_ylim(0,100)

self.post()

self.done.emit(result, self.img)
Expand Down Expand Up @@ -221,7 +222,7 @@ def resizeEvent(self, event):
return super(MainUi, self).resizeEvent(event)

def baboutPressed(self):
print("baboutPressed")
QtWidgets.QMessageBox.about(self, "TODO", "About not implemented!")

def bbouncePressed(self):
self.OOR = 1
Expand Down Expand Up @@ -268,6 +269,8 @@ def __load_thread(self, fileName=None):

return thread

#TODO: Disable load button while loading
# Better implement error handling first though
def LoadWorker(self, fileName=None):
if not self.__loadworker.isRunning():
self.__loadworker = self.__load_thread(fileName)
Expand All @@ -290,7 +293,7 @@ def __render_thread(self):
self.goutput.height()
),
self.data,
self.senergy.value()/10,
self.senergy.value() / 10.0,
self.spitch.value(),
self.OOR
)
Expand Down Expand Up @@ -318,7 +321,13 @@ def RenderWorker(self):
def bloadPressed(self):
options = QtWidgets.QFileDialog.Options()
#options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);", options=options)
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
self,
"Open a media file",
"",
"Media Files (*);",
options=options
)
if fileName:
self.fileName = Path(fileName)
self.setWindowTitle(f"Video: {self.fileName.name}")
Expand All @@ -330,31 +339,19 @@ def bfunscriptPressed(self):

options = QtWidgets.QFileDialog.Options()
#options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getSaveFileName(self,"QFileDialog.getSaveFileName()", self.fileName.stem, "Funscript Files (*.funscript)", options=options)
fileName, _ = QtWidgets.QFileDialog.getSaveFileName(
self,
"Save a funscript",
str(self.fileName.with_suffix(".funscript").resolve()),
"Funscript Files (*.funscript)",
options=options
)
if fileName:
with open(fileName, "w") as f:
json.dump({
"actions": [{"at": int(at*1000), "pos": round(pos)} for at,pos in self.result],
"inverted": False,
"metadata": {
"creator": "PythonDancer",
"description": "",
"duration": int(self.result[-1][0]),
"license": "None",
"notes": "",
"performers": [],
"script_url": "",
"tags": [],
"title": "",
"type": "basic",
"video_url": "",
},
"range": 100,
"version": "1.0",
}, f)
dump_funscript(f, self.result)

def bheatmapPressed(self):
print("bheatmapPressed")
QtWidgets.QMessageBox.about(self, "TODO", "Heatmap not implemented!")

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Expand Down

0 comments on commit cfc3509

Please sign in to comment.