| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef CSOUNDENGINE_H |
| 24 |
#define CSOUNDENGINE_H |
| 25 |
|
| 26 |
#include <QStringList> |
| 27 |
#include <QTimer> |
| 28 |
#include <QFuture> |
| 29 |
#include <QAtomicInt> |
| 30 |
|
| 31 |
#include <csound.hpp> |
| 32 |
#include <csPerfThread.hpp> |
| 33 |
#include <cwindow.h> |
| 34 |
|
| 35 |
#ifdef QCS_DEBUGGER |
| 36 |
#include "csdebug.h" |
| 37 |
#endif |
| 38 |
|
| 39 |
#include "types.h" |
| 40 |
#include "csoundoptions.h" |
| 41 |
#ifdef QCS_PYTHONQT |
| 42 |
#include "pythonconsole.h" |
| 43 |
#endif |
| 44 |
|
| 45 |
|
| 46 |
class ConsoleWidget; |
| 47 |
class QuteScope; |
| 48 |
class QuteGraph; |
| 49 |
class Curve; |
| 50 |
class CsoundEngine; |
| 51 |
class WidgetLayout; |
| 52 |
class MidiHandler; |
| 53 |
class QuteWidget; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#define QCS_DESTROY_CSOUND |
| 58 |
|
| 59 |
typedef enum { |
| 60 |
QCS_NO_FLAGS = 0, |
| 61 |
QCS_NO_COPY_BUFFER = 1, |
| 62 |
QCS_NO_PYTHON_CALLBACK = 2, |
| 63 |
QCS_NO_CONSOLE_MESSAGES = 4, |
| 64 |
QCS_NO_RT_EVENTS = 8 |
| 65 |
} PerfFlags; |
| 66 |
|
| 67 |
struct CsoundUserData { |
| 68 |
int result; |
| 69 |
CSOUND *csound; |
| 70 |
CsoundPerformanceThread *perfThread; |
| 71 |
CsoundEngine *csEngine; |
| 72 |
WidgetLayout *wl; |
| 73 |
MidiHandler *midiHandler; |
| 74 |
QMutex *playMutex; |
| 75 |
|
| 76 |
bool runDispatcher; |
| 77 |
QVector<double> mouseValues; |
| 78 |
RingBuffer audioOutputBuffer; |
| 79 |
bool enableWidgets; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
PerfFlags flags; |
| 84 |
|
| 85 |
MYFLT zerodBFS; |
| 86 |
int numChnls; |
| 87 |
int sampleRate; |
| 88 |
long outputBufferSize; |
| 89 |
int msgRefreshTime; |
| 90 |
|
| 91 |
|
| 92 |
QList<QString> inputChannelNames; |
| 93 |
QList<QString> outputChannelNames; |
| 94 |
QList<QString> outputStringChannelNames; |
| 95 |
QList<QVariant> previousOutputValues; |
| 96 |
QList<QVariant> previousStringOutputValues; |
| 97 |
QString lastRecordingOutfile; |
| 98 |
|
| 99 |
void *midiBuffer; |
| 100 |
void *virtualMidiBuffer; |
| 101 |
|
| 102 |
#ifdef QCS_PYTHONQT |
| 103 |
PythonConsole *m_pythonConsole; |
| 104 |
QString m_pythonCallback; |
| 105 |
int m_pythonCallbackCounter; |
| 106 |
int m_pythonCallbackSkip; |
| 107 |
#endif |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
class CsoundEngine : public QObject |
| 112 |
{ |
| 113 |
Q_OBJECT |
| 114 |
public: |
| 115 |
CsoundEngine(ConfigLists *configlists); |
| 116 |
~CsoundEngine(); |
| 117 |
|
| 118 |
static void outputValueCallback (CSOUND *csound, |
| 119 |
const char *channelName, |
| 120 |
void *channelValuePtr, |
| 121 |
const void *channelType); |
| 122 |
static void inputValueCallback (CSOUND *csound, |
| 123 |
const char *channelName, |
| 124 |
void *channelValuePtr, |
| 125 |
const void *channelType); |
| 126 |
|
| 127 |
static int midiInOpenCb(CSOUND *csound, void **ud, const char *devName); |
| 128 |
static int midiReadCb(CSOUND *csound, void *ud_, unsigned char *buf, int nBytes); |
| 129 |
static int midiInCloseCb(CSOUND *csound, void *ud); |
| 130 |
static int midiOutOpenCb(CSOUND *csound, void **ud, const char *devName); |
| 131 |
static int midiWriteCb(CSOUND *csound, void *ud_, const unsigned char *buf, int nBytes); |
| 132 |
static int midiOutCloseCb(CSOUND *csound, void *ud); |
| 133 |
static const char *midiErrorStringCb(int); |
| 134 |
void queueMidiIn(std::vector<unsigned char> *message); |
| 135 |
void queueVirtualMidiIn(std::vector<unsigned char> &message); |
| 136 |
void sendMidiOut(QVector<unsigned char> &message); |
| 137 |
|
| 138 |
static void makeGraphCallback(CSOUND *csound, WINDAT *windat, const char *name); |
| 139 |
static void drawGraphCallback(CSOUND *csound, WINDAT *windat); |
| 140 |
static void killGraphCallback(CSOUND *csound, WINDAT *windat); |
| 141 |
static int exitGraphCallback(CSOUND *csound); |
| 142 |
static int keyEventCallback(void *userData, |
| 143 |
void *p, |
| 144 |
unsigned int type); |
| 145 |
static void csThread(void *data); |
| 146 |
|
| 147 |
static void readWidgetValues(CsoundUserData *ud); |
| 148 |
static void writeWidgetValues(CsoundUserData *ud); |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void setWidgetLayout(WidgetLayout *wl); |
| 153 |
void setMidiHandler(MidiHandler *mh); |
| 154 |
|
| 155 |
void enableWidgets(bool enable); |
| 156 |
|
| 157 |
void registerConsole(ConsoleWidget *c); |
| 158 |
QList<QPair<int, QString> > getErrorLines(); |
| 159 |
void setConsoleBufferSize(int size); |
| 160 |
int popKeyPressEvent(); |
| 161 |
int popKeyReleaseEvent(); |
| 162 |
|
| 163 |
void processEventQueue(); |
| 164 |
void passOutValue(QString channelName, double value); |
| 165 |
void passOutString(QString channelName, QString value); |
| 166 |
void flushQueues(); |
| 167 |
void queueMessage(QString message); |
| 168 |
|
| 169 |
bool isRunning(); |
| 170 |
bool isRecording(); |
| 171 |
bool isPaused() {return m_paused; } |
| 172 |
|
| 173 |
|
| 174 |
CSOUND * getCsound(); |
| 175 |
CsoundUserData *getUserData(); |
| 176 |
void clearConsoles(void); |
| 177 |
#ifdef QCS_PYTHONQT |
| 178 |
void registerProcessCallback(QString func, int skipPeriods); |
| 179 |
void setPythonConsole(PythonConsole *pc); |
| 180 |
#endif |
| 181 |
|
| 182 |
#ifdef QCS_DEBUGGER |
| 183 |
bool m_debugging; |
| 184 |
|
| 185 |
static void breakpointCallback(CSOUND *csound, debug_bkpt_info_t *bkpt_info, void *udata); |
| 186 |
void setDebug(); |
| 187 |
void pauseDebug(); |
| 188 |
void continueDebug(); |
| 189 |
void stopDebug(); |
| 190 |
void addInstrumentBreakpoint(double instr, int skip); |
| 191 |
void removeInstrumentBreakpoint(double instr); |
| 192 |
void addBreakpoint(int line, int instr, int skip); |
| 193 |
void removeBreakpoint(int line, int instr); |
| 194 |
void setStartingBreakpoints(QVector<QVariantList> bps); |
| 195 |
QVector<QVariantList> getVaribleList(); |
| 196 |
QVector<QVariantList> getInstrumentList(); |
| 197 |
int getCurrentLine(); |
| 198 |
QVector<QVariantList> m_varList; |
| 199 |
QVector<QVariantList> m_instrumentList; |
| 200 |
QAtomicInt m_currentLine; |
| 201 |
QMutex variableMutex; |
| 202 |
QMutex instrumentMutex; |
| 203 |
QVector<QVariantList> m_startBreakpoints; |
| 204 |
#endif |
| 205 |
|
| 206 |
public slots: |
| 207 |
int play(CsoundOptions *options); |
| 208 |
void stop(); |
| 209 |
void pause(); |
| 210 |
int startRecording(int format, QString filename); |
| 211 |
void stopRecording(); |
| 212 |
void queueEvent(QString eventLine, int delay = 0); |
| 213 |
void keyPressForCsound(int key); |
| 214 |
void keyReleaseForCsound(int key); |
| 215 |
|
| 216 |
void registerScope(QuteScope *scope); |
| 217 |
|
| 218 |
void registerGraph(QuteGraph *scope); |
| 219 |
void requestCsoundUserData(QuteWidget *widget); |
| 220 |
void setFlags(PerfFlags flags) {ud->flags = flags;} |
| 221 |
|
| 222 |
void evaluate(QString code); |
| 223 |
|
| 224 |
public: |
| 225 |
QVector<ConsoleWidget *> consoles; |
| 226 |
int runCsound(); |
| 227 |
void stopCsound(); |
| 228 |
void cleanupCsound(); |
| 229 |
int checkSyntax(); |
| 230 |
|
| 231 |
private: |
| 232 |
void setupChannels(); |
| 233 |
QList <int> getAnsiKeySequence(int key); |
| 234 |
|
| 235 |
QFuture<void> m_msgUpdateThread; |
| 236 |
static void messageListDispatcher(void *data); |
| 237 |
|
| 238 |
CsoundUserData *ud; |
| 239 |
|
| 240 |
CsoundOptions m_options; |
| 241 |
|
| 242 |
int m_consoleBufferSize; |
| 243 |
QMutex m_messageMutex; |
| 244 |
QStringList messageQueue; |
| 245 |
QMutex keyMutex; |
| 246 |
QList <int> keyPressBuffer; |
| 247 |
QList <int> keyReleaseBuffer; |
| 248 |
|
| 249 |
bool m_recording; |
| 250 |
bool m_paused; |
| 251 |
|
| 252 |
QMutex m_playMutex; |
| 253 |
QMutex eventMutex; |
| 254 |
QMutex csoundMutex; |
| 255 |
QVector<QString> eventQueue; |
| 256 |
int m_refreshTime; |
| 257 |
QVector<unsigned long> eventTimeStamps; |
| 258 |
int eventQueueSize; |
| 259 |
|
| 260 |
private slots: |
| 261 |
|
| 262 |
signals: |
| 263 |
void errorLines(QList<QPair<int, QString> >); |
| 264 |
void passMessages(QString msg); |
| 265 |
void stopSignal(); |
| 266 |
void breakpointReached(); |
| 267 |
}; |
| 268 |
|
| 269 |
#endif |