![]() |
Mixxx
|
00001 /*************************************************************************** 00002 * * 00003 * This program is free software; you can redistribute it and/or modify * 00004 * it under the terms of the GNU General Public License as published by * 00005 * the Free Software Foundation; either version 2 of the License, or * 00006 * (at your option) any later version. * 00007 * * 00008 ***************************************************************************/ 00009 00010 #include "ladspapresetslot.h" 00011 00012 #include <QtCore> 00013 #include <QtGui> 00014 #include <QtXml> 00015 00016 #include "ladspapresetmanager.h" 00017 #include "ladspapreset.h" 00018 #include "ladspapresetinstance.h" 00019 #include "widget/wknob.h" 00020 #include "widget/wpushbutton.h" 00021 #include "widget/wlabel.h" 00022 #include "configobject.h" 00023 #include "controlpushbutton.h" 00024 #include "controlpotmeter.h" 00025 00026 LADSPAPresetSlot::LADSPAPresetSlot(QWidget *parent, QDomElement element, int slot, LADSPAPresetManager *presetManager, QPalette palette) : QWidget(parent) 00027 { 00028 m_pPresetManager = presetManager; 00029 m_qPalette = palette; 00030 m_iSlotNumber = slot; 00031 00032 setAcceptDrops(true); 00033 00034 m_pScrollArea = new QScrollArea(this); 00035 m_pScrollWidget = new QWidget(m_pScrollArea); 00036 m_pScrollArea->setWidget(m_pScrollWidget); 00037 //m_pScrollArea->setWidgetResizable(true); 00038 m_pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 00039 00040 QDomElement posElement = element.firstChildElement("Pos"); 00041 QString pos = posElement.text(); 00042 int x = pos.left(pos.indexOf(",")).toInt(); 00043 int y = pos.mid(pos.indexOf(",") + 1).toInt(); 00044 if (x < 0) 00045 { 00046 x = parent->width() + x; 00047 } 00048 if (y < 0) 00049 { 00050 y = parent->height() + y; 00051 } 00052 QDomElement spacingElement = element.firstChildElement("Spacing"); 00053 QString spacing = spacingElement.text(); 00054 int spacingWidth = spacing.left(spacing.indexOf(",")).toInt(); 00055 int spacingHeight = spacing.mid(spacing.indexOf(",") + 1).toInt(); 00056 00057 QDomElement sizeElement = element.firstChildElement("Size"); 00058 QString size = sizeElement.text(); 00059 int width = size.left(size.indexOf(",")).toInt(); 00060 int height = size.mid(size.indexOf(",") + 1).toInt(); 00061 if (width <= 0) 00062 { 00063 width = parent->width() + width; 00064 } 00065 if (height <= 0) 00066 { 00067 height = parent->height() + height; 00068 } 00069 move(x + slot * spacingWidth, y + slot * (height + spacingHeight)); 00070 resize(width, height); 00071 m_pScrollArea->resize(width, height); 00072 m_pScrollWidget->resize(width - 5, height - 5); 00073 m_iBaseWidth = width; 00074 00075 QString slotString; 00076 slotString.setNum(slot); 00077 00078 QDomNodeList buttonNodeList = element.elementsByTagName("PushButton"); 00079 for (int i = 0; i < buttonNodeList.count(); i++) 00080 { 00081 QDomElement buttonElement = buttonNodeList.item(i).toElement(); 00082 QString configKey = buttonElement.firstChildElement("Connection").firstChildElement("ConfigKey").text(); 00083 if (configKey.startsWith("[LADSPA],RemoveEffect")) 00084 { 00085 QString keyString = QString("RemoveEffect") + slotString; 00086 ConfigKey *key = new ConfigKey("[LADSPA]", keyString); 00087 ControlPushButton *control = new ControlPushButton(*key, false); 00088 m_pRemoveButton = new WPushButton(m_pScrollWidget); 00089 buttonElement.firstChildElement("Connection").firstChildElement("ConfigKey").firstChild().setNodeValue("[LADSPA]," + keyString); 00090 m_pRemoveButton->setup(buttonElement); 00091 m_pRemoveButton->setVisible(false); 00092 } 00093 else if (configKey.startsWith("[LADSPA],EnableEffect")) 00094 { 00095 qDebug() << "Setting up LADSPA EnableEffect" << slotString; 00096 QString keyString = QString("EnableEffect") + slotString; 00097 ConfigKey *key = new ConfigKey("[LADSPA]", keyString); 00098 qDebug() << "Key string:" << keyString; 00099 ControlObject *control = new ControlPushButton(*key, false); 00100 control->set(1.0f); 00101 m_pEnableButton = new WPushButton(m_pScrollWidget); 00102 buttonElement.firstChildElement("Connection").firstChildElement("ConfigKey").firstChild().setNodeValue("[LADSPA]," + keyString); 00103 m_pEnableButton->setup(buttonElement); 00104 } 00105 else 00106 { 00107 qDebug() << "LADSPA: Invalid skin (unknown button: " << configKey << ")"; 00108 } 00109 } 00110 00111 QDomElement labelElement = element.firstChildElement("Label"); 00112 m_pLabel = new QLabel(m_pScrollWidget); 00113 m_pLabel->setText(tr("Drag a preset from the list & drop it here")); 00114 00115 posElement = labelElement.firstChildElement("Pos"); 00116 pos = posElement.text(); 00117 x = pos.left(pos.indexOf(",")).toInt(); 00118 y = pos.mid(pos.indexOf(",") + 1).toInt(); 00119 if (x < 0) 00120 { 00121 x = this->width() + x; 00122 } 00123 if (y < 0) 00124 { 00125 y = this->height() + y; 00126 } 00127 m_pLabel->move(x, y); 00128 00129 QDomElement widthElement = labelElement.firstChildElement("Width"); 00130 if (!(widthElement.isNull())) 00131 { 00132 width = widthElement.text().toInt(); 00133 m_pLabel->setMaximumWidth(width); 00134 } 00135 00136 m_pLabel->setPalette(palette); 00137 00138 m_qKnobElement = element.firstChildElement("Knob"); 00139 m_pPresetInstance = NULL; 00140 00141 00142 ConfigKey *key = new ConfigKey("[LADSPA]", "DryWet" + slotString); 00143 ControlPotmeter *control = new ControlPotmeter(*key, 0.0, 1.0); 00144 m_pDryWetKnob = new WKnob(m_pScrollWidget); 00145 QString keyString = QString("[LADSPA],DryWet") + slotString; 00146 m_qKnobElement.firstChildElement(QString("Connection")).firstChildElement(QString("ConfigKey")).firstChild().setNodeValue(keyString); 00147 m_qKnobElement.firstChildElement(QString("Tooltip")).firstChild().setNodeValue("Dry/wet"); 00148 m_pDryWetKnob->setup(m_qKnobElement); 00149 m_pDryWetKnob->show(); 00150 00151 posElement = m_qKnobElement.firstChildElement("Pos"); 00152 pos = posElement.text(); 00153 x = pos.left(pos.indexOf(",")).toInt(); 00154 y = pos.mid(pos.indexOf(",") + 1).toInt(); 00155 if (x < 0) 00156 { 00157 x = this->width() + x; 00158 } 00159 if (y < 0) 00160 { 00161 y = this->height() + y; 00162 } 00163 m_pDryWetKnob->move(x, y); 00164 00165 spacingElement = m_qKnobElement.firstChildElement("Spacing"); 00166 spacing = spacingElement.text(); 00167 spacingWidth = spacing.left(spacing.indexOf(",")).toInt(); 00168 00169 m_pDryWetLabel = new QLabel("Dry/wet", m_pScrollWidget); 00170 m_pDryWetLabel->setMaximumWidth(spacingWidth + m_pDryWetKnob->width() - 4); 00171 m_pDryWetLabel->show(); 00172 x += m_pDryWetKnob->width() / 2 - m_pDryWetLabel->width() / 2; 00173 m_pDryWetLabel->move(x, y + m_pDryWetKnob->height() + 1); 00174 m_pDryWetLabel->setPalette(m_qPalette); 00175 00176 connect(m_pRemoveButton, SIGNAL(valueChangedLeftUp(double)), this, SLOT(slotRemove())); 00177 } 00178 00179 LADSPAPresetSlot::~LADSPAPresetSlot() 00180 { 00181 if (m_pPresetInstance != NULL) 00182 unsetPreset(); 00183 } 00184 00185 void LADSPAPresetSlot::dragEnterEvent(QDragEnterEvent *event) 00186 { 00187 if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) 00188 { 00189 event->setDropAction(Qt::CopyAction); 00190 event->accept(); 00191 } 00192 } 00193 00194 void LADSPAPresetSlot::dropEvent(QDropEvent * event) 00195 { 00196 if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) 00197 { 00198 int row, column; 00199 QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist"); 00200 QDataStream stream(&encoded, QIODevice::ReadOnly); 00201 stream >> row >> column; 00202 setPreset(m_pPresetManager->getPreset(row)); 00203 } 00204 00205 event->setDropAction(Qt::CopyAction); 00206 event->accept(); 00207 } 00208 00209 void LADSPAPresetSlot::setPreset(LADSPAPreset *preset) 00210 { 00211 if (m_pPresetInstance != NULL) 00212 unsetPreset(); 00213 00214 if (!preset->isValid()) 00215 { 00216 QMessageBox::warning(0, "LADSPA error", "One or more plugins required by preset '" + preset->getName() + "' are not installed."); 00217 return; 00218 } 00219 00220 m_pLabel->setText(preset->getName()); 00221 m_pRemoveButton->show(); 00222 00223 m_pPresetInstance = preset->instantiate(m_iSlotNumber); 00224 00225 m_iKnobCount = m_pPresetInstance->getKnobCount(); 00226 m_Knobs.resize(m_iKnobCount); 00227 m_Labels.resize(m_iKnobCount); 00228 for (int i = 0; i < m_iKnobCount; i++) 00229 { 00230 addKnob(i); 00231 } 00232 } 00233 00234 void LADSPAPresetSlot::unsetPreset() 00235 { 00236 m_pLabel->setText("Drag a preset from the list & drop it here"); 00237 m_pRemoveButton->hide(); 00238 m_pScrollWidget->resize(m_iBaseWidth - 5, m_pScrollWidget->height()); 00239 00240 delete m_pPresetInstance; 00241 m_pPresetInstance = NULL; 00242 for (int i = 0; i < m_iKnobCount; i++) 00243 { 00244 delete m_Knobs[i]; 00245 delete m_Labels[i]; 00246 } 00247 } 00248 00249 void LADSPAPresetSlot::addKnob(int i) 00250 { 00251 ConfigKey key = m_pPresetInstance->getKey(i); 00252 WKnob * knob = new WKnob(m_pScrollWidget); 00253 m_Knobs.insert(i, knob); 00254 QString keyString = key.group; 00255 keyString.append(","); 00256 keyString.append(key.item); 00257 m_qKnobElement.firstChildElement(QString("Connection")).firstChildElement(QString("ConfigKey")).firstChild().setNodeValue(keyString); 00258 m_qKnobElement.firstChildElement(QString("Tooltip")).firstChild().setNodeValue(key.item); 00259 knob->setup(m_qKnobElement); 00260 knob->show(); 00261 00262 QDomElement posElement = m_qKnobElement.firstChildElement("Pos"); 00263 QString pos = posElement.text(); 00264 int x = pos.left(pos.indexOf(",")).toInt(); 00265 int y = pos.mid(pos.indexOf(",") + 1).toInt(); 00266 if (x < 0) 00267 { 00268 x = this->width() + x; 00269 } 00270 if (y < 0) 00271 { 00272 y = this->height() + y; 00273 } 00274 QDomElement spacingElement = m_qKnobElement.firstChildElement("Spacing"); 00275 QString spacing = spacingElement.text(); 00276 int spacingWidth = spacing.left(spacing.indexOf(",")).toInt(); 00277 int spacingHeight = spacing.mid(spacing.indexOf(",") + 1).toInt(); 00278 knob->move(x + (i + 1) * (knob->width() + spacingWidth), y + (i + 1) * spacingHeight); 00279 if (knob->x() + knob->width() > m_pScrollWidget->width()) 00280 { 00281 qDebug() << "m_pScrollWidget->resize " << m_pScrollWidget->width() << knob->x() << knob->width() << spacingWidth / 2; 00282 m_pScrollWidget->resize(knob->x() + knob->width() + spacingWidth, m_pScrollWidget->height()); 00283 } 00284 00285 int length = key.item.length(); 00286 QLabel * label = new QLabel(key.item, m_pScrollWidget); 00287 label->setMaximumWidth(spacingWidth + knob->width() - 4); 00288 label->show(); 00289 /*while (label->width() >= spacingWidth + knob->width() - 5) 00290 { 00291 qDebug() << label->width() << ", " << length << ", " << spacingWidth << ", " << knob->width(); 00292 if (length > 10) 00293 length = 10; 00294 length -= 2; 00295 if (length <= 1) 00296 break; 00297 label->setText(key.item.left(length) + "..."); 00298 label->updateGeometry(); 00299 }*/ 00300 m_Labels.insert(i, label); 00301 x += knob->width() / 2 - label->width() / 2; 00302 label->move(x + (i + 1) * (knob->width() + spacingWidth), y + (i + 1) * spacingHeight + knob->height() + 1); 00303 label->setPalette(m_qPalette); 00304 } 00305 00306 void LADSPAPresetSlot::slotRemove() 00307 { 00308 unsetPreset(); 00309 }