| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef TYPES_H |
| 24 |
#define TYPES_H |
| 25 |
|
| 26 |
#include <QMutex> |
| 27 |
#include <QtGlobal> |
| 28 |
#include <QDebug> |
| 29 |
#include <csound.h> |
| 30 |
|
| 31 |
|
| 32 |
#define QCS_VERSION "1.1.3" |
| 33 |
|
| 34 |
|
| 35 |
#define QCS_QUEUETIMER_DEFAULT_TIME 50 |
| 36 |
|
| 37 |
#define QCS_MAX_RECENT_FILES 20 |
| 38 |
|
| 39 |
#define QCS_MAX_UNDO 256 |
| 40 |
|
| 41 |
|
| 42 |
#define QCS_MAX_MIDI_QUEUE 128 |
| 43 |
|
| 44 |
#ifdef Q_OS_LINUX |
| 45 |
#define DEFAULT_HTML_DIR "/usr/share/doc/csound-doc/html" |
| 46 |
#define DEFAULT_TERM_EXECUTABLE "/usr/bin/xterm" |
| 47 |
#define DEFAULT_BROWSER_EXECUTABLE "/usr/bin/firefox" |
| 48 |
#define DEFAULT_WAVEEDITOR_EXECUTABLE "/usr/bin/audacity" |
| 49 |
#define DEFAULT_WAVEPLAYER_EXECUTABLE "/usr/bin/aplay" |
| 50 |
#define DEFAULT_PDFVIEWER_EXECUTABLE "/usr/bin/evince" |
| 51 |
#define DEFAULT_DOT_EXECUTABLE "dot" |
| 52 |
#define DEFAULT_LOG_FILE "" |
| 53 |
#define DEFAULT_SCRIPT_DIR "/usr/share/csoundqt/Scripts" |
| 54 |
#endif |
| 55 |
#ifdef Q_OS_SOLARIS |
| 56 |
#define DEFAULT_HTML_DIR "/usr/local/share/doc/csound/html" |
| 57 |
#define DEFAULT_TERM_EXECUTABLE "/usr/openwin/bin/xterm" |
| 58 |
#define DEFAULT_BROWSER_EXECUTABLE "/usr/bin/firefox" |
| 59 |
#define DEFAULT_WAVEEDITOR_EXECUTABLE "/usr/local/bin/audacity" |
| 60 |
#define DEFAULT_WAVEPLAYER_EXECUTABLE "/usr/bin/jmplay" |
| 61 |
#define DEFAULT_PDFVIEWER_EXECUTABLE "/usr/bin/evince" |
| 62 |
#define DEFAULT_DOT_EXECUTABLE "dot" |
| 63 |
#define DEFAULT_LOG_FILE "" |
| 64 |
#define DEFAULT_SCRIPT_DIR "../../csoundqt/src/Scripts" |
| 65 |
#endif |
| 66 |
#ifdef Q_OS_MAC |
| 67 |
#define DEFAULT_HTML_DIR "/Library/Frameworks/CsoundLib64.framework/Resources/Manual" |
| 68 |
#define DEFAULT_TERM_EXECUTABLE "/Applications/Utilities/Terminal.app" |
| 69 |
#define DEFAULT_BROWSER_EXECUTABLE "/Applications/Safari.app" // Safary is installed by default so let's use that |
| 70 |
#define DEFAULT_WAVEEDITOR_EXECUTABLE "/Applications/Audacity.app" |
| 71 |
#define DEFAULT_WAVEPLAYER_EXECUTABLE "/Applications/QuickTime Player.app" |
| 72 |
#define DEFAULT_PDFVIEWER_EXECUTABLE "/Applications/Preview.app" |
| 73 |
#define DEFAULT_DOT_EXECUTABLE "/usr/local/bin/dot" |
| 74 |
#define DEFAULT_LOG_FILE "" |
| 75 |
#define DEFAULT_SCRIPT_DIR qApp->applicationDirPath() + "/../Resources/Scripts" |
| 76 |
#endif |
| 77 |
#ifdef Q_OS_WIN32 |
| 78 |
#define DEFAULT_HTML_DIR "C:/Program Files/Csound/doc/manual" |
| 79 |
#define DEFAULT_TERM_EXECUTABLE "cmd.exe" |
| 80 |
#define DEFAULT_BROWSER_EXECUTABLE "" |
| 81 |
#define DEFAULT_WAVEEDITOR_EXECUTABLE "" |
| 82 |
#define DEFAULT_WAVEPLAYER_EXECUTABLE "" |
| 83 |
#define DEFAULT_PDFVIEWER_EXECUTABLE "" |
| 84 |
#define DEFAULT_DOT_EXECUTABLE "" |
| 85 |
#define DEFAULT_LOG_FILE "" |
| 86 |
#define DEFAULT_SCRIPT_DIR qApp->applicationDirPath() + "/Scripts" |
| 87 |
#endif |
| 88 |
#ifdef Q_OS_HAIKU |
| 89 |
#define DEFAULT_HTML_DIR "/boot/common/share/doc/csound-doc/html" |
| 90 |
#define DEFAULT_TERM_EXECUTABLE "Terminal" |
| 91 |
#define DEFAULT_BROWSER_EXECUTABLE "/boot/apps/WebPositive/WebPositive" |
| 92 |
#define DEFAULT_WAVEEDITOR_EXECUTABLE "" |
| 93 |
#define DEFAULT_WAVEPLAYER_EXECUTABLE "/boot/system/apps/MediaPlayer" |
| 94 |
#define DEFAULT_PDFVIEWER_EXECUTABLE "/boot/apps/BePDF/BePDF" |
| 95 |
#define DEFAULT_DOT_EXECUTABLE "dot" |
| 96 |
#define DEFAULT_LOG_FILE "" |
| 97 |
#endif |
| 98 |
|
| 99 |
#define QCS_DEFAULT_TEMPLATE "<CsoundSynthesizer>\n<CsOptions>\n-odac\n</CsOptions>\n<CsInstruments>\n\nsr = 44100\nksmps = 64\nnchnls = 2\n0dbfs = 1\n\n\n</CsInstruments>\n<CsScore>\n\n</CsScore>\n</CsoundSynthesizer>" |
| 100 |
|
| 101 |
#define QDEBUG qDebug() << __FUNCTION__ << ":" |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
#if QT_VERSION >= QT_VERSION_CHECK(5,14,0) |
| 106 |
#define ENDL Qt::endl |
| 107 |
#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts |
| 108 |
#else |
| 109 |
#define ENDL endl |
| 110 |
#define SKIP_EMPTY_PARTS QString::SkipEmptyParts |
| 111 |
#endif |
| 112 |
|
| 113 |
|
| 114 |
enum viewMode { |
| 115 |
VIEW_CSD, |
| 116 |
VIEW_ORC_SCO |
| 117 |
}; |
| 118 |
|
| 119 |
class Opcode |
| 120 |
{ |
| 121 |
public: |
| 122 |
QString opcodeName; |
| 123 |
QString outArgs; |
| 124 |
QString inArgs; |
| 125 |
QString desc; |
| 126 |
int isFlag; |
| 127 |
bool isInstalled; |
| 128 |
|
| 129 |
Opcode() = default; |
| 130 |
Opcode(QString name, QString outs="", QString ins="", bool installed=true): opcodeName(name), outArgs(outs), inArgs(ins), isInstalled(installed) {} |
| 131 |
|
| 132 |
}; |
| 133 |
|
| 134 |
class RingBuffer |
| 135 |
{ |
| 136 |
public: |
| 137 |
RingBuffer() { |
| 138 |
size = 4096 * 4; |
| 139 |
resize(size); |
| 140 |
currentPos = 0; |
| 141 |
currentReadPos = 0; |
| 142 |
} |
| 143 |
~RingBuffer() = default; |
| 144 |
QList<MYFLT> buffer; |
| 145 |
long currentPos; |
| 146 |
long currentReadPos; |
| 147 |
int size; |
| 148 |
QMutex mutex; |
| 149 |
|
| 150 |
void lock() { |
| 151 |
mutex.lock(); |
| 152 |
} |
| 153 |
|
| 154 |
void unlock() { |
| 155 |
mutex.unlock(); |
| 156 |
} |
| 157 |
|
| 158 |
long availableWriteSpace() { |
| 159 |
if(currentReadPos <= currentPos) |
| 160 |
return size - currentPos + currentReadPos; |
| 161 |
return currentReadPos - currentPos; |
| 162 |
} |
| 163 |
|
| 164 |
long availableReadSpace() { |
| 165 |
return (currentReadPos <= currentPos ? |
| 166 |
currentPos - currentReadPos : |
| 167 |
currentPos - currentReadPos + size); |
| 168 |
} |
| 169 |
|
| 170 |
void put(MYFLT value) { |
| 171 |
mutex.lock(); |
| 172 |
|
| 173 |
buffer[currentPos] = value; |
| 174 |
currentPos++; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
if (currentPos >= size) |
| 179 |
currentPos = 0; |
| 180 |
mutex.unlock(); |
| 181 |
} |
| 182 |
|
| 183 |
void putManyScaled(MYFLT *data, long dataSize, MYFLT scaleFactor) { |
| 184 |
long space = availableWriteSpace(); |
| 185 |
if(dataSize >= space) { |
| 186 |
|
| 187 |
currentReadPos = currentPos; |
| 188 |
} |
| 189 |
mutex.lock(); |
| 190 |
if(scaleFactor != 1.0) { |
| 191 |
for(int i=0; i<dataSize; i++) { |
| 192 |
int idx = (currentPos + i) % size; |
| 193 |
buffer[idx] = data[i] * scaleFactor; |
| 194 |
} |
| 195 |
} else { |
| 196 |
for(int i=0; i<dataSize; i++) { |
| 197 |
int idx = (currentPos + i) % size; |
| 198 |
buffer[idx] = data[i]; |
| 199 |
} |
| 200 |
} |
| 201 |
auto previousPos = currentPos; |
| 202 |
currentPos += dataSize; |
| 203 |
currentPos %= size; |
| 204 |
if(currentPos > currentReadPos && previousPos < currentReadPos) |
| 205 |
currentReadPos = currentPos; |
| 206 |
else if(currentPos < currentReadPos && previousPos >= currentReadPos) |
| 207 |
currentReadPos = currentPos; |
| 208 |
mutex.unlock(); |
| 209 |
} |
| 210 |
|
| 211 |
bool copyAvailableBuffer(MYFLT *data, int saveSize) { |
| 212 |
|
| 213 |
mutex.lock(); |
| 214 |
int available = availableReadSpace(); |
| 215 |
|
| 216 |
if (available <= saveSize) { |
| 217 |
mutex.unlock(); |
| 218 |
return false; |
| 219 |
} |
| 220 |
for (int i = 0; i < saveSize; i++) { |
| 221 |
|
| 222 |
data[i] = buffer[currentReadPos]; |
| 223 |
currentReadPos++; |
| 224 |
if (currentReadPos == size) { |
| 225 |
currentReadPos = 0; } |
| 226 |
} |
| 227 |
mutex.unlock(); |
| 228 |
return true; |
| 229 |
} |
| 230 |
|
| 231 |
void resize(int newsize) { |
| 232 |
qDebug("Resizing scope: %d to %d", buffer.size(), newsize); |
| 233 |
mutex.lock(); |
| 234 |
buffer.clear(); |
| 235 |
for (int i = 0; i< newsize; i++) { |
| 236 |
buffer.append(0.0); |
| 237 |
} |
| 238 |
currentPos = 0; |
| 239 |
size = newsize; |
| 240 |
mutex.unlock(); |
| 241 |
} |
| 242 |
|
| 243 |
void allZero() { |
| 244 |
mutex.lock(); |
| 245 |
for (int i = 0; i< buffer.size(); i++) { |
| 246 |
buffer[i] = 0; |
| 247 |
} |
| 248 |
currentReadPos = 0; |
| 249 |
currentPos = 0; |
| 250 |
mutex.unlock(); |
| 251 |
} |
| 252 |
}; |
| 253 |
|
| 254 |
#endif |