Commit 12c010cb authored by Jürgen Herrmann's avatar Jürgen Herrmann

remove dependency on pulsectl.

added proper gathering of master sink

added moving of sink inputs after insertion and removal of ladspa module
parent 5f512878
......@@ -11,7 +11,6 @@ from matplotlib.figure import Figure
import mmap
import numpy
import os
import pulsectl
from PyQt4 import QtGui, QtCore
from scipy import signal
import struct
......@@ -31,7 +30,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self._pulseaudio_pid = ""
self._mmaps = []
self._pulseClient = None
self._connectPulseAudio()
self._pulseaudio_moduleindex = -1
self._isInserted = False
self._checkInserted()
......@@ -287,24 +285,32 @@ 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
master_sink = self._pulseaudioMasterSink()
if self._isInserted:
self.pushButtonInsert.setText("Insert")
self._pulseaudio_pid = ""
self._mmaps = []
cmd = "pactl set-default-sink %s" % master_sink
os.system("pactl set-default-sink %s" % master_sink)
cmd = """pacmd "list-sink-inputs" | grep 'index: ' | sed 's/ index: /pacmd move-sink-input /g' | sed 's/$/ %s/g'""" % LADSPA_SINK_NAME
ret = os.popen(cmd).read().strip("\n")
cmd = ret.replace("\n", "; ")
os.system(cmd)
os.system("pactl unload-module %s" % self._pulseaudio_moduleindex)
self._pulseaudio_moduleindex = -1
self._isInserted = False
else:
self.pushButtonInsert.setText("Remove")
cmd = "pactl load-module module-ladspa-sink "
cmd += "sink_name=ladspa_output.t5_3band_parameq_with_shelves "
cmd += "sink_name=%s " % LADSPA_SINK_NAME
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"
cmd = "pactl set-default-sink %s" % LADSPA_SINK_NAME
os.system(cmd)
cmd = """pacmd "list-sink-inputs" | grep 'index: ' | sed 's/ index: /pacmd move-sink-input /g' | sed 's/$/ %s/g'""" % LADSPA_SINK_NAME
ret = os.popen(cmd).read().strip("\n")
cmd = ret.replace("\n", "; ")
os.system(cmd)
self._checkInserted()
if self._isInserted:
......@@ -395,18 +401,16 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
check if ladspa module with param eq is already inserted
if so, note module id of it
"""
self._isInserted = False
self.pushButtonInsert.setText("Insert")
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
cmd = """pacmd list | grep -B2 -m1 'argument:.*%s' | grep ' index: ' | sed 's/ index: //g'""" % LADSPA_SINK_NAME
ret = os.popen(cmd).read().replace("\n", "")
if ret == "":
self._isInserted = False
self.pushButtonInsert.setText("Insert")
self._pulseaudio_moduleindex = -1
else:
self._isInserted = True
self.pushButtonInsert.setText("Remove")
break
self._pulseaudio_moduleindex = int(ret)
@staticmethod
......@@ -454,17 +458,6 @@ 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 """
......@@ -635,6 +628,18 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self._disablePresetsComboboxHandler = False
def _pulseaudioMasterSink(self):
""" return name of pulseaudio master sink """
ret = os.popen('pacmd stat|grep "Default sink name"').read().replace("\n", "").replace("Default sink name: ", "")
if ret == "Default sink name: %s" % LADSPA_SINK_NAME:
cmd = r"""pacmd info | grep --color=never -A30 "%s" | grep --color=never -m1 'device.master_device = ' | sed 's/device.master_device = //g' | sed 's/"//g' | sed 's/^[ \t]*//'""" % ret
masterdev = os.popen(cmd).read().replace("\n", "")
else:
masterdev = ret
return masterdev
def _readIniSettings(self):
""" read ini settings """
s = self._settings
......
......@@ -76,7 +76,7 @@ class Ui_MainWindow(object):
font.setBold(True)
font.setWeight(75)
self.comboBoxPresets.setFont(font)
self.comboBoxPresets.setStyleSheet(_fromUtf8("background-color: #666;\n"
self.comboBoxPresets.setStyleSheet(_fromUtf8("background-color: #999;\n"
"color: #fff;\n"
"selection-color: #fff;\n"
"QComboBox QAbstractItemView {\n"
......
......@@ -115,7 +115,7 @@
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: #666;
<string notr="true">background-color: #999;
color: #fff;
selection-color: #fff;
QComboBox QAbstractItemView {
......
......@@ -55,6 +55,8 @@ GRAPH_HEIGHT = 250
INPUT_SUFFIXES = ("Low", "Param1", "Param2", "Param3", "High")
LADSPA_SINK_NAME = "ladspa_output.t5_3band_parameq_with_shelves"
# Simulated samplerate for drawinf frequency responses
SR = 44100
......
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