Debian Codegraph @

src/types.h

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 Andres Cabrera
3 [email protected]
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 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 // Time in milliseconds for widget and console messages updates
35 #define QCS_QUEUETIMER_DEFAULT_TIME 50
36 // Maximum number of files in recent files menu
37 #define QCS_MAX_RECENT_FILES 20
38 // Maximum undo history depth for widget panel and event sheet
39 #define QCS_MAX_UNDO 256
40
41 // Maximum MIDI message queue size for internal control
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 // macros for compatibility problems befor and after Qt 5.14
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 // qDebug() << "RingBuffer::put currentPos " << currentPos << " value " << value;
173 buffer[currentPos] = value;
174 currentPos++;
175 // if (currentPos == currentReadPos) {
176 // qDebug("RingBuffer: Buffer overflow!");
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 // qDebug("RingBuffer: Buffer overflow, only writing %ld elements!", space);
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 // qDebug() << "RingBuffer::copyAvailableBuffer saveSize " << saveSize << " currentPos " << currentPos << " currentReadPos " << currentReadPos ;
213 mutex.lock();
214 int available = availableReadSpace();
215 // qDebug("RingBuffer: Available: %i", available);
216 if (available <= saveSize) { //not enough data in buffer
217 mutex.unlock();
218 return false;
219 }
220 for (int i = 0; i < saveSize; i++) {
221 // qDebug("RingBuffer: currentPos %li currentReadPos %li value %f", currentPos, currentReadPos, buffer[currentReadPos%size]);
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