aboutsummaryrefslogtreecommitdiff
path: root/src/toolkit
diff options
context:
space:
mode:
authortassaron2017-07-23 01:53:54 -0400
committertassaron2017-07-23 01:53:54 -0400
commitbf0890e7c87c730b8970c1a20c5b6a9a1a55d203 (patch)
treebc66d222a5f04598db97df419f5affa35b723f6f /src/toolkit
parent450b944b87487aa60a935bbeee3908e2a62cd45b (diff)
components auto-connect & track widgets, less autosave spam
importing toolkit from live interpreter now works
Diffstat (limited to 'src/toolkit')
-rw-r--r--src/toolkit/common.py56
-rw-r--r--src/toolkit/core.py18
-rw-r--r--src/toolkit/ffmpeg.py46
-rw-r--r--src/toolkit/frame.py4
4 files changed, 48 insertions, 76 deletions
diff --git a/src/toolkit/common.py b/src/toolkit/common.py
index 763d582..5fe601f 100644
--- a/src/toolkit/common.py
+++ b/src/toolkit/common.py
@@ -8,13 +8,6 @@ import sys
import subprocess
from collections import OrderedDict
-from toolkit.core import *
-
-
-def getPresetDir(comp):
- '''Get the preset subdirectory for a particular version of a component'''
- return os.path.join(Core.presetDir, str(comp), str(comp.version))
-
def badName(name):
'''Returns whether a name contains non-alphanumeric chars'''
@@ -66,14 +59,20 @@ def openPipe(commandList, **kwargs):
def disableWhenEncoding(func):
- ''' Blocks calls to a function while the video is being exported
- in MainWindow.
- '''
- def decorator(*args, **kwargs):
- if args[0].encoding:
+ def decorator(self, *args, **kwargs):
+ if self.encoding:
return
else:
- return func(*args, **kwargs)
+ return func(self, *args, **kwargs)
+ return decorator
+
+
+def disableWhenOpeningProject(func):
+ def decorator(self, *args, **kwargs):
+ if self.core.openingProject:
+ return
+ else:
+ return func(self, *args, **kwargs)
return decorator
@@ -108,34 +107,3 @@ def rgbFromString(string):
return tup
except:
return (255, 255, 255)
-
-
-def loadDefaultSettings(self):
- '''
- Runs once at each program start-up. Fills in default settings
- for any settings not found in settings.ini
- '''
- self.resolutions = [
- '1920x1080',
- '1280x720',
- '854x480'
- ]
-
- default = {
- "outputWidth": 1280,
- "outputHeight": 720,
- "outputFrameRate": 30,
- "outputAudioCodec": "AAC",
- "outputAudioBitrate": "192",
- "outputVideoCodec": "H264",
- "outputVideoBitrate": "2500",
- "outputVideoFormat": "yuv420p",
- "outputPreset": "medium",
- "outputFormat": "mp4",
- "outputContainer": "MP4",
- "projectDir": os.path.join(self.dataDir, 'projects'),
- }
-
- for parm, value in default.items():
- if self.settings.value(parm) is None:
- self.settings.setValue(parm, value)
diff --git a/src/toolkit/core.py b/src/toolkit/core.py
deleted file mode 100644
index a96a684..0000000
--- a/src/toolkit/core.py
+++ /dev/null
@@ -1,18 +0,0 @@
-class Core:
- '''A very complicated class for tracking settings'''
-
-
-def init(settings):
- global Core
- for classvar, val in settings.items():
- setattr(Core, classvar, val)
-
-
-def cancel():
- global Core
- Core.canceled = True
-
-
-def reset():
- global Core
- Core.canceled = False
diff --git a/src/toolkit/ffmpeg.py b/src/toolkit/ffmpeg.py
index cc59a6c..30dc0b3 100644
--- a/src/toolkit/ffmpeg.py
+++ b/src/toolkit/ffmpeg.py
@@ -4,18 +4,19 @@
import numpy
import sys
import os
-import subprocess as sp
+import subprocess
-from toolkit.common import Core, checkOutput, openPipe
+import core
+from toolkit.common import checkOutput, openPipe
def findFfmpeg():
if getattr(sys, 'frozen', False):
# The application is frozen
if sys.platform == "win32":
- return os.path.join(Core.wd, 'ffmpeg.exe')
+ return os.path.join(core.Core.wd, 'ffmpeg.exe')
else:
- return os.path.join(Core.wd, 'ffmpeg')
+ return os.path.join(core.Core.wd, 'ffmpeg')
else:
if sys.platform == "win32":
@@ -27,7 +28,7 @@ def findFfmpeg():
['ffmpeg', '-version'], stderr=f
)
return "ffmpeg"
- except sp.CalledProcessError:
+ except subprocess.CalledProcessError:
return "avconv"
@@ -37,9 +38,9 @@ def createFfmpegCommand(inputFile, outputFile, components, duration=-1):
'''
if duration == -1:
duration = getAudioDuration(inputFile)
-
safeDuration = "{0:.3f}".format(duration - 0.05) # used by filters
duration = "{0:.3f}".format(duration + 0.1) # used by input sources
+ Core = core.Core
# Test if user has libfdk_aac
encoders = checkOutput(
@@ -213,12 +214,28 @@ def createFfmpegCommand(inputFile, outputFile, components, duration=-1):
return ffmpegCommand
+def testAudioStream(filename):
+ '''Test if an audio stream definitely exists'''
+ audioTestCommand = [
+ core.Core.FFMPEG_BIN,
+ '-i', filename,
+ '-vn', '-f', 'null', '-'
+ ]
+ try:
+ checkOutput(audioTestCommand, stderr=subprocess.DEVNULL)
+ except subprocess.CalledProcessError:
+ return True
+ else:
+ return False
+
+
def getAudioDuration(filename):
- command = [Core.FFMPEG_BIN, '-i', filename]
+ '''Try to get duration of audio file as float, or False if not possible'''
+ command = [core.Core.FFMPEG_BIN, '-i', filename]
try:
- fileInfo = checkOutput(command, stderr=sp.STDOUT)
- except sp.CalledProcessError as ex:
+ fileInfo = checkOutput(command, stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError as ex:
fileInfo = ex.output
info = fileInfo.decode("utf-8").split('\n')
@@ -236,13 +253,17 @@ def getAudioDuration(filename):
def readAudioFile(filename, parent):
+ '''
+ Creates the completeAudioArray given to components
+ and used to draw the classic visualizer.
+ '''
duration = getAudioDuration(filename)
if not duration:
print('Audio file doesn\'t exist or unreadable.')
return
command = [
- Core.FFMPEG_BIN,
+ core.Core.FFMPEG_BIN,
'-i', filename,
'-f', 's16le',
'-acodec', 'pcm_s16le',
@@ -250,7 +271,8 @@ def readAudioFile(filename, parent):
'-ac', '1', # mono (set to '2' for stereo)
'-']
in_pipe = openPipe(
- command, stdout=sp.PIPE, stderr=sp.DEVNULL, bufsize=10**8
+ command,
+ stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=10**8
)
completeAudioArray = numpy.empty(0, dtype="int16")
@@ -258,7 +280,7 @@ def readAudioFile(filename, parent):
progress = 0
lastPercent = None
while True:
- if Core.canceled:
+ if core.Core.canceled:
return
# read 2 seconds of audio
progress += 4
diff --git a/src/toolkit/frame.py b/src/toolkit/frame.py
index 83fd59e..ca2a054 100644
--- a/src/toolkit/frame.py
+++ b/src/toolkit/frame.py
@@ -7,7 +7,7 @@ from PIL.ImageQt import ImageQt
import sys
import os
-from toolkit.common import Core
+import core
class FramePainter(QtGui.QPainter):
@@ -57,7 +57,7 @@ def Checkerboard(width, height):
'''
image = FloodFrame(1920, 1080, (0, 0, 0, 0))
image.paste(Image.open(
- os.path.join(Core.wd, "background.png")),
+ os.path.join(core.Core.wd, "background.png")),
(0, 0)
)
image = image.resize((width, height))