| 1 |
''' |
| 2 |
Quickly generate widget layouts |
| 3 |
in CsoundQt with Python |
| 4 |
v 0.2.1 |
| 5 |
|
| 6 |
Luís Salgueiro |
| 7 |
May 2020 |
| 8 |
''' |
| 9 |
|
| 10 |
import PythonQt.QtGui as pqt |
| 11 |
|
| 12 |
|
| 13 |
default_size = 80 |
| 14 |
gutter = 20 |
| 15 |
width = default_size + gutter |
| 16 |
y = 0 |
| 17 |
|
| 18 |
knobs = [] |
| 19 |
knobs_labels = [] |
| 20 |
knobs_readout = [] |
| 21 |
|
| 22 |
faders = [] |
| 23 |
faders_labels = [] |
| 24 |
faders_readout = [] |
| 25 |
|
| 26 |
solo = [] |
| 27 |
mute = [] |
| 28 |
rec = [] |
| 29 |
|
| 30 |
|
| 31 |
def invalue(name): |
| 32 |
''' |
| 33 |
Inserts an invalue opcode at the cursor position. |
| 34 |
''' |
| 35 |
invalue = 'k%s invalue "%s"\n' % (name, name) |
| 36 |
return q.insertText(invalue) |
| 37 |
|
| 38 |
|
| 39 |
def knob(x, y): |
| 40 |
''' |
| 41 |
Generates a knob, accompanied by a label and a readout SpinBox. Inserts an invalue at the cursor position. |
| 42 |
Argument x refers not to an absolute x position, but to a column of size w (cf. class constructor). |
| 43 |
''' |
| 44 |
label_y = y |
| 45 |
knob_y = label_y + 20 |
| 46 |
readout_y = y + default_size + gutter |
| 47 |
|
| 48 |
|
| 49 |
knobLabel = q.createNewLabel(width * x + 5, label_y, "" + str(x + 1)) |
| 50 |
knobs_labels.append(knobLabel) |
| 51 |
|
| 52 |
name = "knob" + str(x + 1) |
| 53 |
newKnob = q.createNewKnob(width * x, knob_y, name) |
| 54 |
knobs.append(newKnob) |
| 55 |
invalue(name) |
| 56 |
|
| 57 |
knobReadout = q.createNewSpinBox(width * x + 5, readout_y, name) |
| 58 |
knobs_readout.append(knobReadout) |
| 59 |
|
| 60 |
|
| 61 |
def fader(x, y): |
| 62 |
''' |
| 63 |
Generates a fader, accompanied by a label and a readout SpinBox. |
| 64 |
Argument x refers not to an absolute x position, but to a column of size w (cf. class constructor). |
| 65 |
''' |
| 66 |
label_y = y |
| 67 |
fader_y = label_y + 20 |
| 68 |
readout_y = fader_y + 100 |
| 69 |
|
| 70 |
faderLabel = q.createNewLabel(width * x + 5, label_y, "" + str(x + 1)) |
| 71 |
faders_labels.append(faderLabel) |
| 72 |
|
| 73 |
name = "fader" + str(x + 1) |
| 74 |
newFader = q.createNewSlider(width * x + 50, fader_y, name) |
| 75 |
faders.append(newFader) |
| 76 |
invalue(name) |
| 77 |
|
| 78 |
faderReadout = q.createNewSpinBox(width * x + 5, readout_y, name) |
| 79 |
faders_readout.append(faderReadout) |
| 80 |
|
| 81 |
|
| 82 |
def buttons(x, y): |
| 83 |
''' |
| 84 |
Generates a group of three buttons, labelled Solo, Mute and Rec. |
| 85 |
Argument x refers not to an absolute x position, but to a column of size w (cf. class constructor). |
| 86 |
''' |
| 87 |
solo_y = y |
| 88 |
mute_y = solo_y + gutter |
| 89 |
rec_y = mute_y + gutter |
| 90 |
|
| 91 |
solo_name = "solo" + str(x + 1) |
| 92 |
newSolo = q.createNewButton(100 * x, solo_y, solo_name) |
| 93 |
solo.append(newSolo) |
| 94 |
invalue(solo_name) |
| 95 |
|
| 96 |
mute_name = "mute" + str(x + 1) |
| 97 |
newMute = q.createNewButton(100 * x, mute_y, mute_name) |
| 98 |
mute.append(newMute) |
| 99 |
invalue(mute_name) |
| 100 |
|
| 101 |
rec_name = "rec" + str(x + 1) |
| 102 |
newRec = q.createNewButton(100 * x, rec_y, rec_name) |
| 103 |
rec.append(newRec) |
| 104 |
invalue(rec_name) |
| 105 |
|
| 106 |
|
| 107 |
def column(x, y): |
| 108 |
''' |
| 109 |
Generates a mixer channel-like column of widgets, comprising a knob, fader, and button group, arranged vertically. |
| 110 |
Argument x refers not to an absolute x position, but to a column of size w (cf. class constructor). |
| 111 |
''' |
| 112 |
knob(x, y) |
| 113 |
|
| 114 |
fader_y = y + width + (gutter * 1.5) |
| 115 |
fader(x, fader_y) |
| 116 |
|
| 117 |
buttons_y = y + 280 |
| 118 |
buttons(x, buttons_y) |
| 119 |
|
| 120 |
|
| 121 |
def strip(): |
| 122 |
''' |
| 123 |
Generates a set of channel strips by iterating the column function. |
| 124 |
ToDo: manual trash collection, deleting the objects stored in the arrays, so the script properly keeps track of the objects it created. |
| 125 |
''' |
| 126 |
|
| 127 |
for widget in q.getWidgetUuids(): |
| 128 |
q.destroyWidget(widget) |
| 129 |
|
| 130 |
for x in range(strip_spinbox.value): |
| 131 |
column(x, y) |
| 132 |
|
| 133 |
if strip_spinbox.value == 0: |
| 134 |
pass |
| 135 |
elif strip_spinbox.value == 1: |
| 136 |
print('Created %d channel strip!' % strip_spinbox.value) |
| 137 |
else: |
| 138 |
print('Created %d channel strips!' % strip_spinbox.value) |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
w = pqt.QWidget() |
| 143 |
w.setGeometry(50, 50, 400, 400) |
| 144 |
layout = pqt.QGridLayout(w) |
| 145 |
w.setLayout(layout) |
| 146 |
w.setWindowTitle("Generate widgets") |
| 147 |
|
| 148 |
|
| 149 |
text = pqt.QTextBrowser(w) |
| 150 |
layout.addWidget(text, 2, 2) |
| 151 |
text.setText( |
| 152 |
'''This script generates a number of widgets arranged as channel strips, composed of a knob, a slider, and a group of Solo, Mute, and Record Arm buttons, while creating the appropriate software channels in the code at the current cursor position. |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
Quickly generate widget layouts |
| 158 |
in CsoundQt with Python |
| 159 |
v 0.2.1 |
| 160 |
|
| 161 |
Luís Salgueiro |
| 162 |
May 2020 |
| 163 |
''') |
| 164 |
|
| 165 |
|
| 166 |
strip_label = pqt.QLabel('Generate... :') |
| 167 |
layout.addWidget(strip_label, 1, 0) |
| 168 |
|
| 169 |
strip_spinbox = pqt.QSpinBox(w) |
| 170 |
strip_spinbox.setRange(0, 99) |
| 171 |
layout.addWidget(strip_spinbox, 1, 1) |
| 172 |
|
| 173 |
strip_button = pqt.QPushButton("Channel strips", w) |
| 174 |
layout.addWidget(strip_button, 1, 2) |
| 175 |
strip_button.connect("clicked()", strip) |
| 176 |
|
| 177 |
|
| 178 |
w.show() |