Commit 35847651 authored by Jürgen Herrmann's avatar Jürgen Herrmann

bugfix: make sure dials are changed at least once when loading a preset

big code inspection and cleanup

will be released as 0.30
parent 538a179a
......@@ -4,6 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/builds" />
<excludeFolder url="file://$MODULE_DIR$/debian" />
<excludeFolder url="file://$MODULE_DIR$/designer_qt5" />
</content>
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
......
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyArgumentListInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyAttributeOutsideInitInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyArgumentEqualDefaultInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PyCallByClassInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyPep8Inspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyPep8NamingInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
......
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices
from designer_qt5.Ui_AboutDialog import Ui_AboutDialog
from helpers.constants import *
from PyQt5.QtWidgets import QDialog
......@@ -17,11 +19,11 @@ class AboutDialog(QDialog, Ui_AboutDialog):
# noinspection PyUnusedLocal,PyMethodMayBeStatic
def onEmailClicked(self, ignore=None):
url = QtCore.QUrl('mailto:t-5@t-5.eu')
url = QUrl('mailto:t-5@t-5.eu')
QDesktopServices().openUrl(url)
# noinspection PyUnusedLocal,PyMethodMayBeStatic
def onLicenceClicked(self, ignore=None):
url = QtCore.QUrl(os.path.join(os.path.dirname(sys.argv[0]), "licence.txt"))
url = QUrl(os.path.join(os.path.dirname(sys.argv[0]), "licence.txt"))
QDesktopServices().openUrl(url)
import base64
import binascii
from DataClasses.Preset import Preset
from designer_qt5.Ui_MainWindow import Ui_MainWindow
import glob
from helpers.functions import *
from io import BytesIO
from math import sin, cos, pi, pow, degrees, sqrt
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import json
import mmap
import re
import struct
from math import sin, cos, pi, pow, sqrt
import numpy
import os
from PyQt5.QtWidgets import QMainWindow
from PyQt5 import QtCore
import re
from PyQt5.QtWidgets import QMainWindow, QInputDialog, QMessageBox
from designer_qt5.Ui_MainWindow import Ui_MainWindow
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from scipy import signal
import struct
from time import time
from DataClasses.Preset import Preset
from WindowClasses.AboutDialog import AboutDialog
from helpers.functions import *
class MainWindow(QMainWindow, Ui_MainWindow):
......@@ -37,6 +36,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._doNotDirty = False
self._needApply = False
self._needRedraw = False
self._bypassed = False
# push button bindings
self.pushButtonAbout.clicked.connect(self.onShowAboutDialog)
self.pushButtonBypass.clicked.connect(self.onBypass)
......@@ -99,12 +99,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# setup auto-apply timer
self._timerApplyEq = QtCore.QTimer(self)
self._timerApplyEq.setInterval(50)
# noinspection PyUnresolvedReferences
self._timerApplyEq.timeout.connect(self._applyEq)
self._timerApplyEq.start()
# setup update ui timer
self._needRedraw = True
self._timerUpdateUi = QtCore.QTimer(self)
self._timerUpdateUi.setInterval(50)
# noinspection PyUnresolvedReferences
self._timerUpdateUi.timeout.connect(self._updateFrGraph)
self._timerUpdateUi.start()
......@@ -278,6 +280,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._needApply = True
# noinspection PyUnusedLocal
def onGainSliderDoubleClicked(self, ignored):
""" gain slider was double clicked, change to half value """
self.sliderGain.setValue(self.sliderGain.maximum() / 2)
......@@ -337,7 +340,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def onSavePreset(self):
""" save a preset with given name """
dlg = QtGui.QInputDialog()
dlg = QInputDialog()
name, ok = dlg.getText(self, "Save preset as...", 'Preset name:', text=self._loadedPresetName)
if ok:
preset = self._valuesToPreset()
......@@ -358,31 +361,25 @@ class MainWindow(QMainWindow, Ui_MainWindow):
""" apply ui settings to eq """
if not self._needApply:
return
try:
if self._bypassed:
buffer = struct.pack("fffffffffffffffff",
1.0,
100.0, 0.0, 1.0,
300.0, 0.0, 1.0,
1000.0, 0.0, 1.0,
3000.0, 0.0, 1.0,
10000.0, 0.0, 1.0,
0.0)
else:
params = self._uiParams()
buffer = struct.pack("fffffffffffffffff",
1.0,
params[0], params[1], params[2],
params[3], params[4], params[5],
params[6], params[7], params[8],
params[9], params[10], params[11],
params[12], params[13], params[14],
params[15])
except ValueError:
buffer = None
raise
if buffer is None:
return
if self._bypassed:
buffer = struct.pack("fffffffffffffffff",
1.0,
100.0, 0.0, 1.0,
300.0, 0.0, 1.0,
1000.0, 0.0, 1.0,
3000.0, 0.0, 1.0,
10000.0, 0.0, 1.0,
0.0)
else:
params = self._uiParams()
buffer = struct.pack("fffffffffffffffff",
1.0,
params[0], params[1], params[2],
params[3], params[4], params[5],
params[6], params[7], params[8],
params[9], params[10], params[11],
params[12], params[13], params[14],
params[15])
for mm in self._mmaps:
mm.seek(0)
mm.seek(0)
......@@ -518,12 +515,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
for suffix in INPUT_SUFFIXES:
freq = getattr(preset, "frequency%s" % suffix)
dial = getattr(self, "dialFrequency%s" % suffix)
dial.setValue(0)
dial.setValue(1)
dial.setValue(frequency2dialSteps(freq))
gain = getattr(preset, "gain%s" % suffix)
dial = getattr(self, "dialGain%s" % suffix)
dial.setValue(0)
dial.setValue(1)
dial.setValue(gain2dialSteps(gain))
q = getattr(preset, "q%s" % suffix)
dial = getattr(self, "dialQ%s" % suffix)
dial.setValue(0)
dial.setValue(1)
dial.setValue(q2dialSteps(q))
self.sliderGain.setValue(int(round((MAX_GAIN + preset.gain) * 10)))
self._doNotDirty = False
......@@ -533,26 +536,26 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def _modifyDefaultPa(self, action=None):
""" modify ~/.config/pulse/default.pa """
dlg = QMessageBox()
try:
f = open(os.path.expanduser("~/.config/pulse/default.pa"), "r")
f = open(os.path.expanduser("~/.config/pulse/default.pa"))
content = f.read()
f.close()
except (OSError, IOError, FileNotFoundError):
os.system("mkdir -p ~/.config/pulse")
try:
f = open(os.path.expanduser("/etc/pulse/default.pa"), "r")
f = open(os.path.expanduser("/etc/pulse/default.pa"))
content = f.read()
f.close()
except (OSError, IOError, FileNotFoundError):
dlg.critical("FATAL ERROR", "Could not read /etc/pulse/default.pa !")
dlg.critical(self, "FATAL ERROR", "Could not read /etc/pulse/default.pa !")
return
try:
f = open(os.path.expanduser("~/.config/pulse/default.pa.backup_by_parameq"), "w")
f.write(content)
f.close()
except (OSError, IOError, FileNotFoundError):
dlg = QtGui.QMessageBox()
dlg.critical("FATAL ERROR", "Could not write ~/.config/pulse/default.pa.backup_by_parameq !")
dlg.critical(self, "FATAL ERROR", "Could not write ~/.config/pulse/default.pa.backup_by_parameq !")
return
if action == "insert":
masterSinkName = self._pulseaudioMasterSink()
......@@ -589,8 +592,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
f.write(content)
f.close()
except (OSError, IOError, FileNotFoundError):
dlg = QtGui.QMessageBox()
dlg.critical("FATAL ERROR", "Could not write ~/.config/pulse/default.pa.backup_by_parameq !")
dlg = QMessageBox()
dlg.critical(self, "FATAL ERROR", "Could not write ~/.config/pulse/default.pa.backup_by_parameq !")
def _onDialFrequencyChanged(self, suffix):
......@@ -706,7 +709,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
try:
jsonString = base64.b64decode(s.value("main/currentPreset", "")).decode("ascii")
currentPreset.unserialize(jsonString)
except Exception as e:
except json.JSONDecodeError:
pass
self._loadedPresetName = currentPreset.name
self._presets[currentPreset.name] = currentPreset
......@@ -740,7 +743,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
fig.patch.set_facecolor("#333333")
self._pltAx1 = ax1 = fig.add_subplot(111)
ax1.patch.set_facecolor("#111111")
ax1.grid(which='major', axis='both', color="#dddddd", linestyle='-')
ax1.grid(color="#dddddd", linestyle='-')
ax1.grid(which='minor', axis='x', color="#bbbbbb", linestyle='--')
ax1.spines['bottom'].set_color('#dddddd')
ax1.spines['top'].set_color('#dddddd')
......@@ -749,6 +752,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
ax1.tick_params(axis='x', colors='#dddddd')
ax1.tick_params(axis='y', colors='#dddddd')
self._pltLine1, = self._pltAx1.plot(w, 20 * numpy.log10(abs(h)), '#00ff00', linewidth=2.0)
# noinspection PyTypeChecker
ax1.axis([10, SR / 2, -12, 12])
ax1.set_ylabel('Amplitude [dB]', color='#00ff00')
ax1.set_xscale('log')
......@@ -827,7 +831,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
jsonString = preset.serialize()
s.setValue("main/currentPreset", base64.b64encode(jsonString.encode("utf-8")))
# store presets
toDelete = filter(lambda k: k.startswith("presets/"), s.allKeys())
toDelete = filter(lambda x: x.startswith("presets/"), s.allKeys())
for k in toDelete:
s.remove(k)
for name, preset in self._presets.items():
......
#!/bin/bash
for ui in *.ui; do
echo reading $ui...
py=`echo $ui | sed s#.ui#.py#`
echo writing $py...
pyuic5 $ui -o $py
echo reading ${ui}...
py=`echo ${ui} | sed s#.ui#.py#`
echo writing ${py}...
pyuic5 ${ui} -o $py
done
echo
......
import math
import os
from PAPEq_rc import darkstyle_icons
from PAPEq_rc import darkstyle_icons # import resources from this lib. see next line...
darkstyle_icons = darkstyle_icons # make PyCharm shut up about unused import statement
CURRENT_VERSION = "0.29"
CURRENT_VERSION = "0.30"
DIALSTEPS = 10000
......@@ -42,7 +43,7 @@ GRAPH_FREQUS = []
_f = 0.001
while _f < math.pi:
GRAPH_FREQUS.append(_f)
_f = _f * 1.01
_f = _f * 1.03
GRAPH_HEIGHT = 250
INPUT_SUFFIXES = ("Low", "Param1", "Param2", "Param3", "High")
......
import math
from helpers.constants import *
......@@ -17,7 +16,8 @@ def dialSteps2frequency(dialSteps):
def gain2dialSteps(gain):
""" convert gain to dial steps """
return int(round(DIALSTEPS/2 + gain / (MAX_GAIN - MIN_GAIN) * DIALSTEPS))
ret = int(round(DIALSTEPS/2 + gain / (MAX_GAIN - MIN_GAIN) * DIALSTEPS))
return ret
def dialSteps2gain(dialSteps):
......
......@@ -2,7 +2,7 @@
cd ..
DT=`date +%Y%m%d_%H%M%S `
aptly snapshot create t-5_$DT from repo t-5
aptly snapshot create t-5_${DT} from repo t-5
aptly publish drop repo
aptly -distribution="repo" publish snapshot t-5_$DT
aptly -distribution="repo" publish snapshot t-5_${DT}
rsync -r --progress /home/jh/.aptly/public/ /home/jh/t-5.eu/debian-repo/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment