class library: Reset has been renamed to OnError
[supercollider.git] / bindings / PySCLang / PySCLang_vpost_stuff.cpp
blob67af869c1d6697486a78ec4f03237f67ab5c9c7a
1 /*
2 * File: PYSCLang_Module_GUIStuff.cpp
3 * Project : Psycollider
5 * by:
6 * Benjamin Golinvaux
7 * benjamin.golinvaux@euresys.com
8 * messenger: bgolinvaux@hotmail.com
10 * currently maintained by:
11 * Christopher Frauenberger
12 * frauenberger@iem.at
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
27 * USA
31 #ifndef SC_WIN32
32 #include "CXX/Objects.hxx"
33 #include "CXX/Extensions.hxx"
34 #else
35 #include "stdafx.h"
36 #endif
38 #include "PySCLang_Module.h"
40 #include <stdio.h>
41 #include <stdarg.h>
42 #include <iostream>
44 const int kPostBufferSize = 1024;
46 static char* _postBuffer = NULL;
47 using std::cout;
48 using std::flush;
50 int PySCLang_vpost(const char *fmt, va_list ap)
52 if(_postBuffer == NULL)
53 _postBuffer = new char[kPostBufferSize];
54 #ifdef SC3_WIN
55 int size = _vscprintf(fmt, ap);
56 #else
57 int size = vprintf(fmt, ap);
58 #endif
60 if (size < kPostBufferSize) {
61 vsprintf(_postBuffer, fmt, ap);
62 //_txtCtrl->AppendText(wxString(_postBuffer));
64 if( PySCLang_Module::scLogSink_s != NULL) {
65 /* make the Python call thread safe (global interpreter clock) */
66 PyGILState_STATE gstate;
67 gstate = PyGILState_Ensure();
69 PyObject *arglist = Py_BuildValue("(s)", _postBuffer);
70 PyEval_CallObject(PySCLang_Module::scLogSink_s, arglist);
72 PyGILState_Release(gstate);
74 else { // no log sink callable..
75 cout << _postBuffer;
79 else {
80 char* tmpPostBuffer = new char[size+1]; // +1 : NULL ending
81 vsprintf(tmpPostBuffer, fmt, ap);
82 cout << tmpPostBuffer << flush; //implement in python !!!!!!
83 delete [] tmpPostBuffer;
85 return 0;
88 void setPostFile(FILE* file)
90 // we're not using that , are we ?
93 #ifndef SC3_WIN
94 extern "C" {
95 int vpost(const char *fmt, va_list ap);
97 #endif
98 int vpost(const char *fmt, va_list ap)
100 PySCLang_vpost(fmt, ap);
101 return 0;
104 void post(const char *fmt, ...)
106 va_list ap;
107 va_start(ap, fmt);
108 PySCLang_vpost(fmt, ap);
111 void postfl(const char *fmt, ...)
113 va_list ap;
114 va_start(ap, fmt);
115 PySCLang_vpost(fmt, ap);
118 void postText(const char *str, long len)
120 char* txt = new char[len+1];
121 memcpy(txt,str,len);
122 txt[len] = 0;
123 post("%s",txt);
124 delete [] txt;
127 void postChar(char c)
129 char txt[2];
130 txt[0] = c;
131 txt[1] = 0;
132 post("%s",txt);
135 void error(const char *fmt, ...)
137 va_list ap;
138 va_start(ap, fmt);
139 PySCLang_vpost(fmt, ap);
143 void flushPostBuf(void)
147 void closeAllGUIScreens()
151 void initGUI()
156 void initSCViewPrimitives()
160 void initCocoaFilePrimitives()
164 void initRendezvousPrimitives()
169 #ifdef SC3_WIN
170 void initSpeechPrimitives()
173 #endif
175 long scMIDIout(int port, int len, int statushi, int chan, int data1, int data2)
177 return 0;