1 /* 2 Copyright (C) 2008, 2009 Andres Cabrera 3 mantaraya36@gmail.com 4 5 This file is part of CsoundQt. 6 7 CsoundQt is free software; you can redistribute it 8 and/or modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 CsoundQt is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with Csound; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 20 02111-1307 USA 21 */ 22 23 #ifndef QUTEWIDGET_H 24 #define QUTEWIDGET_H 25 26 #ifdef USE_QT5 27 #include <QtWidgets> 28 #else 29 #include <QtGui> 30 #endif 31 #include <QtXml> 32 33 #define QCS_CURRENT_XML_VERSION "2" 34 #define QCS_CURVE_BUFFER_SIZE 256 35 //#define USE_WIDGET_MUTEX 36 37 #include "csoundengine.h" 38 39 enum QuteWidgetType { UNKNOWN=0, SPINBOX=1, LINEEDIT, CHECKBOX, SLIDER, KNOB, SCROLLNUMBER, 40 BUTTON, DROPDOWN, CONTROLLER, GRAPH, SCOPE, CONSOLE, 41 TABLEDISPLAY }; 42 43 class QuteWidget : public QWidget 44 { 45 Q_OBJECT 46 public: 47 QuteWidget(QWidget* parent); 48 ~QuteWidget(); 49 50 virtual void setWidgetGeometry(int x, int y, int w, int h); 51 virtual void setValue(double); // These should only be reimplemented if something special needs to be done with the value. 52 virtual void setValue2(double); 53 virtual void setValue(QString); 54 virtual void setMidiValue(int value); 55 virtual void setMidiValue2(int value); acceptsMidi()56 virtual bool acceptsMidi() {return false;} setLocked(bool locked)57 virtual void setLocked(bool locked) {m_locked = locked;} 58 59 virtual void widgetMessage(QString path, QString text); 60 virtual void widgetMessage(QString path, double value); 61 62 virtual QString getWidgetLine() = 0; 63 virtual QString getCabbageLine(); 64 virtual QString getCsladspaLine(); 65 virtual QString getQml(); 66 virtual QString getWidgetXmlText() = 0; 67 virtual QString getChannelName(); 68 virtual QString getChannel2Name(); 69 virtual double getValue(); 70 virtual double getValue2(); 71 virtual QString getStringValue(); 72 virtual QString getDescription(); 73 74 QString getUuid(); 75 virtual QString getWidgetType() = 0; refreshWidget()76 virtual void refreshWidget() { ;} 77 78 virtual void applyInternalProperties(); 79 80 void createXmlWriter(QXmlStreamWriter &s); 81 void markChanged(); 82 void canFocus(bool can); 83 void updateDialogWindow(int cc, int channel); setCsoundUserData(CsoundUserData * ud)84 virtual void setCsoundUserData(CsoundUserData *ud) { m_csoundUserData = ud; } 85 double getSr(double defaultSr=0.0) { 86 if(m_csoundUserData == nullptr) { 87 QDEBUG << "csoundUserData: null"; 88 return defaultSr; 89 } 90 auto engine = m_csoundUserData->csEngine; 91 if(engine == nullptr) { 92 QDEBUG << "engine null"; 93 return defaultSr; 94 } 95 if(!engine->isRunning()) { 96 QDEBUG << "not running"; 97 return defaultSr; 98 } 99 return csoundGetSr(engine->getCsound()); 100 } 101 102 bool m_valueChanged; 103 bool m_value2Changed; 104 105 106 public slots: 107 void popUpMenu(QPoint pos); 108 void openProperties(); 109 110 protected: 111 QSpinBox *xSpinBox; 112 QSpinBox *ySpinBox; 113 QSpinBox *wSpinBox; 114 QSpinBox *hSpinBox; 115 QLabel *channelLabel; 116 QLineEdit *nameLineEdit; 117 QLineEdit *descriptionLineEdit; 118 119 QSpinBox *midiccSpinBox; 120 QSpinBox *midichanSpinBox; 121 QPushButton *midiLearnButton; 122 QWidget *m_widget; 123 QDialog *dialog; 124 QGridLayout *layout; // For preference dialog 125 double m_value, m_value2; 126 QString m_stringValue; 127 QString m_channel, m_channel2; 128 int m_midicc, m_midichan; 129 bool m_locked; // Allow modification of widget (properties, alignment, etc.) 130 CsoundUserData *m_csoundUserData; 131 QString m_description; 132 133 134 #ifdef USE_WIDGET_MUTEX 135 QReadWriteLock widgetLock; 136 #endif 137 QString xmlText; 138 139 virtual void contextMenuEvent(QContextMenuEvent *event); 140 141 virtual void createPropertiesDialog(); 142 virtual void applyProperties(); 143 144 QList<QAction *> getParentActionList(); 145 QList<QAction *> getParentPresetList(); 146 147 protected slots: 148 void apply(); 149 void deleteWidget(); 150 void openMidiDialog(); 151 152 private: 153 154 QAction *propertiesAct; 155 QAction *addChn_kAct; 156 157 158 QPushButton *applyButton; 159 QPushButton *cancelButton; 160 QPushButton *acceptButton; 161 162 private slots: 163 void addChn_k(); 164 165 signals: 166 void newValue(QPair<QString,double> channelValue); 167 void newValue(QPair<QString,QString> channelValue); 168 void widgetChanged(QuteWidget* widget); 169 void deleteThisWidget(QuteWidget *thisWidget); 170 void propertiesAccepted(); 171 void showMidiLearn(QuteWidget* widget); 172 void addChn_kSignal(QString channel); 173 174 }; 175 176 #endif 177