File: PySCLang_vpost_stuff.cpp

package info (click to toggle)
supercollider 1%3A3.4.5-1wheezy1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,972 kB
  • sloc: cpp: 116,645; lisp: 64,914; ansic: 10,725; python: 3,548; perl: 766; ruby: 487; sh: 152; makefile: 117; xml: 13
file content (178 lines) | stat: -rw-r--r-- 3,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * File: PYSCLang_Module_GUIStuff.cpp
 * Project : Psycollider
 *
 * by:
 * Benjamin Golinvaux
 * benjamin.golinvaux@euresys.com
 * messenger: bgolinvaux@hotmail.com
 *
 * currently maintained by:
 * Christopher Frauenberger
 * frauenberger@iem.at
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 *  USA
 *
 */

#ifndef SC_WIN32
#include "pycxx/CXX/Objects.hxx"
#include "pycxx/CXX/Extensions.hxx"
#else
#include "stdafx.h"
#endif

#include "PySCLang_Module.h"

#include <stdio.h>
#include <stdarg.h>
#include <iostream>

const int kPostBufferSize = 1024;

static char* _postBuffer = NULL;
using std::cout;
using std::flush;

int PySCLang_vpost(const char *fmt, va_list ap)
{
  if(_postBuffer == NULL)
    _postBuffer = new char[kPostBufferSize];
#ifdef SC3_WIN
  int size = _vscprintf(fmt, ap);
#else
  int size = vprintf(fmt, ap);
#endif

  if (size < kPostBufferSize) {
    vsprintf(_postBuffer, fmt, ap);
    //_txtCtrl->AppendText(wxString(_postBuffer));

	if( PySCLang_Module::scLogSink_s != NULL) {
		/* make the Python call thread safe (global interpreter clock) */
		PyGILState_STATE gstate;
		gstate = PyGILState_Ensure();

		PyObject *arglist = Py_BuildValue("(s)", _postBuffer);
		PyEval_CallObject(PySCLang_Module::scLogSink_s, arglist);

		PyGILState_Release(gstate);
	}
    else { // no log sink callable..
      cout << _postBuffer;
    }

  }
  else {
    char* tmpPostBuffer = new char[size+1]; // +1 : NULL ending
    vsprintf(tmpPostBuffer, fmt, ap);
    cout << tmpPostBuffer << flush; //implement in python !!!!!!
    delete [] tmpPostBuffer;
  }
  return 0;
}

void setPostFile(FILE* file)
{
  // we're not using that , are we ?
}

#ifndef SC3_WIN
extern "C" {
	int vpost(const char *fmt, va_list ap);
}
#endif
int vpost(const char *fmt, va_list ap)
{
	PySCLang_vpost(fmt, ap);
	return 0;
}

void post(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  PySCLang_vpost(fmt, ap);
}

void postfl(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  PySCLang_vpost(fmt, ap);
}

void postText(const char *str, long len)
{
  char* txt = new char[len+1];
  memcpy(txt,str,len);
  txt[len] = 0;
  post("%s",txt);
  delete [] txt;
}

void postChar(char c)
{
  char txt[2];
  txt[0] = c;
  txt[1] = 0;
  post("%s",txt);
}

void error(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  PySCLang_vpost(fmt, ap);
}


void flushPostBuf(void)
{
}

void closeAllGUIScreens()
{
}

void initGUI()
{
}


void initSCViewPrimitives()
{
}

void initCocoaFilePrimitives()
{
}

void initRendezvousPrimitives()
{
}


#ifdef SC3_WIN
void initSpeechPrimitives()
{
}
#endif

long scMIDIout(int port, int len, int statushi, int chan, int data1, int data2)
{
    return 0;
}