Commit 8335772c authored by Jürgen Herrmann's avatar Jürgen Herrmann

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
  write presets to ini
parent ad918da6
2do:
====
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:
if inserted, edit default.pa to automatically load module with parameters
......@@ -20,6 +16,10 @@ ladspa plugin: triple band param. eq with shelve:
done:
=====
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 storingwrite presets to ini
insert/remove/apply dance:
auto-apply with timer
control ladspa plugin via shared memory api
......@@ -32,7 +32,6 @@ insert/remove/apply dance:
store preset
1. input dialog with name, default to loaded name
2. put preset into dict under given name
write presets to ini
load presets
always add flat preset
iterate over stored preset keys in config, deserialize presets into dict "name"->Preset
......
......@@ -15,6 +15,7 @@ import pulsectl
from PyQt4 import QtGui, QtCore
from scipy import signal
import struct
from time import time
from WindowClasses.AboutDialog import AboutDialog
......@@ -24,6 +25,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
super(MainWindow, self).__init__()
self.setupUi(self)
self._prohibitLineEditUpdates = False
self._disablePresetsComboboxHandler = False
self._loadedPresetName = ""
self._pulseaudio_pid = ""
self._mmaps = []
......@@ -33,6 +35,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self._isInserted = False
self._checkInserted()
self._setupMmaps()
self._doNotDirty = False
self._needApply = False
self._needRedraw = False
# push button bindings
self.pushButtonAbout.clicked.connect(self.onShowAboutDialog)
self.pushButtonBypass.clicked.connect(self.onBypass)
......@@ -93,16 +98,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self._presets = {}
self._readIniSettings()
# setup auto-apply timer
self._needApply = True
self._timerApplyEq = QtCore.QTimer(self)
self._timerApplyEq.setInterval(50)
self.connect(self._timerApplyEq, QtCore.SIGNAL("timeout()"), self._applyEq)
self._timerApplyEq.start()
# setup update ui timer
self._needRedraw = True
self._timerUpdateUi = QtCore.QTimer(self)
self._timerUpdateUi.setInterval(50)
self.connect(self._timerUpdateUi, QtCore.SIGNAL("timeout()"), self._updateFrGraph)
self._needRedraw = True
self._timerUpdateUi.start()
......@@ -309,9 +313,16 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def onPresetComboBoxSelected(self):
""" a preset was selected in the combo box, load it """
if self._disablePresetsComboboxHandler:
return
name = self.comboBoxPresets.itemText(self.comboBoxPresets.currentIndex())
if name == "":
return
self._doNotDirty = True
self._loadPresetValues(self._presets[name])
self._doNotDirty = False
self._needApply = True
self._needRedraw = True
def onSavePreset(self):
......@@ -499,12 +510,23 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def _dirty(self):
""" enable apply switch """
if self._needApply and self._needRedraw:
return
if self._doNotDirty:
return
self._needApply = True
self._needRedraw = True
if self._loadedPresetName != "":
self._loadedPresetName = ""
preset = self._valuesToPreset()
self._presets[""] = preset
self._populatePresetDropdown()
def _loadPresetValues(self, preset):
""" load a given preset instance into inputs """
self._loadedPresetName = preset.name
self._doNotDirty = True
for suffix in INPUT_SUFFIXES:
freq = getattr(preset, "frequency%s" % suffix)
dial = getattr(self, "dialFrequency%s" % suffix)
......@@ -516,7 +538,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
dial = getattr(self, "dialQ%s" % suffix)
dial.setValue(q2dialSteps(q))
self.sliderGain.setValue(int(round((MAX_GAIN + preset.gain) * 10)))
self._loadedPresetName = preset.name
self._doNotDirty = False
self._needRedraw = True
self._needApply = True
def _onDialFrequencyChanged(self, suffix):
......@@ -596,6 +620,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def _populatePresetDropdown(self):
""" (re)populate presets dropdown menu """
self._disablePresetsComboboxHandler = True
self.comboBoxPresets.clear()
selected = -1
i = 0
......@@ -606,6 +631,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
i += 1
if selected > -1:
self.comboBoxPresets.setCurrentIndex(selected)
self._disablePresetsComboboxHandler = False
def _readIniSettings(self):
......@@ -621,6 +647,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
except Exception as e:
pass
self._loadedPresetName = currentPreset.name
self._presets[currentPreset.name] = currentPreset
# presets
for k in s.allKeys():
if k.startswith("presets/"):
......@@ -632,8 +659,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
# always reinit flat preset
preset = Preset()
self._presets[preset.name] = preset
# load values of current preset
self._populatePresetDropdown()
self._loadPresetValues(currentPreset)
self._populatePresetDropdown()
def _setupMmaps(self):
......@@ -698,6 +727,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def _valuesToPreset(self):
""" make Preset from current values on UI """
preset = Preset()
preset.name = self._loadedPresetName
for suffix in INPUT_SUFFIXES:
dial = getattr(self, "dialFrequency%s" % suffix)
setattr(preset, "frequency%s" % suffix, dialSteps2frequency(dial.value()))
......
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