Commit 4579ffd8 authored by Jürgen Herrmann's avatar Jürgen Herrmann

initial implementation of insertion and removal of ladspa module

parent 4463a727
2do:
====
Storing/Loading presets:
storing/loading presets:
do not load presets while repopulating dropdown
on dirty set currentindex of dropdown to 0 and set name of loaded preset to ""
prohibit empty name when storing
insert/remove/apply dance:
insert handler:
on insert load ladspa-sink-module with parameters and change default sink
on remove. unload ladspa module and set default sink to master
if inserted, edit default.pa on exit to automatically load module with parameters
if not inserted, edit default.pa on exit and remove loading of ladspa-sink-module
if inserted, edit default.pa to automatically load module with parameters
if not inserted, edit default.pa and remove loading of ladspa-sink-module
stylesheets, fix currently broken:
ToolTips
QInputDialog
......@@ -26,6 +24,9 @@ insert/remove/apply dance:
write control values if dirty
write 0 values if bypassed
set dirty on bypass toggle
insert handler:
on insert load ladspa-sink-module with parameters and change default sink
on remove. unload ladspa module and set default sink to master
store preset
1. input dialog with name, default to loaded name
2. put preset into dict under given name
......
......@@ -11,6 +11,7 @@ from matplotlib.figure import Figure
import mmap
import numpy
import os
import pulsectl
from PyQt4 import QtGui, QtCore
from scipy import signal
import struct
......@@ -25,6 +26,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self._loadedPresetName = ""
self._pulseaudio_pid = ""
self._mmaps = []
self._pulseClient = None
self._connectPulseAudio()
self._pulseaudio_moduleindex = -1
self._isInserted = False
self._checkInserted()
# push button bindings
self.pushButtonAbout.clicked.connect(self.onShowAboutDialog)
self.pushButtonBypass.clicked.connect(self.onBypass)
......@@ -91,8 +97,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self._needRedraw = True
self._timerUpdateUi.start()
# setup auto-apply timer
self._isInserted = False
self._dirtyFlag = True
self._needApply = True
self._timerApplyEq = QtCore.QTimer(self)
self._timerApplyEq.setInterval(50)
self.connect(self._timerApplyEq, QtCore.SIGNAL("timeout()"), self._applyEq)
......@@ -107,7 +112,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def onBypass(self):
""" bypass checked state was changed """
self._bypassed = self.pushButtonBypass.isChecked()
self._dirtyFlag = True
self._needApply = True
def onDialFrequencyLowChanged(self):
......@@ -149,7 +154,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
gain = MIN_GAIN + self.sliderGain.value() / 10.0
self.labelGain.setText("Gain: %0.1fdB" % gain)
self._needRedraw = True
self._dirtyFlag = True
self._needApply = True
def onGainSliderDoubleClicked(self, ignored):
......@@ -159,17 +164,31 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def onInsert(self):
""" insert eq ladspa module and persist into ini """
master_sink = self._pulseClient.sink_list()[0].name
if self._isInserted:
print("Removing... (2do)")
self.pushButtonInsert.setText("Insert")
self._pulseaudio_pid = ""
self._mmaps = []
cmd = "pactl set-default-sink %s" % master_sink
os.system("pactl unload-module %s" % self._pulseaudio_moduleindex)
self._pulseaudio_moduleindex = -1
self._isInserted = False
else:
print("Inserting... (2do)")
self.pushButtonInsert.setText("Remove")
self._setupMmaps()
self._dirtyFlag = True
self._isInserted = not self._isInserted
cmd = "pactl load-module module-ladspa-sink "
cmd += "sink_name=ladspa_output.t5_3band_parameq_with_shelves "
cmd += "master=%s " % master_sink
cmd += "plugin=t5_3band_parameq_with_shelves label=3band_parameq_with_shelves "
cmd += "control=100,0,1,300,0,1,1000,0,1,3000,0,1,10000,0,1,0"
os.system(cmd)
cmd = "pactl set-default-sink ladspa_output.t5_3band_parameq_with_shelves"
os.system(cmd)
self._checkInserted()
if self._isInserted:
self._setupMmaps()
self._needApply = True
def onLineEditsChanged(self):
......@@ -209,7 +228,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
""" a preset was selected in the combo box, load it """
name = self.comboBoxPresets.itemText(self.comboBoxPresets.currentIndex())
self._loadPresetValues(self._presets[name])
self._dirtyFlag = True
self._needApply = True
def onQDialsChanged(self):
......@@ -279,7 +298,24 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
mm.seek(0)
mm.seek(0)
mm.write(buffer)
self._dirtyFlag = False
self._needApply = False
def _checkInserted(self):
"""
check if ladspa module with param eq is already inserted
if so, note module id of it
"""
self._isInserted = False
self._pulseaudio_moduleindex = -1
for module in self._pulseClient.module_list():
if not module.name == 'module-ladspa-sink':
continue
if not "sink_name=ladspa_output.t5_3band_parameq_with_shelves" in module.argument:
continue
self._pulseaudio_moduleindex = module.index
self._isInserted = True
break
@staticmethod
......@@ -327,6 +363,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
return (b0, b1, b2), (a0, a1, a2)
def _connectPulseAudio(self):
""" connect to pulseaudio """
try:
self._pulseClient = pulsectl.Pulse('pulseaudio-parametric-eq')
except pulsectl.PulseError:
msgbox = QtGui.QMessageBox()
msgbox.critical(self, "CRITICAL ERROR", "Could not connect to pulseaudio server." + \
"Cannot proceed, will exit.")
sys.exit(1)
# noinspection PyTypeChecker
def _frequencyResponse(self):
""" return w, h frequency response components for all filters """
......@@ -373,7 +420,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def _dirty(self):
""" enable apply switch """
self._dirtyFlag = True
self._needApply = True
self._needRedraw = True
......@@ -448,7 +495,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
pid = os.popen("ps x|grep pulseaudio|grep -v grep").read().strip().split(" ")[0]
self._pulseaudio_pid = pid
os.chdir("/dev/shm")
for fname in glob.glob("t5-parameq_%s_*.*" % pid):
for fname in glob.glob("t5_3BandParamEqWithShelves_%s_*.*" % pid):
f = open(fname, "a+b")
self._mmaps.append(mmap.mmap(f.fileno(), 0))
......
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