1 /* 2 Copyright (C) 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 EVENTSHEET_H 24 #define EVENTSHEET_H 25 26 #include <QTableWidget> 27 #include <QStandardItemModel> 28 #include <QAction> 29 #include <QTimer> 30 31 class EventSheet : public QTableWidget 32 { 33 Q_OBJECT 34 public: 35 36 EventSheet(QWidget *parent = 0); 37 ~EventSheet(); 38 39 QString getPlainText(bool scaleTempo = false); 40 QString getSelection(bool cut = false); 41 QString getLine(int number, bool scaleTempo = false, 42 bool storeNumber = false, bool preprocess = false, 43 double startOffset = 0.0); 44 QList< QList<QVariant> > getData(); 45 // double getTempo(); 46 // QString getName(); 47 void setFromText(QString text, int rowOffset = 0, int columnOffset = 0, 48 int numRows = 0, int numColumns = 0, bool noHistoryMark = false); 49 void setCell(int row, int column, QVariant text); 50 void setDebug(bool debug); 51 QPair<int, int> getSelectedRowsRange(); 52 53 public slots: 54 void setTempo(double value); 55 void setLoopLength(double value); 56 void sendEvents(); 57 void sendAllEvents(); 58 void sendEventsOffset(); 59 void loopEvents(); 60 void setLoopActive(bool loop); 61 void markLoop(double start = -1, double end = -1); // This does the actual marking and setting. 62 void setLoopRange(); // This is called internally, and it calls the mark loop function in event sheet panel 63 void stopAllEvents(); 64 void del(); 65 void cut(); 66 void copy(bool cut = false); 67 void paste(); 68 void undo(); 69 void redo(); 70 void markHistory(); 71 void clearHistory(); 72 void setScriptDirectory(QString dir); 73 74 void subtract(); 75 void add(); 76 void multiply(); 77 void divide(); 78 79 void randomize(); 80 void reverse(); // Reverse columns 81 void shuffle(); 82 // void mirror(); 83 void rotate(); 84 void fill(); 85 86 void insertColumnHere(); 87 void insertRowHere(); 88 void appendColumn(); 89 void appendRow(); 90 void appendColumns(); 91 void appendRows(); 92 void deleteColumn(); 93 void deleteRows(); 94 95 protected: 96 void contextMenuEvent(QContextMenuEvent * event); 97 virtual void keyPressEvent(QKeyEvent * event); 98 99 private: 100 void createActions(); 101 QList<QPair<QString, QString> > parseLine(QString line); 102 bool m_stopScript; // Order stopping python script 103 104 // Operations 105 void add(double value); 106 void multiply(double value); 107 void divide(double value); 108 void randomize(double min, double max, int mode); 109 void shuffle(int iterations); 110 void rotate(int amount); 111 void fill(double start, double end, double slope); 112 113 void runScript(QString script); 114 QString generateDataText(QString outFileName); 115 void addDirectoryToMenu(QMenu *m, QString dir, int depth = 0); 116 // void rename(QString name); 117 118 // Attributes to be saved 119 double m_tempo; 120 QString m_name; 121 122 // Actions 123 // QAction *copyAct; 124 // QAction *pasteAct; 125 // QAction *cutAct; 126 QAction *sendEventsAct; 127 QAction *sendEventsOffsetAct; 128 QAction *loopSelectionAct; 129 QAction *enableLoopAct; 130 QAction *markLoopAct; 131 QAction *stopAllEventsAct; 132 QAction *subtractAct; 133 QAction *addAct; 134 QAction *multiplyAct; 135 QAction *divideAct; 136 QAction *randomizeAct; 137 QAction *reverseAct; 138 QAction *shuffleAct; 139 // QAction *mirrorAct; 140 QAction *rotateAct; 141 QAction *fillAct; 142 QAction *stopScriptAct; 143 144 QAction *insertColumnHereAct; 145 QAction *insertRowHereAct; 146 QAction *appendColumnAct; 147 QAction *appendRowAct; 148 QAction *appendColumnsAct; 149 QAction *appendRowsAct; 150 QAction *deleteColumnAct; 151 QAction *deleteRowAct; 152 153 QStringList columnNames; 154 155 QList<double> activeInstruments; 156 bool m_looping; // Whether currently looping 157 bool m_debug; // Debug mode 158 double m_loopLength; 159 int noHistoryChange; // Last change in cells was made by undo 160 161 //Undo / Redo 162 int historyIndex; 163 QVector<QString> history; 164 165 // Looping 166 QTimer loopTimer; 167 int m_loopStart, m_loopEnd; // Start and end rows for looping (both inclusive) 168 // QModelIndexList loopList; 169 170 // Python scripts 171 QString scriptDir; 172 QStringList builtinScripts; 173 QStringList converterScripts; 174 QStringList testScripts; 175 176 private slots: 177 void newSelection(); 178 void cellDoubleClickedSlot(int row, int column); 179 void cellChangedSlot(int row, int column); 180 void stopScript(); 181 182 void runScript(); 183 184 signals: 185 void sendEvent(QString event); 186 void setLoopRangeFromSheet(double start, double end); 187 void setLoopEnabledFromSheet(bool enabled); 188 // void cellDoubleClicked(); 189 void modified(); 190 }; 191 192 #endif // EVENTSHEET_H 193