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
|
/*
winFLTK.c: graphs using FLTK library
Copyright (C) 2002 John ffitch
This file is part of Csound.
The Csound Library is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Csound 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Csound; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
/* winFLTK.c */
/* Csound FLTK/X graphs */
/* jpff,06Oct02 */
#include "csdl.h"
#include <stdio.h>
#include "cwindow.h"
#ifdef LINUX
#include <X11/Xlib.h>
#endif
#include "winFLTK.h"
static void MakeGraph_FLTK(CSOUND *csound, WINDAT *wdptr, const char *name)
{
wdptr->windid = MakeWindow_FLTK(csound,(char*)name);
}
static void KillGraph_FLTK(CSOUND *csound, WINDAT *wdptr)
{
kill_graph(csound, wdptr->windid);
}
static int dummyWidgetOpcode(CSOUND *csound, void *p)
{
const char *opname;
opname = csound->GetOpcodeName(p);
csound->Die(csound, Str("%s: widget opcodes have been disabled by "
"the host application"), opname);
return NOTOK;
}
PUBLIC int csoundModuleCreate(CSOUND *csound)
{
(void)csound;
return 0;
}
PUBLIC int csoundModuleInit(CSOUND *csound)
{
const OENTRY *ep = &(widgetOpcodes_[0]);
int initFlags = 0;
int *fltkFlags;
int enableDisplays = 0;
OPARMS oparms;
csound->GetOParms(csound, &oparms);
if (csound->QueryGlobalVariable(csound,
"FLTK_Flags") == (void*) 0) {
if (UNLIKELY(csound->CreateGlobalVariable(csound,
"FLTK_Flags", sizeof(int)) != 0))
csound->Die(csound, "%s",
Str("widgets.cpp: error allocating FLTK flags"));
initFlags = 1;
}
fltkFlags = getFLTKFlagsPtr(csound);
if (((*fltkFlags) & 2) == 0 &&
!(oparms.graphsoff || oparms.postscript)) {
#ifdef LINUX
Display *dpy = XOpenDisplay(NULL);
if (dpy != NULL) {
XCloseDisplay(dpy);
#endif
if (csound->SetIsGraphable(csound, 1) == 0) {
enableDisplays = 1;
(*fltkFlags) |= 64;
if (!((*fltkFlags) & 256))
csound->SetInternalYieldCallback(csound, CsoundYield_FLTK);
flgraph_init(csound); /* Create space */
csound->SetMakeGraphCallback(csound, MakeGraph_FLTK);
csound->SetDrawGraphCallback(csound, DrawGraph_FLTK);
csound->SetKillGraphCallback(csound, KillGraph_FLTK);
csound->SetExitGraphCallback(csound, ExitGraph_FLTK);
/* seemed to crash, but not anymore... */
csound->RegisterResetCallback(csound, NULL, widget_reset);
csound->Message(csound, "graph init...\n");
}
#ifdef LINUX
}
#endif
}
if (initFlags) {
#ifndef __MACH__
if (enableDisplays)
#endif
(*fltkFlags) |= 28;
}
if (!((*fltkFlags) & 129))
for ( ; ep->opname != NULL; ep++) {
if (csound->AppendOpcode(csound, ep->opname,
(int)ep->dsblksiz, (int)ep->flags, (int)ep->thread,
ep->outypes, ep->intypes,
ep->iopadr, ep->kopadr, ep->aopadr) != 0) {
csound->ErrorMsg(csound, Str("Error registering opcode '%s'"),
ep->opname);
return -1;
}
}
else if (!((*fltkFlags) & 128)) {
for ( ; ep->opname != NULL; ep++) {
if (csound->AppendOpcode(
csound, ep->opname, (int)ep->dsblksiz,
(int)ep->flags,(int)ep->thread,
ep->outypes, ep->intypes,
(((int)ep->thread & 1) ? dummyWidgetOpcode : (SUBR) 0),
(((int)ep->thread & 2) ? dummyWidgetOpcode : (SUBR) 0),
(((int)ep->thread & 4) ? dummyWidgetOpcode : (SUBR) 0)) != 0) {
csound->ErrorMsg(csound, Str("Error registering opcode '%s'"),
ep->opname);
return -1;
}
}
}
widget_init(csound);
return 0;
}
PUBLIC int csoundModuleInfo(void)
{
return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int)sizeof(MYFLT));
}
|