2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #import <objc/objc-class.h>
23 //#import <objc/runtime.h>
26 #include "PyrSymbol.h"
27 #include "PyrObject.h"
28 #include "PyrKernel.h"
30 #include "VMGlobals.h"
33 #if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4)
34 #define class_getName(a) ((a)->name)
37 NSMutableArray
*gUserPanels
= nil;
38 extern PyrSymbol
*s_doaction
;
39 extern PyrSymbol
*s_closed
;
40 extern pthread_mutex_t gLangMutex
;
42 @implementation UserPanel
46 if (gUserPanels
&& [gUserPanels count
]) {
47 NSMutableArray
*copy
= [gUserPanels copy
];
48 [gUserPanels removeAllObjects
];
49 [copy makeObjectsPerformSelector
: @selector(close
)];
58 gUserPanels
= [NSMutableArray arrayWithCapacity
: 8];
61 [gUserPanels addObject
: self];
65 - (NSWindow
*)window
{ return window
; }
72 - (void)windowWillClose
:(NSNotification
*)aNotification
74 [gUserPanels removeObject
: self];
76 pthread_mutex_lock (&gLangMutex
);
78 VMGlobals
*g
= gMainVMGlobals
;
80 ++g
->sp
; SetObject(g
->sp
, scobject
); // push window obj
81 runInterpreter(g
, s_closed
, 1);
84 pthread_mutex_unlock (&gLangMutex
);
87 - (void)setSCObject
: (struct PyrObject
*)inObject
{ scobject
= inObject
; }
89 - (struct PyrObject
*) getSCObject
{ return scobject
; }
91 void post(const char *fmt
, ...
);
93 - (IBAction
) panelAction
: (id) sender
96 post("sender '%s' %d\n", class_getName(object_getClass(sender
)), [sender tag
]);
97 if ([sender respondsToSelector
: @selector(selectedCell
)]) {
98 id cell
= [sender selectedCell
];
105 int tag
= [hitThing tag
];
106 post("hitThing '%s' %d\n", class_getName(object_getClass(hitThing
)), [sender tag
]);
107 // what kind of value is appropriate?
108 double controlValue
= 0.
;
109 if ([hitThing respondsToSelector
: @selector(doubleValue
)]) {
110 controlValue
= [hitThing doubleValue
];
113 if ([hitThing respondsToSelector
: @selector(stringValue
)]) {
114 cstring
= (char*)[[hitThing stringValue
] cStringUsingEncoding
:[NSString defaultCStringEncoding
]];
117 pthread_mutex_lock (&gLangMutex
);
119 VMGlobals
*g
= gMainVMGlobals
;
121 ++g
->sp
; SetObject(g
->sp
, scobject
); // push window obj
122 ++g
->sp
; SetInt(g
->sp
, tag
); // push tag
123 ++g
->sp
; SetFloat(g
->sp
, controlValue
);
125 PyrString
*scstring
= newPyrString(g
->gc
, cstring
, 0, false);
126 ++g
->sp
; SetObject(g
->sp
, scstring
); // push tag
128 ++g
->sp
; SetNil(g
->sp
); // push tag
130 runInterpreter(g
, s_doaction
, 4);
131 g
->canCallOS
= false;
133 pthread_mutex_unlock (&gLangMutex
);