/[cl-xmms]/cl-xmms/cl-xmms.lisp
ViewVC logotype

Contents of /cl-xmms/cl-xmms.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sun Feb 6 15:57:05 2005 UTC (9 years, 2 months ago) by vgorur
Branch: MAIN
CVS Tags: HEAD
first commit
1 ;;; CL-XMMS --- Common Lisp bindings for libxmms
2 ;;; version 0.1
3 ;;;
4 ;;; (C) 2005 Vikas Gorur P <vikasgp@gmail.com>
5 ;;;
6 ;;; You are granted the rights to distribute and use this software
7 ;;; as governed by the terms of the Lisp Lesser GNU Public License
8 ;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
9
10 ;;; TODO: The API can be made much nicer, e.g., volume,
11 ;;; equalizer, etc., can be made generalized variables.
12
13 ;;; Setup
14
15 (defpackage :xmms
16 (:use :common-lisp)
17 (:export :get-version
18 ; :playlist
19 ; :playlist-add
20 :playlist-delete
21 :play
22 :pause
23 :stop
24 :playing?
25 :paused?
26 :get-playlist-position
27 :set-playlist-position
28 :get-playlist-length
29 :playlist-clear
30 :get-output-time
31 :jump-to-time
32 :get-volume
33 :get-main-volume
34 :get-balance
35 :set-volume
36 :set-main-volume
37 :set-balance
38 :get-skin
39 :set-skin
40 :get-playlist-file
41 :get-playlist-title
42 :get-playlist-time
43 :get-info
44 :main-window-toggle
45 :equalizer-window-toggle
46 :playlist-window-toggle
47 :is-main-window?
48 :is-equalizer-window?
49 :is-playlist-window?
50 :show-preferences-box
51 :toggle-always-on-top
52 :eject
53 :playlist-previous
54 :playlist-next
55 :playlist-add-url-string
56 :running?
57 :toggle-repeat
58 :toggle-shuffle
59 :repeat?
60 :shuffle?
61 ; :get-equalizer
62 :get-equalizer-preamp
63 :get-equalizer-band
64 ; :set-equalizer
65 :set-equalizer-preamp
66 :set-equalizer-band
67 :quit
68 :play-pause
69 :playlist-insert-url-string
70 )
71 (:documentation "CL bindings for libxmms"))
72
73 (in-package :xmms)
74
75 (defparameter *xmms-library-path* #p"/usr/lib/libxmms.so.1")
76 (require :uffi)
77 (uffi:load-foreign-library *xmms-library-path*)
78
79 ;;; Truth conversion utilities
80
81 (defun lisp-truth (truth-value)
82 (if (= truth-value 0)
83 nil
84 t))
85
86 (defun c-truth (truth-value)
87 (if truth-value
88 1
89 0))
90
91 ;;; Bindings
92
93 ;--------------------
94 (uffi:def-function "xmms_remote_playlist"
95 ((session :int)
96 (plist (* :cstring))
97 (num :int)
98 (enqueue :int))
99 :returning :void)
100
101 ;; (defun playlist (plist &optional (enqueue nil) (session 0))
102 ;; (let* ((n (length plist))
103 ;; (cplist (uffi:allocate-foreign-object :cstring n)))
104 ;; (mapcar #'(lambda (item i)
105 ;; (setf (uffi:deref-array cplist :cstring i)
106 ;; (uffi:convert-to-cstring item)))
107 ;; plist
108 ;; (loop for i from 0 to (1- n) collect i))
109 ;; (xmms-remote-playlist session cplist n (c-truth enqueue))
110 ;; (uffi:free-foreign-object cplist)
111 ;; (values)))
112
113 ;--------------------
114 (uffi:def-function "xmms_remote_get_version"
115 ((session :int))
116 :returning :int)
117
118 (defun get-version (&optional (session 0))
119 (xmms-remote-get-version session))
120
121 ;--------------------
122 ;(uffi:def-function "xmms_remote_playlist_add")
123
124 ;--------------------
125 (uffi:def-function "xmms_remote_playlist_delete"
126 ((session :int)
127 (pos :int))
128 :returning :void)
129
130 (defun playlist-delete (pos &optional (session 0))
131 (xmms-remote-playlist-delete session pos)
132 (values))
133
134 ;--------------------
135 (uffi:def-function "xmms_remote_play"
136 ((session :int))
137 :returning :void)
138
139 (defun play (&optional (session 0))
140 (xmms-remote-play session)
141 (values))
142
143 ;--------------------
144 (uffi:def-function "xmms_remote_pause"
145 ((session :int))
146 :returning :void)
147
148 (defun pause (&optional (session 0))
149 (xmms-remote-pause session)
150 (values))
151
152 ;--------------------
153 (uffi:def-function "xmms_remote_stop"
154 ((session :int))
155 :returning :void)
156
157 (defun stop (&optional (session 0))
158 (xmms-remote-stop session)
159 (values))
160
161 ;--------------------
162 (uffi:def-function "xmms_remote_is_playing"
163 ((session :int))
164 :returning :int)
165
166 (defun playing? (&optional (session 0))
167 (lisp-truth (xmms-remote-is-playing session)))
168
169 ;--------------------
170 (uffi:def-function "xmms_remote_is_paused"
171 ((session :int))
172 :returning :int)
173
174 (defun paused? (&optional (session 0))
175 (lisp-truth (xmms-remote-is-paused session)))
176
177 ;--------------------
178 (uffi:def-function "xmms_remote_get_playlist_pos"
179 ((session :int))
180 :returning :int)
181
182 (defun get-playlist-position (&optional (session 0))
183 (xmms-remote-get-playlist-pos session))
184
185 ;--------------------
186 (uffi:def-function "xmms_remote_set_playlist_pos"
187 ((session :int)
188 (pos :int))
189 :returning :void)
190
191 (defun set-playlist-position (pos &optional (session 0))
192 (xmms-remote-set-playlist-pos session pos)
193 (values))
194
195 ;--------------------
196 (uffi:def-function "xmms_remote_get_playlist_length"
197 ((session :int))
198 :returning :int)
199
200 (defun get-playlist-length (&optional (session 0))
201 (xmms-remote-get-playlist-length session))
202
203 ;--------------------
204 (uffi:def-function "xmms_remote_playlist_clear"
205 ((session :int))
206 :returning :void)
207
208 (defun playlist-clear (&optional (session 0))
209 (xmms-remote-playlist-clear session)
210 (values))
211
212 ;--------------------
213 (uffi:def-function "xmms_remote_get_output_time"
214 ((session :int))
215 :returning :int)
216
217 (defun get-output-time (&optional (session 0))
218 (xmms-remote-get-output-time session))
219
220 ;--------------------
221 (uffi:def-function "xmms_remote_jump_to_time"
222 ((session :int)
223 (ms :int))
224 :returning :int)
225
226 (defun jump-to-time (ms &optional (session 0))
227 (xmms-remote-jump-to-time session ms))
228
229 ;--------------------
230 (uffi:def-function "xmms_remote_get_volume"
231 ((session :int)
232 (vl (* :int))
233 (vr (* :int)))
234 :returning :void)
235
236 (defun get-volume (&optional (session 0))
237 (let ((pvl (uffi:allocate-foreign-object :int))
238 (pvr (uffi:allocate-foreign-object :int)))
239 (xmms-remote-get-volume session pvl pvr)
240 (let ((vl (uffi:deref-pointer pvl :int))
241 (vr (uffi:deref-pointer pvr :int)))
242 (uffi:free-foreign-object pvl)
243 (uffi:free-foreign-object pvr)
244 (values vl vr))))
245
246 ;--------------------
247 (uffi:def-function "xmms_remote_get_main_volume"
248 ((session :int))
249 :returning :int)
250
251 (defun get-main-volume (&optional (session 0))
252 (xmms-remote-get-main-volume session))
253
254 ;--------------------
255 (uffi:def-function "xmms_remote_get_balance"
256 ((session :int))
257 :returning :int)
258
259 (defun get-balance (&optional (session 0))
260 (xmms-remote-get-balance session))
261
262 ;--------------------
263 (uffi:def-function "xmms_remote_set_volume"
264 ((session :int)
265 (vl (* :int))
266 (vr (* :int)))
267 :returning :void)
268
269 (defun set-volume (vl vr &optional (session 0))
270 (let ((pvl (uffi:allocate-foreign-object :int))
271 (pvr (uffi:allocate-foreign-object :int)))
272 (setf (uffi:deref-pointer pvl :int) vl)
273 (setf (uffi:deref-pointer pvr :int) vr)
274 (xmms-remote-set-volume session pvl pvr)
275 (uffi:free-foreign-object pvl)
276 (uffi:free-foreign-object pvr)
277 (values)))
278
279 ;--------------------
280 (uffi:def-function "xmms_remote_set_main_volume"
281 ((session :int)
282 (v :int))
283 :returning :void)
284
285 (defun set-main-volume (v &optional (session 0))
286 (xmms-remote-set-main-volume session v)
287 (values))
288
289 ;--------------------
290 (uffi:def-function "xmms_remote_set_balance"
291 ((session :int)
292 (b :int))
293 :returning :void)
294
295 (defun set-balance (b &optional (session 0))
296 (xmms-remote-set-balance session b)
297 (values))
298
299 ;--------------------
300 (uffi:def-function "xmms_remote_get_skin"
301 ((session :int))
302 :returning :cstring)
303
304 (defun get-skin (&optional (session 0))
305 (uffi:convert-from-cstring (xmms-remote-get-skin session)))
306
307 ;--------------------
308 (uffi:def-function "xmms_remote_set_skin"
309 ((session :int)
310 (skinfile :cstring))
311 :returning :void)
312
313 (defun set-skin (skinfile &optional (session 0))
314 (uffi:with-cstring (cskinfile skinfile)
315 (xmms-remote-set-skin session cskinfile)
316 (values)))
317
318 ;--------------------
319 (uffi:def-function "xmms_remote_get_playlist_file"
320 ((session :int)
321 (pos :int))
322 :returning :cstring)
323
324 (defun get-playlist-file (pos &optional (session 0))
325 (uffi:convert-from-cstring (xmms-remote-get-playlist-file session pos)))
326
327 ;--------------------
328 (uffi:def-function "xmms_remote_get_playlist_title"
329 ((session :int)
330 (pos :int))
331 :returning :cstring)
332
333 (defun get-playlist-title (pos &optional (session 0))
334 (uffi:convert-from-cstring (xmms-remote-get-playlist-title pos session)))
335
336 ;--------------------
337 (uffi:def-function "xmms_remote_get_playlist_time"
338 ((session :int)
339 (pos :int))
340 :returning :int)
341
342 (defun get-playlist-time (pos &optional (session 0))
343 (xmms-remote-get-playlist-time session pos))
344
345 ;--------------------
346 (uffi:def-function "xmms_remote_get_info"
347 ((session :int)
348 (rate (* :int))
349 (freq (* :int))
350 (nch (* :int)))
351 :returning :void)
352
353 (defun get-info (&optional (session 0))
354 (let ((prate (uffi:allocate-foreign-object :int))
355 (pfreq (uffi:allocate-foreign-object :int))
356 (pnch (uffi:allocate-foreign-object :int)))
357 (xmms-remote-get-info session prate pfreq pnch)
358 (let ((rate (uffi:deref-pointer prate :int))
359 (freq (uffi:deref-pointer pfreq :int))
360 (nch (uffi:deref-pointer pnch :int)))
361 (uffi:free-foreign-object prate)
362 (uffi:free-foreign-object pfreq)
363 (uffi:free-foreign-object pnch)
364 (values rate freq nch))))
365
366 ;--------------------
367 (uffi:def-function "xmms_remote_main_win_toggle"
368 ((session :int)
369 (show :int))
370 :returning :void)
371
372 (defun main-window-toggle (show &optional (session 0))
373 (xmms-remote-main-win-toggle session (c-truth show))
374 (values))
375
376 ;--------------------
377 (uffi:def-function "xmms_remote_eq_win_toggle"
378 ((session :int)
379 (show :int))
380 :returning :void)
381
382 (defun equalizer-window-toggle (show &optional (session 0))
383 (xmms-remote-eq-win-toggle session (c-truth show))
384 (values))
385
386 ;--------------------
387 (uffi:def-function "xmms_remote_pl_win_toggle"
388 ((session :int)
389 (show :int))
390 :returning :void)
391
392 (defun playlist-window-toggle (show &optional (session 0))
393 (xmms-remote-pl-win-toggle session (c-truth show))
394 (values))
395
396 ;--------------------
397 (uffi:def-function "xmms_remote_is_main_win"
398 ((session :int))
399 :returning :int)
400
401 (defun is-main-window? (&optional (session 0))
402 (lisp-truth (xmms-remote-is-main-win session)))
403
404 ;--------------------
405 (uffi:def-function "xmms_remote_is_eq_win"
406 ((session :int))
407 :returning :int)
408
409 (defun is-equalizer-window? (&optional (session 0))
410 (lisp-truth (xmms-remote-is-eq-win session)))
411
412 ;--------------------
413 (uffi:def-function "xmms_remote_is_pl_win"
414 ((session :int))
415 :returning :int)
416
417 (defun is-playlist-window? (&optional (session 0))
418 (lisp-truth (xmms-remote-is-pl-win session)))
419
420 ;--------------------
421 (uffi:def-function "xmms_remote_show_prefs_box"
422 ((session :int))
423 :returning :void)
424
425 (defun show-preferences-box (&optional (session 0))
426 (xmms-remote-show-prefs-box session)
427 (values))
428
429 ;--------------------
430 (uffi:def-function "xmms_remote_toggle_aot"
431 ((session :int)
432 (ontop :int))
433 :returning :void)
434
435 (defun toggle-always-on-top (on-top &optional (session 0))
436 (xmms-remote-toggle-aot session (c-truth on-top)))
437
438 ;--------------------
439 (uffi:def-function "xmms_remote_eject"
440 ((session :int))
441 :returning :void)
442
443 (defun eject (&optional (session 0))
444 (xmms-remote-eject session)
445 (values))
446
447 ;--------------------
448 (uffi:def-function "xmms_remote_playlist_prev"
449 ((session :int))
450 :returning :void)
451
452 (defun playlist-previous (&optional (session 0))
453 (xmms-remote-playlist-prev session)
454 (values))
455
456 ;--------------------
457 (uffi:def-function "xmms_remote_playlist_next"
458 ((session :int))
459 :returning :void)
460
461 (defun playlist-next (&optional (session 0))
462 (xmms-remote-playlist-next session)
463 (values))
464
465 ;--------------------
466 (uffi:def-function "xmms_remote_playlist_add_url_string"
467 ((session :int)
468 (string :cstring))
469 :returning :void)
470
471 (defun playlist-add-url-string (string &optional (session 0))
472 (uffi:with-cstring (cstring string)
473 (xmms-remote-playlist-add-url-string session cstring)
474 (values)))
475
476 ;--------------------
477 (uffi:def-function "xmms_remote_is_running"
478 ((session :int))
479 :returning :int)
480
481 (defun running? (&optional (session 0))
482 (lisp-truth (xmms-remote-is-running session)))
483
484 ;--------------------
485 (uffi:def-function "xmms_remote_toggle_repeat"
486 ((session :int))
487 :returning :void)
488
489 (defun toggle-repeat (&optional (session 0))
490 (xmms-remote-toggle-repeat session)
491 (values))
492
493 ;--------------------
494 (uffi:def-function "xmms_remote_toggle_shuffle"
495 ((session :int))
496 :returning :void)
497
498 (defun toggle-shuffle (&optional (session 0))
499 (xmms-remote-toggle-shuffle session)
500 (values))
501
502 ;--------------------
503 (uffi:def-function "xmms_remote_is_repeat"
504 ((session :int))
505 :returning :int)
506
507 (defun repeat? (&optional (session 0))
508 (lisp-truth (xmms-remote-is-repeat session)))
509
510 ;--------------------
511 (uffi:def-function "xmms_remote_is_shuffle"
512 ((session :int))
513 :returning :int)
514
515 (defun shuffle? (&optional (session 0))
516 (lisp-truth (xmms-remote-is-shuffle session)))
517
518 ;--------------------
519 (uffi:def-function "xmms_remote_get_eq"
520 ((session :int)
521 (preamp (* :float))
522 (bands (* (* :float))))
523 :returning :void)
524
525 ;; (defun get-equalizer (&optional (session 0))
526 ;; (let* ((ppreamp (uffi:allocate-foreign-object :float))
527 ;; (syms (loop for i from 0 to 9
528 ;; collect (gensym)))
529 ;; (cbands (mapcar #'(lambda (sym)
530 ;; (set sym (uffi:allocate-foreign-object :float))
531 ;; (symbol-value sym))
532 ;; syms))
533 ;; (pbands (uffi:allocate-foreign-object '(* :float) 10)))
534
535 ;; (mapcar #'(lambda (i ptr)
536 ;; (setf (uffi:deref-array pbands '(* :float) i)
537 ;; ptr))
538 ;; (loop for i from 0 to 9)
539 ;; cbands)
540
541 ;; (xmms-remote-get-eq session ppreamp pbands)
542 ;; (let ((preamp (uffi:deref-pointer ppreamp :float))
543 ;; (bands (mapcar #'(lambda (i)
544 ;; (uffi:deref-array cbands :float i))
545 ;; (loop for i from 0 to 9 collect i))))
546 ;; (values preamp bands))))
547
548 ;--------------------
549 (uffi:def-function "xmms_remote_get_eq_preamp"
550 ((session :int))
551 :returning :float)
552
553 (defun get-equalizer-preamp (&optional (session 0))
554 (xmms-remote-get-eq-preamp session))
555
556 ;--------------------
557 (uffi:def-function "xmms_remote_get_eq_band"
558 ((session :int)
559 (band :int))
560 :returning :float)
561
562 (defun get-equalizer-band (band &optional (session 0))
563 (xmms-remote-get-eq-band session band))
564
565 ;--------------------
566 (uffi:def-function "xmms_remote_set_eq"
567 ((session :int)
568 (preamp :float)
569 (bands (* :float)))
570 :returning :void)
571
572 ;--------------------
573 (uffi:def-function "xmms_remote_set_eq_preamp"
574 ((session :int)
575 (preamp :float))
576 :returning :void)
577
578 (defun set-equalizer-preamp (preamp &optional (session 0))
579 (xmms-remote-set-eq-preamp session preamp)
580 (values))
581
582 ;--------------------
583 (uffi:def-function "xmms_remote_set_eq_band"
584 ((session :int)
585 (band :float))
586 :returning :void)
587
588 (defun set-equalizer-band (band &optional (session 0))
589 (xmms-remote-set-eq-band session band)
590 (values))
591
592 ;--------------------
593 (uffi:def-function "xmms_remote_quit"
594 ((session :int))
595 :returning :void)
596
597 (defun quit (&optional (session 0))
598 (xmms-remote-quit session)
599 (values))
600
601 ;--------------------
602 (uffi:def-function "xmms_remote_play_pause"
603 ((session :int))
604 :returning :void)
605
606 (defun play-pause (&optional (session 0))
607 (xmms-remote-play-pause session)
608 (values))
609
610 ;--------------------
611 (uffi:def-function "xmms_remote_playlist_ins_url_string"
612 ((session :int)
613 (string :cstring)
614 (pos :int))
615 :returning :void)
616
617 (defun playlist-insert-url-string (string pos &optional (session 0))
618 (uffi:with-cstring (cstring string)
619 (xmms-remote-playlist-ins-url-string session cstring pos)
620 (values)))
621
622

  ViewVC Help
Powered by ViewVC 1.1.5