download event.scm
Language: Scheme
LOC: 300
Project Info
Snd
Server: SourceForge
Type: cvs
SourceForge\s\snd\snd\cvs‑snd\
   _new_snd-test.rb
   _sndlib.h
   aclocal.m4
   analog-filter.scm
   audinfo.c
   audio.c
   autosave.scm
   bess.rb
   bess.scm
   bess1.rb
   bess1.scm
   bird.rb
   bird.scm
   clm-ins.rb
   clm-ins.scm
   clm-strings.h
   clm.c
   clm.h
   clm23.scm
   clm2xen.c
   clm2xen.h
   cmn-glyphs.lisp
   config.guess
   config.h.in
   config.rpath
   config.sub
   configure.ac
   debug.scm
   dlocsig.rb
   draw.rb
   draw.scm
   dsp.rb
   dsp.scm
   edit-menu.scm
   edit123.scm
   effects-utils.scm
   effects.rb
   env.rb
   env.scm
   enved.scm
   eval-c.scm
   event.scm
   examp.rb
   examp.scm
   extensions.rb
   extensions.scm
   fade.scm
   fft-menu.scm
   fix-optargs.scm
   fmv.scm
   freeverb.rb
   freeverb.scm
   gettext.h
   gl.c
   grani.scm
   gtk-effects.scm
   gtk-popup.scm
   gui.scm
   headers.c
   help-snd-fm.pd
   help-snd.pd
   HISTORY.Snd
   hooks.rb
   hooks.scm
   index.rb
   index.scm
   inf-snd.el
   io.c
   jcrev.scm
   ladspa-help.scm
   ladspa.scm
   makefile.in
   makefile.no-gettext
   maraca.rb
   maraca.scm
   marks-menu.scm
   marks.rb
   marks.scm
   maxf.rb
   maxf.scm
   midi.c
   misc.scm
   mix-menu.scm
   mix.rb
   mix.scm
   mixer.scm
   moog.scm
   musglyphs.rb
   musglyphs.scm
   nb.rb
   nb.scm
   new-backgrounds.scm
   new-buttons.scm
   new-effects.scm
   new-icons.scm
   noise.rb
   noise.scm
   old-mac-audio.c
   old-snd.spec
   oo.scm
   oscope.scm
   panic.scm
   pd-add.scm
   pd-any.scm
   pd-fm.scm
   pd-global.scm
   pd-inout.scm
   pd-local.scm
   pd-mozilla.scm
   pd-send_receive.scm
   peak-env.scm
   piano.rb
   piano.scm
   play.rb
   play.scm
   poly.rb
   poly.scm
   popup.rb
   popup.scm
   prc95.rb
   prc95.scm
   pvoc.rb
   pvoc.scm
   README.Snd
   rgb.rb
   rgb.scm
   rmsgain.scm
   rt-compiler.scm
   rt-engine.scm
   rt-examples.scm
   rt.tex
   rtio.rb
   rtio.scm
   rubber.rb
   rubber.scm
   saw.c
   singer.rb
   singer.scm
   snd-0.h
   snd-1.h
   snd-axis.c
   snd-chn.c
   snd-completion.c
   snd-dac.c
   snd-data.c
   snd-draw.c
   snd-edits.c
   snd-env.c
   snd-error.c
   snd-fft.c
   snd-file.c
   snd-file.h
   snd-find.c
   snd-g0.h
   snd-g1.h
   snd-gchn.c
   snd-gdraw.c
   snd-gdrop.c
   snd-genv.c
   snd-gfft.c
   snd-gfile.c
   snd-gfind.c
   snd-ghelp.c
   snd-gl.scm
   snd-glistener.c
   snd-gmain.c
   snd-gmenu.c
   snd-gmix.c
   snd-gprefs.c
   snd-gprint.c
   snd-grec.c
   snd-gregion.c
   snd-gsnd.c
   snd-gtk.scm
   snd-gutils.c
   snd-gxbitmaps.c
   snd-gxcolormaps.c
   snd-gxen.c
   snd-gxutils.c
   snd-help.c
   snd-hobbit.scm
   snd-io.c
   snd-kbd.c
   snd-ladspa.c
   snd-listener.c
   snd-main.c
   snd-marks.c
   snd-menu.c
   snd-menu.h
   snd-mix.c
   snd-motif.scm
   snd-nogui.c
   snd-nogui0.h
   snd-nogui1.h
   snd-prefs.c
   snd-print.c
   snd-rec.c
   snd-rec.h
   snd-region.c
   snd-run.c
   snd-select.c
   snd-sig.c
   snd-snd.c
   snd-strings.h
   snd-trans.c
   snd-utils.c
   snd-x0.h
   snd-x1.h
   snd-xchn.c
   snd-xdraw.c
   snd-xdrop.c
   snd-xen.c
   snd-xenv.c
   snd-xfft.c
   snd-xfile.c
   snd-xfind.c
   snd-xhelp.c
   snd-xlistener.c
   snd-xm.rb
   snd-xmain.c
   snd-xmenu.c
   snd-xmix.c
   snd-xprefs.c
   snd-xprint.c
   snd-xrec.c
   snd-xref.c
   snd-xregion.c
   snd-xsnd.c
   snd-xutils.c
   snd-xxen.c
   snd.1
   Snd.ad
   snd.c
   Snd.gtkrc
   snd.h
   snd.spec
   snd_conffile.scm
   snd_pd_external.c
   snd_pd_external.h
   snd4.scm
   snd5.scm
   snd6.scm
   snd7.scm
   sndctrl.c
   sndinfo.c
   sndlib-strings.h
   sndlib.h.in
   sndlib2xen.c
   sndlib2xen.h
   sndplay.c
   sndrecord.c
   sndwarp.scm
   sound.c
   special-menu.scm
   spectr.rb
   spectr.scm
   strad.rb
   strad.scm
   TODO.Snd
   track-colors.scm
   v.rb
   v.scm
   vct.c
   vct.h
   ws.rb
   ws.scm
   xen.c
   xen.h
   xg-x11.h
   xm-enved.rb
   xm-enved.scm
   zip.rb
   zip.scm

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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
;;; event.scm: user-interface auto-test functions (see snd-test.scm)

(provide 'snd-event.scm)

(if (not (provided? 'xm))
    (let ((hxm (dlopen "xm.so")))
      (if (string? hxm)
	  (snd-error (format #f "event.scm needs the xm module: ~A" hxm))
	  (dlinit hxm "Init_libxm"))))


(define key-event
  (let ((e (XEvent KeyPress))
	(cast-current-time (list 'Time CurrentTime)))
    (lambda (widget key state)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.type e) KeyPress)
	(set! (.window e) window)
	(set! (.display e) dpy)
	(set! (.root e) (RootWindow dpy (DefaultScreen dpy)))
	(set! (.x e) 0)
	(set! (.y e) 0)
	(set! (.x_root e) 0)
	(set! (.y_root e) 0)
	(set! (.keycode e) (XKeysymToKeycode dpy (list 'KeySym key)))
	(set! (.state e) state)
	(set! (.time e) cast-current-time)
	(set! (.same_screen e) #t)
	(set! (.subwindow e) (list 'Window None))
	(let ((err (XSendEvent dpy window #f KeyPressMask e)))
	  (if (not (= err 0))
	      (begin
		(set! (.time e) cast-current-time)
		(set! (.type e) KeyRelease)
		(set! err (XSendEvent dpy window #f KeyReleaseMask e))))
	  (if (= err 0)
	      (display (format #f "[key-event error] " err)))
	  err)))))
    
;;; (key-event (car (channel-widgets)) (char->integer #\a) 4)

(define key-event-with-mouse
  (let ((e (XEvent KeyPress))
	(cast-current-time (list 'Time CurrentTime)))
    (lambda (widget key state x y)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.type e) KeyPress)
	(set! (.window e) window)
	(set! (.display e) dpy)
	(set! (.root e) (RootWindow dpy (DefaultScreen dpy)))
	(set! (.x e) x)
	(set! (.y e) y)
	(set! (.x_root e) x)
	(set! (.y_root e) y)
	(set! (.keycode e) (XKeysymToKeycode dpy (list 'KeySym key)))
	(set! (.state e) state)
	(set! (.time e) cast-current-time)
	(set! (.same_screen e) #t)
	(set! (.subwindow e) (list 'Window None))
	(let ((err (XSendEvent dpy window #f KeyPressMask e)))
	  (if (not (= err 0))
	      (begin
		(set! (.time e) cast-current-time)
		(set! (.type e) KeyRelease)
		(set! err (XSendEvent dpy window #f KeyReleaseMask e))))
	  (if (= err 0)
	      (display (format #f "[key-event error] " err)))
	  err)))))

(define resize-event
  (let ((e (XEvent ResizeRequest)))
    (lambda (widget width height)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.window e) window)
	(set! (.display e) dpy)
	(set! (.width e) width)
	(set! (.height e) height)
	(XSendEvent dpy window #f ResizeRedirectMask e)))))

(define enter-event
  (let ((e (XEvent EnterNotify)))
    (lambda (widget)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.window e) window)
	(set! (.display e) dpy)
	(XSendEvent dpy window #f EnterWindowMask e)))))

(define leave-event
  (let ((e (XEvent LeaveNotify)))
    (lambda (widget)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.window e) window)
	(set! (.display e) dpy)
	(XSendEvent dpy window #f LeaveWindowMask e)))))

(define expose-event
  (let ((e (XEvent Expose)))
    (lambda (widget x y width height)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.window e) window)
	(set! (.display e) dpy)
	(set! (.width e) width)
	(set! (.height e) height)
	(set! (.x e) x)
	(set! (.y e) y)
	(set! (.count e) 0)
	(XSendEvent dpy window #f ExposureMask e)))))

(define click-event
  (let ((e (XEvent ButtonPress)))
    (lambda (widget button state x y)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.type e) ButtonPress)
	(set! (.window e) window)
	(set! (.display e) dpy)
	(set! (.root e) (RootWindow dpy (DefaultScreen dpy)))
	(set! (.x e) x)
	(set! (.y e) y)
	(set! (.x_root e) 0)
	(set! (.y_root e) 0)
	(set! (.state e) state)
	(set! (.button e) button)
	(set! (.time e) (list 'Time CurrentTime))
	(set! (.same_screen e) #t)
	(set! (.subwindow e) (list 'Window None))
	(let ((err (XSendEvent dpy window #f ButtonPressMask e)))
	  (if (not (= err 0))
	      (begin
		(set! (.time e) (list 'Time CurrentTime))
		(set! (.type e) ButtonRelease)
		(set! err (XSendEvent dpy window #f ButtonReleaseMask e))))
	  (if (= err 0)
	      (display (format #f "[click-event error] " err)))
	  err)))))


(define drag-event
  (let ((e (XEvent ButtonPress))
	(e1 (XEvent MotionNotify)))
    (lambda (widget button state x0 y0 x1 y1)
      (let ((dpy (XtDisplay widget))
	    (window (XtWindow widget)))
	(set! (.type e) ButtonPress)
	(set! (.window e) window)
	(set! (.display e) dpy)
	(set! (.root e) (RootWindow dpy (DefaultScreen dpy)))
	(set! (.x e) x0)
	(set! (.y e) y0)
	(set! (.x_root e) 0)
	(set! (.y_root e) 0)
	(set! (.state e) state)
	(set! (.button e) button)
	(set! (.time e) (list 'Time CurrentTime))
	(set! (.same_screen e) #t)
	(set! (.subwindow e) (list 'Window None))
	(let ((err (XSendEvent dpy window #f ButtonPressMask e)))
	  (if (not (= err 0))
	      (begin
		(set! (.window e1) window)
		(set! (.display e1) dpy)
		(set! (.root e1) (RootWindow dpy (DefaultScreen dpy)))
		;(set! (.x e1) x1)
		;(set! (.y e1) y1)
		(set! (.x_root e1) x0)
		(set! (.y_root e1) y0)
		(set! (.state e1) state)
		(set! (.time e1) (list 'Time (+ 300 CurrentTime)))
		(set! (.same_screen e1) #t)
		(set! (.subwindow e1) (list 'Window None))
		(set! (.is_hint e1) NotifyNormal)
		(let* ((den (if (or (> (abs (- x1 x0)) 10)
				    (> (abs (- y1 y0)) 10))
				10
				2))
		       (xdiff (inexact->exact (floor (/ (- x1 x0) den))))
		       (ydiff (inexact->exact (floor (/ (- y1 y0) den)))))
		  (do ((xn (+ x0 xdiff) (+ xn xdiff))
		       (yn (+ y0 ydiff) (+ yn ydiff))
		       (i 0 (1+ i)))
		      ((= i den))
		    (set! (.x e1) xn)
		    (set! (.y e1) yn)
		    (XSendEvent dpy window #f ButtonMotionMask e1)))
		(set! (.type e) ButtonRelease)
		(set! (.time e) (list 'Time (+ 500 CurrentTime)))
		(set! (.x e) x1)
		(set! (.y e) y1)
		(XSendEvent dpy window #f ButtonReleaseMask e))))))))

(define (select-item wid pos)
  (if (not (XmIsList wid))
      (display (format #f "~A is not a list" (XtName wid)))
      (XmListSelectPos wid (+ pos 1) #t)))

(define* (click-button button #:optional value bits)
  (if (Widget? button)
      (if (XtIsSensitive button)
	  (if (or (XmIsPushButton button)
		  (XmIsPushButtonGadget button))
	      (if (= (XtHasCallbacks button XmNactivateCallback) XtCallbackHasSome)
		  (XtCallCallbacks button XmNactivateCallback 
				   (let ((but (XmPushButtonCallbackStruct)))
				     (set! (.click_count but) 0)
				     (set! (.event but) 
					   (let ((e (XEvent ButtonPress)))
					     (set! (.state e) (or bits 0))
					     e))
				     but))
		  (display (format #f 
				   ";pushbutton ~A has no activate callbacks~%" 
				   (XtName button))))
	      (if (or (XmIsToggleButton button)
		      (XmIsToggleButtonGadget button))
		  (if (= (XtHasCallbacks button XmNvalueChangedCallback) XtCallbackHasSome)
		      (XtCallCallbacks button XmNvalueChangedCallback 
				       (let ((tgl (XmToggleButtonCallbackStruct)))
					 (set! (.set tgl) value)
					 (set! (.event tgl) 
					       (let ((e (XEvent ButtonPress)))
						 (set! (.state e) (or bits 0))
						 e))
					 tgl))
		      (display (format #f 
				       ";togglebutton ~A has no valueChanged callbacks~%" 
				       (XtName button))))
		  (if (XmIsArrowButton button)
		      (if (= (XtHasCallbacks button XmNactivateCallback) XtCallbackHasSome)
			  (XtCallCallbacks button XmNactivateCallback
					   (let ((arr (XmArrowButtonCallbackStruct)))
					     (set! (.click_count arr) 0)
					     (set! (.event arr) 
						   (let ((e (XEvent ButtonPress)))
						     (set! (.state e) (or bits 0))
						     e))
					     arr))
			  (display (format #f 
					   ";arrowbutton ~A has no activate callbacks~%" 
					   (XtName button))))
		      (display (format #f 
				       ";~A (~A) is not a push or toggle button~%" 
				       (XtName button) (XtName (XtParent button)))))))
	  (display (format #f 
			   ";~A is not sensitive~%" 
			   (XtName button))))
      (display (format #f 
		       ";~A is not a widget~%" 
		       button))))

(define (resize-pane wid height)
  (XtUnmanageChild wid)
  (XtVaSetValues wid (list XmNpaneMinimum (if (> height 5) (- height 5) 0)
			   XmNpaneMaximum (+ height 5)))
  (XtManageChild wid)
  (XtVaSetValues wid (list XmNpaneMinimum 5
			   XmNpaneMaximum 1000)))

(define (force-event)
  (let ((app (car (main-widgets)))
	(done #f))
    (do ()
	(done)
      (let ((msk (XtAppPending app)))
	(if (= (logand msk (logior XtIMXEvent XtIMAlternateInput)) 0)
	    (set! done #t)
	    (XtDispatchEvent (XtAppNextEvent app)))))))
	      
(define (take-keyboard-focus wid)
  (if (and (XmIsTraversable wid)
	   (not (= (XmGetVisibility wid) XmVISIBILITY_FULLY_OBSCURED)))
      (XmProcessTraversal wid XmTRAVERSE_CURRENT)))

(define (move-scale scl val)
  (XmScaleSetValue scl val)
  (XtCallCallbacks scl XmNvalueChangedCallback
    (let ((cb (XmScaleCallbackStruct)))
      (set! (.value cb) val)
      (set! (.event cb) (XEvent))
      cb)))


(define (change-prop winat name command)
  (define (find-window dpy top natom)
    (let ((res (XGetWindowProperty dpy top natom 0 1024 #f XA_STRING)))
      (if (and (= (car res) Success) 
	       (not (equal? (cadr res) (list 'Atom None))))
	  top
	  (let ((vals (XQueryTree dpy top)))
	    (if (= (car vals) 0)
		#f
		(call-with-current-continuation
		 (lambda (return)
		   (for-each 
		    (lambda (win)
		      (let ((val (find-window dpy win natom)))
			(if (Window? val)
			    (return val))))
		    (list-ref vals 3)))))))))
  (let* ((dpy (XtDisplay (cadr (main-widgets))))
	 (natom (XInternAtom dpy winat #f))
	 (window (find-window dpy (DefaultRootWindow dpy) natom)))
    (if (Window? window)
	(begin
	  (XChangeProperty dpy window (XInternAtom dpy name #f) XA_STRING 8 PropModeReplace command)
	  (XFlush dpy)
	  command)
	#f)))

(define beep-state
  (make-procedure-with-setter
   (lambda ()
     ;; returns amp pitch duration
     (let ((vals (XGetKeyboardControl (XtDisplay (cadr (main-widgets))))))
       (list (list-ref vals 1) (list-ref vals 2) (list-ref vals 3))))
   (lambda (lst) 
     ; amp pitch dur
     ; (set! (beep-state) (list 100 200 100))
     (XChangeKeyboardControl 
       (XtDisplay (cadr (main-widgets)))
       (logior KBBellPercent KBBellPitch KBBellDuration)
       (cons 0 lst)))))

(define (beep)
  (XBell (XtDisplay (cadr (main-widgets))) 100))

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us