/usr/share/pyshared/libqtopensesame/items/synth.py is in opensesame 0.27.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | #-*- coding:utf-8 -*-
"""
This file is part of OpenSesame.
OpenSesame is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSesame is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSesame. If not, see <http://www.gnu.org/licenses/>.
"""
import libopensesame.synth
from libqtopensesame.misc import _
from libqtopensesame.items import qtitem
from libqtopensesame.ui import synth_widget_ui
from PyQt4 import QtCore, QtGui
class synth(libopensesame.synth.synth, qtitem.qtitem):
"""GUI controls for the synth item"""
def __init__(self, name, experiment, string = None):
"""
Constructor
Arguments:
name -- the item name
experiment -- the experiment
Keywords arguments:
string -- definition string (default=None)
"""
libopensesame.synth.synth.__init__(self, name, experiment, string)
qtitem.qtitem.__init__(self)
self.lock = False
def init_edit_widget(self):
"""Build the GUI controls"""
qtitem.qtitem.init_edit_widget(self, False)
self.synth_widget = QtGui.QWidget()
self.synth_widget.ui = synth_widget_ui.Ui_synth_widget()
self.synth_widget.ui.setupUi(self.synth_widget)
self.experiment.main_window.theme.apply_theme(self.synth_widget)
self.synth_widget.ui.spin_attack.valueChanged.connect( \
self.apply_edit_changes)
self.synth_widget.ui.spin_decay.valueChanged.connect( \
self.apply_edit_changes)
self.synth_widget.ui.spin_pan.valueChanged.connect( \
self.apply_edit_changes)
self.synth_widget.ui.spin_volume.valueChanged.connect( \
self.apply_edit_changes)
self.synth_widget.ui.spin_length.valueChanged.connect( \
self.apply_edit_changes)
self.synth_widget.ui.edit_freq.editingFinished.connect( \
self.apply_edit_changes)
self.synth_widget.ui.edit_duration.editingFinished.connect( \
self.apply_edit_changes)
self.synth_widget.ui.dial_attack.valueChanged.connect(self.apply_dials)
self.synth_widget.ui.dial_decay.valueChanged.connect(self.apply_dials)
self.synth_widget.ui.dial_pan.valueChanged.connect(self.apply_dials)
self.synth_widget.ui.dial_volume.valueChanged.connect(self.apply_dials)
self.synth_widget.ui.button_sine.clicked.connect(self.set_sine)
self.synth_widget.ui.button_saw.clicked.connect(self.set_saw)
self.synth_widget.ui.button_square.clicked.connect(self.set_square)
self.synth_widget.ui.button_white_noise.clicked.connect( \
self.set_white_noise)
self.edit_vbox.addWidget(self.synth_widget)
self.edit_vbox.addStretch()
def set_sine(self):
"""Select the sine oscillator"""
self.synth_widget.ui.button_sine.setChecked(True)
self.synth_widget.ui.button_saw.setChecked(False)
self.synth_widget.ui.button_square.setChecked(False)
self.synth_widget.ui.button_white_noise.setChecked(False)
self.set("osc", "sine")
self.apply_edit_changes()
def set_saw(self):
"""Select the saw oscillator"""
self.synth_widget.ui.button_sine.setChecked(False)
self.synth_widget.ui.button_saw.setChecked(True)
self.synth_widget.ui.button_square.setChecked(False)
self.synth_widget.ui.button_white_noise.setChecked(False)
self.set("osc", "saw")
self.apply_edit_changes()
def set_square(self):
"""Select the square oscillator"""
self.synth_widget.ui.button_sine.setChecked(False)
self.synth_widget.ui.button_saw.setChecked(False)
self.synth_widget.ui.button_square.setChecked(True)
self.synth_widget.ui.button_white_noise.setChecked(False)
self.set("osc", "square")
self.apply_edit_changes()
def set_white_noise(self):
"""Select the white noise oscillator"""
self.synth_widget.ui.button_sine.setChecked(False)
self.synth_widget.ui.button_saw.setChecked(False)
self.synth_widget.ui.button_square.setChecked(False)
self.synth_widget.ui.button_white_noise.setChecked(True)
self.set("osc", "white_noise")
self.apply_edit_changes()
def edit_widget(self):
"""Refresh the GUI controls"""
self.lock = True
qtitem.qtitem.edit_widget(self, False)
if self.variable_vars(["duration", "freq"]):
self.synth_widget.ui.frame_controls.setVisible(False)
self.user_hint_widget.add_user_hint(_( \
'The controls are disabled, because one of the settings is defined using variables.'))
self.user_hint_widget.refresh()
else:
self.synth_widget.ui.frame_controls.setVisible(True)
self.synth_widget.ui.edit_freq.setText(self.unistr(self.get( \
'freq', _eval=False)))
self.synth_widget.ui.edit_duration.setText(self.unistr(self.get( \
'duration', _eval=False)))
self.synth_widget.ui.spin_attack.setValue(self.get("attack", \
_eval=False))
self.synth_widget.ui.spin_decay.setValue(self.get("decay", _eval= \
False))
self.synth_widget.ui.spin_pan.setValue(self.get("pan", _eval=False))
self.synth_widget.ui.spin_volume.setValue(100.0 * self.get( \
"volume", _eval=False))
self.synth_widget.ui.spin_length.setValue(self.get("length", \
_eval=False))
self.synth_widget.ui.dial_attack.setValue(self.get("attack", \
_eval=False))
self.synth_widget.ui.dial_decay.setValue(self.get("decay", \
_eval=False))
self.synth_widget.ui.dial_pan.setValue(self.get("pan", _eval= \
False))
self.synth_widget.ui.dial_volume.setValue(100.0 * self.get( \
"volume", _eval=False))
self.synth_widget.ui.button_sine.setChecked(self.get("osc", \
_eval=False) == "sine")
self.synth_widget.ui.button_saw.setChecked(self.get("osc", _eval= \
False) == "saw")
self.synth_widget.ui.button_square.setChecked(self.get("osc", \
_eval=False) == "square")
self.synth_widget.ui.button_white_noise.setChecked(self.get( \
"osc", _eval=False) == "white_noise")
self.lock = False
return self._edit_widget
def apply_edit_changes(self, dummy1=None, dummy2=None):
"""
Apply the GUI controls
Keywords arguments:
dummy1 -- a dummy argument (default=None)
dummy2 -- a dummy argument (default=None)
"""
if not qtitem.qtitem.apply_edit_changes(self) or self.lock:
return
self.set("freq", self.sanitize(self.synth_widget.ui.edit_freq.text(), \
strict=True))
dur = self.sanitize(self.synth_widget.ui.edit_duration.text(), \
strict=True)
if dur == "":
dur = "sound"
self.set("duration", dur)
self.set("attack", self.synth_widget.ui.spin_attack.value())
self.set("decay", self.synth_widget.ui.spin_decay.value())
self.set("pan", self.synth_widget.ui.spin_pan.value())
self.set("volume", .01 * self.synth_widget.ui.spin_volume.value())
self.set("length", self.synth_widget.ui.spin_length.value())
if self.synth_widget.ui.button_sine.isChecked():
self.set("osc", "sine")
elif self.synth_widget.ui.button_saw.isChecked():
self.set("osc", "saw")
elif self.synth_widget.ui.button_square.isChecked():
self.set("osc", "square")
else:
self.set("osc", "white_noise")
self.experiment.main_window.refresh(self.name)
def apply_dials(self, dummy=None):
"""
Set the spinbox values based on the dials
Keywords arguments:
dummy -- a dummy argument (default=None)
"""
if self.lock:
return
self.set("attack", self.synth_widget.ui.dial_attack.value())
self.set("decay", self.synth_widget.ui.dial_decay.value())
self.set("pan", self.synth_widget.ui.dial_pan.value())
self.set("volume", .01 * self.synth_widget.ui.dial_volume.value())
self.edit_widget()
|