download inf-snd.el
Language: Lisp
License: GPL
Copyright: (C) 2002--2006 Michael Scholz
LOC: 998
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
;;; inf-snd.el -- Inferior Snd Process (Ruby/Guile/Forth)

;; Copyright (C) 2002--2006 Michael Scholz

;; Author: Michael Scholz <scholz-micha@gmx.de>
;; Created: Wed Nov 27 20:52:54 CET 2002
;; Changed: Sun Jan 15 12:10:40 CET 2006
;; Keywords: processes, snd, ruby, guile, forth

;; This file is not part of GNU Emacs.

;; 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
;; USA

;;; Commentary:

;; This file defines a snd-in-a-buffer package built on top of
;; comint-mode.  It includes inferior mode for Snd-Ruby
;; (inf-snd-ruby-mode), Snd-Guile (inf-snd-guile-mode) and Snd-Forth
;; (inf-snd-forth-mode), furthermore a Snd-Ruby mode (snd-ruby-mode),
;; a Snd-Guile mode (snd-guile-mode) and a Snd-Forth mode
;; (snd-forth-mode) for editing source files.  It is tested with
;; Snd-Ruby, Snd-Guile and Snd-Forth 7.18 and GNU Emacs 21.2/22.0.50.

;; Since this mode is built on top of the general command-interpreter-
;; in-a-buffer mode (comint-mode), it shares a common base
;; functionality, and a common set of bindings, with all modes derived
;; from comint mode.  This makes these modes easier to use.  For
;; documentation on the functionality provided by comint-mode, and the
;; hooks available for customizing it, see the file comint.el.

;; A nice feature may be the commands `inf-snd-help' and `snd-help',
;; which shows the description which Snd provides for many functions.
;; With tab-completion in the minibuffer you can scan all functions at
;; a glance.  It should be easy to extent this mode with new commands
;; and key bindings; the example below and the code in this file may
;; show the way.

;; There exist six main modes in this file: the three inferior
;; Snd-process-modes (inf-snd-ruby-mode, inf-snd-guile-mode and
;; inf-snd-forth-mode) and the replacements of ruby-mode
;; (snd-ruby-mode), of scheme-mode (snd-guile-mode) and of gforth-mode
;; (snd-forth-mode).

;; Variables of the inferior Snd-process-modes
;; inf-snd-ruby|guile|forth-mode (defaults):
;;
;; inf-snd-ruby-program-name   "snd-ruby"    Snd-Ruby program name
;; inf-snd-guile-program-name  "snd-guile"   Snd-Guile program name
;; inf-snd-forth-program-name  "snd-forth"   Snd-Forth program name
;; inf-snd-working-directory   "~/"          where Ruby, Guile or Forth scripts reside
;; inf-snd-ruby-mode-hook      nil           to customize inf-snd-ruby-mode
;; inf-snd-guile-mode-hook     nil           to customize inf-snd-guile-mode
;; inf-snd-forth-mode-hook     nil           to customize inf-snd-forth-mode
;; inf-snd-ruby-quit-hook      nil           to reset snd variables before exit
;; inf-snd-guile-quit-hook     nil           to reset snd variables before exit
;; inf-snd-forth-quit-hook     nil           to reset snd variables before exit
;; inf-snd-index-path          "~/"          path to snd-xref.c
;; inf-snd-prompt              ">"           listener prompt

;; Variables of the editing modes snd-ruby|guile|forth-mode
;; (defaults):
;;
;; snd-ruby-mode-hook          nil     	     to customize snd-ruby-mode
;; snd-guile-mode-hook         nil     	     to customize snd-guile-mode
;; snd-forth-mode-hook         nil     	     to customize snd-forth-mode

;; You can start inf-snd-ruby-mode interactive either with prefix-key
;; (C-u M-x run-snd-ruby)--you will be ask for program name and
;; optional arguments--or direct (M-x run-snd-ruby).  In the latter
;; case, variable inf-snd-ruby-program-name should be set correctly.
;; The same usage goes for inf-snd-guile-mode and inf-snd-forth-mode.

;; Example for your .emacs file:
;;
;; (autoload 'run-snd-ruby     "inf-snd" "Start inferior Snd-Ruby process" t)
;; (autoload 'run-snd-guile    "inf-snd" "Start inferior Snd-Guile process" t)
;; (autoload 'run-snd-forth    "inf-snd" "Start inferior Snd-Forth process" t)
;; (autoload 'snd-ruby-mode    "inf-snd" "Load snd-ruby-mode." t)
;; (autoload 'snd-guile-mode   "inf-snd" "Load snd-guile-mode." t)
;; (autoload 'snd-forth-mode   "inf-snd" "Load snd-forth-mode." t)
;;
;; ;; These variables should be set to your needs!
;; (setq inf-snd-ruby-program-name "snd-ruby -notebook")
;; (setq inf-snd-guile-program-name "snd-guile -separate")
;; (setq inf-snd-forth-program-name "snd-forth")
;; (setq inf-snd-working-directory "~/Snd/")
;; (setq inf-snd-index-path "~/Snd/snd/")

;; The hook-variables may be used to set new key bindings and menu
;; entries etc. in your .emacs file, e.g.:
;;
;; (defun snd-sounds ()
;;   (interactive)
;;   (inf-snd-send-string "(sounds)"))
;;
;; (add-hook 'inf-snd-ruby-mode-hook
;; 	  '(lambda ()
;; 	    (define-key (current-local-map) [menu-bar inf-snd-ruby-mode foo]
;; 	      '("Sounds" . snd-sounds))
;; 	    (define-key (current-local-map) "\C-c\C-t" 'snd-sounds)))
;;
;; To edit source code with special key bindings:
;;
;; (add-hook 'snd-ruby-mode-hook
;; 	  '(lambda ()
;;	    (define-key (current-local-map) "\C-co" 'snd-send-buffer)
;; 	    (define-key (current-local-map) "\C-cb" 'snd-send-block)
;; 	    (define-key (current-local-map) "\C-cr" 'snd-send-region)
;; 	    (define-key (current-local-map) "\C-ce" 'snd-send-definition)))
;;
;; (add-hook 'snd-guile-mode-hook
;; 	  '(lambda ()
;;	    (define-key (current-local-map) "\C-co" 'snd-send-buffer)
;; 	    (define-key (current-local-map) "\C-cr" 'snd-send-region)
;; 	    (define-key (current-local-map) "\C-ce" 'snd-send-definition)))
;; 
;; (add-hook 'snd-forth-mode-hook
;; 	  '(lambda ()
;; 	    (define-key (current-local-map) "\C-co" 'snd-send-buffer)
;; 	    (define-key (current-local-map) "\C-cr" 'snd-send-region)
;; 	    (define-key (current-local-map) "\C-ce" 'snd-send-definition)))

;; You can change the mode in a source file by M-x snd-ruby-mode (or
;; snd-guile-mode, snd-forth-mode).  To determine automatically which
;; mode to set, you can decide to use special file-extensions.  One
;; may use file-extension `.rbs' for Snd-Ruby source files and `.cms'
;; for Snd-Guile.
;;
;; (set-default 'auto-mode-alist
;; 	     (append '(("\\.rbs$" . snd-ruby-mode)
;;                     ("\\.cms$" . snd-guile-mode))
;; 		     auto-mode-alist))
;;
;; Or you can use the local mode variable in source files, e.g. by
;; `-*- snd-ruby -*-', `-*- snd-guile -*-' or `-*- snd-forth -*-' in
;; first line.

;; Key bindings for inf-* and snd-*-modes
;; 
;; \e\TAB        snd-completion    symbol completion at point
;; C-h m     	 describe-mode	   describe current major mode

;; Key binding of inf-snd-ruby|guile|forth-mode:
;;
;; C-c C-s   	 inf-snd-run-snd   (Snd-Ruby|Guile|Forth from a dead Snd process buffer)
;; M-C-l 	 inf-snd-load      load script in current working directory
;; C-c C-f   	 inf-snd-file      open view-files-dialog of Snd
;; M-C-p 	 inf-snd-play      play current sound file
;; C-c C-t 	 inf-snd-stop      stop playing all sound files
;; C-c C-i   	 inf-snd-help      help on Snd-function (snd-help)
;; C-u C-c C-i   inf-snd-help-html help on Snd-function (html)
;; C-c C-q   	 inf-snd-quit      send exit to Snd process
;; C-c C-k   	 inf-snd-kill      kill Snd process and buffer

;; Key bindings of snd-ruby|guile|forth-mode editing source
;; files:
;;
;; C-c C-s   	 snd-run-snd
;; M-C-x     	 snd-send-definition
;; C-x C-e   	 snd-send-last-sexp
;; C-c M-e   	 snd-send-definition
;; C-c C-e   	 snd-send-definition-and-go
;; C-c M-r   	 snd-send-region
;; C-c C-r   	 snd-send-region-and-go
;; C-c M-o   	 snd-send-buffer
;; C-c C-o   	 snd-send-buffer-and-go
;; C-c M-b   	 snd-send-block          (Ruby only)
;; C-c C-b   	 snd-send-block-and-go   (Ruby only)
;; C-c C-z   	 snd-switch-to-snd
;; C-c C-l   	 snd-load-file
;; C-u C-c C-l 	 snd-load-file-protected (Ruby only)
;;
;; and in addition:
;; 
;; C-c C-f   	 snd-file    	   open view-files-dialog of Snd
;; C-c C-p   	 snd-play    	   play current sound file
;; C-c C-t   	 snd-stop    	   stop playing all sound files
;; C-c C-i   	 snd-help    	   help on Snd-function (snd-help)
;; C-u C-c C-i   snd-help-html 	   help on Snd-function (html)
;; C-c C-q   	 snd-quit    	   send exit to Snd process
;; C-c C-k   	 snd-kill    	   kill Snd process and buffer

;;; Code:

;;;; The inf-snd-ruby-mode, inf-snd-guile-mode, and inf-snd-forth-mode.

(require 'comint)
(require 'ruby-mode)
(require 'scheme)
(require 'inf-ruby)
(require 'cmuscheme)
(require 'forth-mode "gforth")

(defconst inf-snd-version "15-Jan-2006"
  "Version of inf-snd.el.")

;; snd-ruby
(defvar inf-snd-ruby-buffer "*Snd-Ruby*"
  "Inferior Snd-Ruby process buffer.")

(defvar inf-snd-ruby-buffer-name "Snd-Ruby"
  "Inferior Snd-Ruby process buffer name.")

(defvar inf-snd-ruby-mode-hook nil
  "User hook variable of `inf-snd-ruby-mode'.
Will be called after `comint-mode-hook' and before starting
inferior Snd-Ruby process.")

(defvar inf-snd-ruby-quit-hook nil
  "User hook variable of `inf-snd-ruby-mode'.
Will be called before finishing inferior Snd-Ruby process.")

(defvar inf-snd-ruby-program-name "snd-ruby"
  "*User variable to set Snd-Ruby-program name and optional arguments.")

;; snd-forth
(defvar inf-snd-forth-buffer "*Snd-Forth*"
  "Inferior Snd-Forth process buffer.")

(defvar inf-snd-forth-buffer-name "Snd-Forth"
  "Inferior Snd-Forth process buffer name.")

(defvar inf-snd-forth-mode-hook nil
  "User hook variable of `inf-snd-forth-mode'.
Will be called after `comint-mode-hook' and before starting
inferior Snd-Forth process.")

(defvar inf-snd-forth-quit-hook nil
  "User hook variable of `inf-snd-forth-mode'.
Will be called before finishing inferior Snd-Forth process.")

(defvar inf-snd-forth-program-name "snd-forth"
  "*User variable to set Snd-Forth-program name and optional arguments.")

;; snd-guile
(defvar inf-snd-guile-buffer "*Snd-Guile*"
  "Inferior Snd-Guile process buffer.")

(defvar inf-snd-guile-buffer-name "Snd-Guile"
  "Inferior Snd-Guile process buffer name.")

(defvar inf-snd-guile-mode-hook nil
  "User hook variable of `inf-snd-guile-mode'.
Will be called after `comint-mode-hook' and before starting
inferior Snd-Guile process.")

(defvar inf-snd-guile-quit-hook nil
  "User hook variable of `inf-snd-guile-mode'.
Will be called before finishing inferior Snd-Guile process.")

(defvar inf-snd-guile-program-name "snd-guile"
  "*User variable to set Snd-Guile-program name and optional args.")

;; general
(defvar snd-completions-buffer "*Completions*"
  "Snd completions buffer.")

(defvar inf-snd-prompt ">"
  "*User variable to determine Snd's listener prompt.
Example: (setq inf-snd-prompt \"snd> \")")

(defvar inf-snd-working-directory "~/"
  "*User variable where Emacs will find the Ruby, Forth, or Guile scripts.")

(defvar inf-snd-kind nil
  "Options are 'ruby, 'forth, or 'guile.
Needed to determine which extension language to use.  This variable is
buffer-local.")

(defvar inf-snd-index-path "~/"
  "*User variable to path where snd-xref.c is located.")

(defvar snd-send-eval-file (expand-file-name
			    (concat
			     (user-login-name) "-snd-eval-file.rb") temporary-file-directory)
  "*User variable of `inf-snd-ruby-mode' and `snd-ruby-mode'.
File where the commands will be collected before sending to
inferior Snd process.")

(defvar inf-snd-to-comment-regexp "^\\(Exception\\|undefined\\|([-A-Za-z]+)\\)"
  "*User variable of `inf-snd-ruby-mode'.
Lines with regexp will be prepended by ruby's comment sign and space '# '.")

(defvar inf-snd-ruby-keywords nil
  "Snd keywords providing online help.
\\<inf-snd-ruby-mode-map> Will be used by
`inf-snd-help' (\\[inf-snd-help], \\[universal-argument]
\\[inf-snd-help]) and `snd-help' (\\[snd-help],
\\[universal-argument] \\[snd-help]), taken from
snd/snd-xref.c.  The user variable `inf-snd-index-path' should
point to the correct path where snd-xref.c is located.")

(defvar inf-snd-guile-keywords nil
  "Snd keywords providing online help.
\\<inf-snd-guile-mode-map> Will be used by
`inf-snd-help' (\\[inf-snd-help], \\[universal-argument]
\\[inf-snd-help]) and `snd-help' (\\[snd-help],
\\[universal-argument] \\[snd-help]), taken from
snd/snd-xref.c.  The user variable `inf-snd-index-path' should
point to the correct path where snd-xref.c is located.")

(defvar inf-snd-ruby-keyword-regexp "^  \"\\([A-Za-z0-9$_?!()]+?\\)\"[,}]+?"
  "*User variable to find Snd-Ruby's keywords in snd-xref.c.")

(defvar inf-snd-guile-keyword-regexp "^  \"\\([-A-Za-z0-9*>?!()]+?\\)\"[,}]+?"
  "*User variable to find Snd-Guile's and Snd-Forth's keywords in snd-xref.c.")

(defun inf-snd-set-keywords ()
  "Set the keywords for `inf-snd-help'.
The user variable `inf-snd-index-path' should point to the
correct path of snd-xref.c to create valid keywords."
  (let ((fbuf (find-file-noselect (concat (expand-file-name inf-snd-index-path) "snd-xref.c")))
	(regex (if (eq 'ruby inf-snd-kind)
		   inf-snd-ruby-keyword-regexp
		 inf-snd-guile-keyword-regexp))
	(keys '()))
    (with-current-buffer fbuf
      (goto-char (point-min))
      (setq case-fold-search nil)
      (while (re-search-forward regex nil t)
	(let ((val (match-string 1)))
	  (or (member val keys)
	      (setq keys (cons val keys))))))
    (kill-buffer fbuf)
    keys))

;;; from share/emacs/22.0.50/lisp/thingatpt.el
;;; lisp-complete-symbol (&optional predicate)
(defun snd-completion ()
  "Perform completion on Scheme or Ruby symbol preceding point.
Compare that symbol against the known Snd symbols.
If no characters can be completed, display a list of possible completions.
Repeating the command at that point scrolls the list."
  (interactive)
  (let ((window (get-buffer-window snd-completions-buffer)))
    (if (and (eq last-command this-command)
	     window (window-live-p window) (window-buffer window)
	     (buffer-name (window-buffer window)))
	;; If this command was repeated, and
	;; there's a fresh completion window with a live buffer,
	;; and this command is repeated, scroll that window.
	(with-current-buffer (window-buffer window)
	  (if (pos-visible-in-window-p (point-max) window)
	      (set-window-start window (point-min))
	    (save-selected-window
	      (select-window window)
	      (scroll-up))))
      ;; Do completion.
      (let* ((end (point))
	     (beg (save-excursion
		    (backward-sexp 1)
		    (while (= (char-syntax (following-char)) ?\')
		      (forward-char 1))
		    (point)))
	     (pattern (buffer-substring-no-properties beg end))
	     (key-list (if (eq 'ruby inf-snd-kind) inf-snd-ruby-keywords inf-snd-guile-keywords))
	     (completion (try-completion pattern key-list)))
	(cond ((eq completion t))
	      ((null completion)
	       (message "Can't find completion for \"%s\"" pattern))
	      ((not (string= pattern completion))
	       (delete-region beg end)
	       (insert completion))
	      (t
	       (let ((list (all-completions pattern key-list)))
		 (setq list (sort list 'string<))
		 (with-output-to-temp-buffer snd-completions-buffer
		   (display-completion-list list)))))))))

(defun inf-snd-set-keys (mode name)
  "Set the key bindings and menu entries for MODE.
Menu name is NAME.  You can extend the key bindings and menu entries
here or via hook variables in .emacs file."
  ;; key bindings
  (define-key (current-local-map) "\C-c\C-f" 'inf-snd-file)
  (define-key (current-local-map) "\M-\C-l"  'inf-snd-load)
  (define-key (current-local-map) "\M-\C-p"  'inf-snd-play)
  (define-key (current-local-map) "\C-c\C-s" 'inf-snd-run-snd)
  (define-key (current-local-map) "\C-c\C-t" 'inf-snd-stop)
  (define-key (current-local-map) "\C-c\C-i" 'inf-snd-help)
  (define-key (current-local-map) "\C-c\C-k" 'inf-snd-kill)
  (define-key (current-local-map) "\C-c\C-q" 'inf-snd-quit)
  (define-key (current-local-map) "\e\C-i"   'snd-completion)
  ;; menu entries in reverse order of appearance
  (define-key (current-local-map) [menu-bar mode]
    (cons name (make-sparse-keymap name)))
  (define-key (current-local-map) [menu-bar mode kill]
    '(menu-item "Kill Snd Process and Buffer" inf-snd-kill
		:enable (inf-snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode quit]
    '(menu-item "Send exit to Snd Process" inf-snd-quit
		:enable (inf-snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode start-r]
    '(menu-item "Start Snd-Ruby Process" inf-snd-run-snd
		:enable (not (inf-snd-proc-p))
		:visible (eq 'ruby inf-snd-kind)))
  (define-key (current-local-map) [menu-bar mode start-f]
    '(menu-item "Start Snd-Forth Process" inf-snd-run-snd
		:enable (not (inf-snd-proc-p))
		:visible (eq 'forth inf-snd-kind)))
  (define-key (current-local-map) [menu-bar mode start-g]
    '(menu-item "Start Snd-Guile Process" inf-snd-run-snd
		:enable (not (inf-snd-proc-p))
		:visible (eq 'guile inf-snd-kind)))
  (define-key (current-local-map) [menu-bar mode sep-quit] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode desc]
    '(menu-item "Describe Mode" describe-mode))
  (define-key (current-local-map) [menu-bar mode help-html]
    '(menu-item "Describe Snd Function (html) ..." inf-snd-help-html
		:enable (inf-snd-proc-p)
		:visible (not (eq 'ruby inf-snd-kind))))
  (define-key (current-local-map) [menu-bar mode help]
    '(menu-item "Describe Snd Function (snd-help) ..." inf-snd-help
		:enable (inf-snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-reset] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode stop]
    '(menu-item "Stop Playing" inf-snd-stop
		:enable (inf-snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode play]
    '(menu-item "Start Playing" inf-snd-play
		:enable (inf-snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode file]
    '(menu-item "Open Snd-File Dialog" inf-snd-file
		:enable (inf-snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-play] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode load-r]
    '(menu-item "Load Ruby Script ..." inf-snd-load
		:enable (inf-snd-proc-p)
		:visible (eq 'ruby inf-snd-kind)))
  (define-key (current-local-map) [menu-bar mode load-f]
    '(menu-item "Load Forth Script ..." inf-snd-load
		:enable (inf-snd-proc-p)
		:visible (eq 'forth inf-snd-kind)))
  (define-key (current-local-map) [menu-bar mode load-g]
    '(menu-item "Load Guile Script ..." inf-snd-load
		:enable (inf-snd-proc-p)
		:visible (eq 'guile inf-snd-kind))))
	  
(defun inf-snd-send-string (str &optional no-strip-p)
  "Print STR in buffer and send it to the inferior Snd process.
If NO-STRIP-P is nil, the default, all dashes (-) will be translated
to underlines (_), if `inf-snd-kind' is 'ruby.  If NO-STRIP-P is
non-nil, it won't translate.  See `inf-snd-load' for the latter case."
  (interactive)
  (and (not no-strip-p)
       (eq 'ruby inf-snd-kind)
       (while (string-match "-" str)
	 (setq str (replace-match "_" t nil str))))
  (if (eq 'guile inf-snd-kind)
      (setq str (concat "(" str ")")))
  (with-current-buffer (inf-snd-proc-buffer)
    (insert str)
    (comint-send-input)))

(defun inf-snd-run-snd ()
  "Start inferior Snd-Ruby, Snd-Forth, or Snd-Guile process.
Started from dead Snd process buffer."
  (interactive)
  (cond ((eq 'ruby inf-snd-kind)
	 (run-snd-ruby inf-snd-ruby-program-name))
	((eq 'forth inf-snd-kind)
	 (run-snd-forth inf-snd-forth-program-name))
	(t
	 (run-snd-guile inf-snd-guile-program-name))))

(defun inf-snd-file ()
  "Open Snd's view-files-dialog widget."
  (interactive)
  (inf-snd-send-string "view-files-dialog"))

(defun inf-snd-load (file)
  "Load the required Ruby, Forth, or Guile script.
Asks for FILE interactively in minibuffer."
  (interactive "fLoad Snd Script: ")
  (unless (file-directory-p file)
    (inf-snd-send-string
     (if (eq 'forth inf-snd-kind)
	 (format "include %s" (car (file-expand-wildcards file t)))
       (format "load %S" (car (file-expand-wildcards file t)))) t)))

(defun inf-snd-play ()
  "Play current sound."
  (interactive)
  (inf-snd-send-string "play"))

(defun inf-snd-stop ()
  "Stop playing of all sound files."
  (interactive)
  (inf-snd-send-string "stop-playing"))

(defun inf-snd-help (&optional html-help)
  "Receive a string in minibuffer and show corresponding help.
\\<inf-snd-ruby-mode-map>\\<inf-snd-forth-mode-map>\\<inf-snd-guile-mode-map>
This is done via Snd's function snd_help() or html() if HTML-HELP
is non-nil, i.e. it's called by \\[universal-argument]
\\[inf-snd-help], putting result at the end of the inferior Snd
process buffer.  If point is near a function name in inferior Snd
process buffer, that function will be used as default value in
minibuffer; tab-completion is activated.  `inf-snd-ruby-keywords'
and `inf-snd-guile-keywords' hold the help strings, the user
variable `inf-snd-index-path' should point to the correct path of
snd-xref.c."
  (interactive "P")
  (let ((prompt (format "Snd%s Help: " (if html-help " HTML" "")))
	(default (thing-at-point 'sexp)))
    (if default
	(setq prompt (format "%s(default %s): " prompt default)))
    (let ((str (completing-read prompt
				(if (eq 'ruby inf-snd-kind)
				    inf-snd-ruby-keywords
				  inf-snd-guile-keywords)
				nil nil nil nil default)))
      (unless (string= str "")
	(unless html-help
	  (while (string-match " " str)
	    (setq str (replace-match "" t nil str))))
	(let ((inf-str (if (and html-help
				(not (eq 'forth inf-snd-kind)))
			   (format "(html \"%s\")" str)
			 (cond ((eq 'ruby inf-snd-kind)
				(format "Snd.display(snd_help(\"%s\", true))" str))
			       ((eq 'forth inf-snd-kind)
				(format "\"%s\" #t snd-help" str))
			       (t
				(format "snd-help \"%s\" #t" str))))))
	  (with-current-buffer (inf-snd-proc-buffer)
	    (goto-char (point-max))
	    (if (and (string= (char-to-string (preceding-char)) inf-snd-prompt)
		     (eobp))
		(inf-snd-send-string inf-str t)
	      (beginning-of-line)
	      (kill-region (point) (point-max))
	      (inf-snd-send-string inf-str t)
	      (yank))))))))

(defun inf-snd-help-html ()
  "Start html help."
  (interactive)
  (inf-snd-help t))

(defun inf-snd-quit ()
  "Send exit to inferior Snd process."
  (interactive)
  (cond ((eq 'ruby inf-snd-kind)
	 (run-hooks 'inf-snd-ruby-quit-hook))
	((eq 'forth inf-snd-kind)
	 (run-hooks 'inf-snd-forth-quit-hook))
	(t
	 (run-hooks 'inf-snd-guile-quit-hook)))
  (if (bufferp snd-completions-buffer)
      (kill-buffer snd-completions-buffer))
  (get-buffer-process (inf-snd-proc-buffer))
  (goto-char (point-max))
  (cond ((eq 'ruby inf-snd-kind)
	 (snd-send-invisible "exit(0)"))
	((eq 'forth inf-snd-kind)
	 (snd-send-invisible "0 snd-exit drop"))
	(t
	 (snd-send-invisible "(exit 0)")))
  (and (file-exists-p snd-send-eval-file)
       (delete-file snd-send-eval-file)))

(defun inf-snd-kill ()
  "Kill current inferior Snd process and buffer."
  (interactive)
  (inf-snd-quit)
  (delete-process (get-buffer-process (inf-snd-proc-buffer)))
  (kill-buffer (current-buffer))
  (unless (one-window-p)
    (delete-window (get-buffer-window (inf-snd-proc-buffer)))))

(defun inf-snd-proc-buffer ()
  "Return the current process buffer."
  (cond ((eq 'ruby inf-snd-kind)
	 inf-snd-ruby-buffer)
	((eq 'forth inf-snd-kind)
	 inf-snd-forth-buffer)
	(t
	 inf-snd-guile-buffer)))

(defun inf-snd-proc-p ()
  "Return non-nil if process buffer is available."
  (save-current-buffer
    (comint-check-proc (inf-snd-proc-buffer))))

(defun snd-send-invisible (str &optional no-newline)
  "Send a STR to the process running in the current buffer.
Non-nil NO-NEWLINE means string without carriage return append."
  (let ((proc (get-buffer-process (current-buffer))))
    (cond ((not proc)
	   (error "Current buffer has no process"))
	  ((stringp str)
	   (comint-snapshot-last-prompt)
	   (if no-newline
	       (comint-send-string proc str)
	     (comint-simple-send proc str))))))
  
(defun inf-snd-comint-put-prompt-ruby (string)
  "Look for `inf-snd-to-comment-regexp' in STRING in the current output.
Prepends matching lines with ruby's comment sign and space `# '.
Showing a prompt is forced by run_emacs_eval_hook() in
snd/examp.rb.  This function could be on the so called abnormal
hook with one arg `comint-preoutput-filter-functions'."
  (if (eq 'ruby inf-snd-kind)
      (progn
       (if (string-match "\\(nil\n$\\)" string)
	   (setq string (replace-match "" t nil string 1)))
       (while (string-match inf-snd-to-comment-regexp string)
	 (setq string (replace-match "# \\1" t nil string 1)))))
  string)
  
(defun inf-snd-comint-put-prompt-forth (string)
  "Append `inf-snd-prompt' to STRING.
Furthermore looks for `inf-snd-to-comment-regexp' in STRING in
the current output.  Prepends matching lines with ruby's comment
sign and space `# '.  This function could be on the so called
abnormal hook with one arg `comint-preoutput-filter-functions'."
  (if (eq 'forth inf-snd-kind)
      (if (string-match "\\(nil\n\\)" string)
	  (setq string (replace-match inf-snd-prompt t nil string 1))))
  string)

(defun inf-snd-comint-put-prompt-guile (string)
  "Append `inf-snd-prompt' to STRING.
This function could be on the so called abnormal hook with one
arg `comint-preoutput-filter-functions'."
  (if (eq 'guile inf-snd-kind)
      (concat string inf-snd-prompt)
    string))

  (defun inf-snd-comint-snd-send (proc line)
  "Special function for sending input LINE to PROC.
Variable `comint-input-sender' is set to this function.  Running
Snd-Ruby it is necessary to load snd/examp.rb in your ~/.snd file
which contains run_emacs_eval_hook(line).  Running Snd-Forth
run-emacs-eval-hook is in FTH's C-core.  inf-snd.el uses this
function to evaluate one line or multi-line input (Ruby only)."
  (if (= (length line) 0)
      (if (eq 'guile inf-snd-kind)	;guile-1.7.x discards nil
	  (setq line "#f")
	(setq line "nil")))
  (comint-send-string proc
		      (cond ((eq 'ruby inf-snd-kind)
			     (format "run_emacs_eval_hook(%%(%s))\n" line))
			    ((eq 'forth inf-snd-kind)
			     (format "%S run-emacs-eval-hook\n" (substring-no-properties line)))
			    (t
			     (concat line "\n")))))

(defun inf-snd-get-old-input ()
  "Snarf the whole pointed line."
  (save-excursion
    (end-of-line)
    (let ((end (point)))
      (beginning-of-line)
      (buffer-substring-no-properties (point) end))))

(defun inf-snd-args-to-list (string)
  "Return a list containing the program and optional arguments list.
Argument STRING is the Snd command and optional arguments."
  (let ((where (string-match "[ \t]" string)))
    (cond ((null where) (list string))
	  ((not (= where 0))
	   (cons (substring string 0 where)
		 (inf-snd-args-to-list (substring string (+ 1 where)
						 (length string)))))
	  (t (let ((pos (string-match "[^ \t]" string)))
	       (if (null pos)
		   nil
		 (inf-snd-args-to-list (substring string pos
						 (length string)))))))))

(define-derived-mode inf-snd-ruby-mode comint-mode inf-snd-ruby-buffer-name
  "Inferior mode running Snd-Ruby, derived from `comint-mode'.

Snd is a sound editor created by Bill Schottstaedt
\(bil@ccrma.Stanford.EDU).  You can find it on
ftp://ccrma-ftp.stanford.edu/pub/Lisp/snd-7.tar.gz.

You can type in Ruby commands in inferior Snd process buffer which
will be sent via `comint-send-string' to the inferior Snd process.
The return value will be shown in the process buffer, other output
goes to the listener of Snd.

You should set variable `inf-snd-ruby-program-name' and
`inf-snd-working-directory' in your .emacs file to set the appropriate
program name and optional arguments and to direct Snd to the Ruby
scripts directory, you have.

The hook variables `comint-mode-hook' and
`inf-snd-ruby-mode-hook' will be called in that special order
after calling the inferior Snd process.  You can use them e.g. to
set additional key bindings.  The hook variable
`inf-snd-ruby-quit-hook' will be called before finishing the
inferior Snd process.  You may use it for resetting Snd
variables, e.g. the listener prompt.

\\<inf-snd-ruby-mode-map> Interactive start is possible either by
\\[universal-argument] \\[run-snd-ruby], you will be ask for the Snd
program name, or by \\[run-snd-ruby].  Emacs shows an additional menu
entry ``Snd-Ruby'' in the menu bar.

The following key bindings are defined:
\\{inf-snd-ruby-mode-map}"
  (ruby-mode-variables)
  (add-hook 'comint-preoutput-filter-functions 'inf-snd-comint-put-prompt-ruby nil t)
  (add-hook 'comint-input-filter-functions 'ruby-input-filter nil t)
  (setq comint-get-old-input (function inf-snd-get-old-input))
  (setq comint-input-sender (function inf-snd-comint-snd-send))
  (setq default-directory inf-snd-working-directory)
  (make-local-variable 'inf-snd-prompt)
  (make-local-variable 'inf-snd-kind)
  (setq comint-prompt-regexp (concat "^\\(" inf-snd-prompt "\\)+"))
  (setq inf-snd-kind 'ruby)
  (setq mode-line-process '(":%s"))
  (unless inf-snd-ruby-keywords
    (setq inf-snd-ruby-keywords (inf-snd-set-keywords)))
  (inf-snd-set-keys 'inf-snd-ruby-mode inf-snd-ruby-buffer-name)
  (pop-to-buffer inf-snd-ruby-buffer)
  (goto-char (point-max))
  (run-hooks 'inf-snd-ruby-mode-hook))

(define-derived-mode inf-snd-forth-mode comint-mode inf-snd-forth-buffer-name
  "Inferior mode running Snd-Forth, derived from `comint-mode'.

Snd is a sound editor created by Bill Schottstaedt
\(bil@ccrma.Stanford.EDU).  You can find it on
ftp://ccrma-ftp.stanford.edu/pub/Lisp/snd-7.tar.gz.

You can type in Forth commands in inferior Snd process buffer which
will be sent via `comint-send-string' to the inferior Snd process.
The return value will be shown in the process buffer, other output
goes to the listener of Snd.

You should set variable `inf-snd-forth-program-name' and
`inf-snd-working-directory' in your .emacs file to set the appropriate
program name and optional arguments and to direct Snd to the Forth
scripts directory, you have.

The hook variables `comint-mode-hook' and
`inf-snd-forth-mode-hook' will be called in that special order
after calling the inferior Snd process.  You can use them e.g. to
set additional key bindings.  The hook variable
`inf-snd-forth-quit-hook' will be called before finishing the
inferior Snd process.  You may use it for resetting Snd
variables, e.g. the listener prompt.

\\<inf-snd-forth-mode-map> Interactive start is possible either by
\\[universal-argument] \\[run-snd-forth], you will be ask for the Snd
program name, or by \\[run-snd-forth].  Emacs shows an additional menu
entry ``Snd-Forth'' in the menu bar.

The following key bindings are defined:
\\{inf-snd-forth-mode-map}"
  (add-hook 'comint-preoutput-filter-functions 'inf-snd-comint-put-prompt-forth nil t)
  (setq comint-get-old-input (function inf-snd-get-old-input))
  (setq comint-input-sender (function inf-snd-comint-snd-send))
  (setq default-directory inf-snd-working-directory)
  (make-local-variable 'inf-snd-prompt)
  (make-local-variable 'inf-snd-kind)
  (setq comint-prompt-regexp (concat "^\\(" inf-snd-prompt "\\)+"))
  (setq inf-snd-kind 'forth)
  (setq mode-line-process '(":%s"))
  (unless inf-snd-guile-keywords
    (setq inf-snd-guile-keywords (inf-snd-set-keywords)))
  (inf-snd-set-keys 'inf-snd-forth-mode inf-snd-forth-buffer-name)
  (pop-to-buffer inf-snd-forth-buffer)
  (goto-char (point-max))
  (run-hooks 'inf-snd-forth-mode-hook))

(define-derived-mode inf-snd-guile-mode comint-mode inf-snd-guile-buffer-name
  "Inferior mode running Snd-Guile, derived from `comint-mode'.

Snd is a sound editor created by Bill Schottstaedt
\(bil@ccrma.Stanford.EDU).  You can find it on
ftp://ccrma-ftp.stanford.edu/pub/Lisp/snd-7.tar.gz.

You can type in Guile commands in inferior Snd process buffer which
will be sent via `comint-send-string' to the inferior Snd process.
The return value will be shown in the process buffer, other output
goes to the listener of Snd.

You sould set variable `inf-snd-guile-program-name' and
`inf-snd-working-directory' in your .emacs file to set the appropriate
program name and optional arguments and to direct Snd to the Guile
scripts directory, you have.

The hook variables `comint-mode-hook' and
`inf-snd-guile-mode-hook' will be called in that special order
after calling the inferior Snd process.  You can use them e.g. to
set additional key bindings.  The hook variable
`inf-snd-guile-quit-hook' will be called before finishing the
inferior Snd process.  You may use it for resetting Snd
variables, e.g. the listener prompt.

\\<inf-snd-guile-mode-map> Interactive start is possible either by
\\[universal-argument] \\[run-snd-guile], you will be ask for the Snd
program name, or by \\[run-snd-guile].  Emacs shows an additional menu
entry ``Snd-Guile'' in the menu bar.

The following key bindings are defined:
\\{inf-snd-guile-mode-map}"
  (scheme-mode-variables)
  (add-hook 'comint-preoutput-filter-functions 'inf-snd-comint-put-prompt-guile nil t)
  (add-hook 'comint-input-filter-functions 'scheme-input-filter nil t)
  (setq comint-get-old-input (function scheme-get-old-input))
  (setq comint-input-sender (function inf-snd-comint-snd-send))
  (setq default-directory inf-snd-working-directory)
  (make-local-variable 'inf-snd-prompt)
  (make-local-variable 'inf-snd-kind)
  (setq comint-prompt-regexp (concat "^\\(" inf-snd-prompt "\\)+"))
  (setq inf-snd-kind 'guile)
  (setq mode-line-process '(":%s"))
  (unless inf-snd-guile-keywords
    (setq inf-snd-guile-keywords (inf-snd-set-keywords)))
  (inf-snd-set-keys 'inf-snd-guile-mode inf-snd-guile-buffer-name)
  (pop-to-buffer inf-snd-guile-buffer)
  (goto-char (point-max))
  (run-hooks 'inf-snd-guile-mode-hook))

(defun run-snd-ruby (cmd)
  "Start inferior Snd-Ruby process.
CMD is used for determine which program to run.  If interactively
called, one will be asked for program name to run."
  (interactive (list (if current-prefix-arg
 			 (read-string "Run Snd Ruby: " inf-snd-ruby-program-name)
 		       inf-snd-ruby-program-name)))
  (unless (comint-check-proc inf-snd-ruby-buffer)
    (let ((cmdlist (inf-snd-args-to-list cmd)))
      (setq inf-snd-ruby-program-name cmd)
      (set-buffer (apply 'make-comint inf-snd-ruby-buffer-name (car cmdlist) nil (cdr cmdlist))))
    (inf-snd-ruby-mode)))

(defun run-snd-forth (cmd)
  "Start inferior Snd-Forth process.
CMD is used for determine which program to run.  If interactively
called, one will be asked for program name to run."
  (interactive (list (if current-prefix-arg
 			 (read-string "Run Snd Forth: " inf-snd-forth-program-name)
 		       inf-snd-forth-program-name)))
  (unless (comint-check-proc inf-snd-forth-buffer)
    (let ((cmdlist (inf-snd-args-to-list cmd)))
      (setq inf-snd-forth-program-name cmd)
      (set-buffer (apply 'make-comint inf-snd-forth-buffer-name (car cmdlist) nil (cdr cmdlist))))
    (inf-snd-forth-mode)
    (snd-send-invisible "nil")))

(defun run-snd-guile (cmd)
  "Start inferior Snd-Guile process.
CMD is used for determine which program to run.  If interactively
called, one will be asked for program name to run."
  (interactive (list (if current-prefix-arg
 			 (read-string "Run Snd Guile: " inf-snd-guile-program-name)
 		       inf-snd-guile-program-name)))
  (unless (comint-check-proc inf-snd-guile-buffer)
    (let ((cmdlist (inf-snd-args-to-list cmd)))
      (setq inf-snd-guile-program-name cmd)
      (set-buffer (apply 'make-comint inf-snd-guile-buffer-name (car cmdlist) nil (cdr cmdlist))))
    (inf-snd-guile-mode)
    (snd-send-invisible "#f")))

;;;; The snd-ruby-, snd-guile-, and snd-forth-mode

;;; Commentary:

;; These three modes are derived from ruby-mode, scheme-mode, and
;; forth-mode.  The main changes are the key bindings, which now refer
;; to special Snd-process-buffer-related ones.  I took commands from
;; inf-ruby.el, from cmuscheme.el and from gforth.el and changed them
;; appropriately.

(defvar snd-ruby-buffer-name "Snd/Ruby"
  "Buffer name of `snd-ruby-mode'.")

(defvar snd-forth-buffer-name "Snd/Forth"
  "Buffer name of `snd-forth-mode'.")

(defvar snd-guile-buffer-name "Snd/Guile"
  "Buffer name of `snd-guile-mode'.")

(defvar snd-ruby-mode-hook nil
  "User hook variable.
Called after `ruby-mode-hook' and before starting inferior Snd
process.")

(defvar snd-forth-mode-hook nil
  "User hook variable.
Called after `forth-mode-hook' and before starting inferior Snd
process.")

(defvar snd-guile-mode-hook nil
  "User hook variable.
Called after `scheme-mode-hook' and before starting inferior Snd
process.")

(defvar snd-source-modes '(snd-ruby-mode)
  "Used to determine if a buffer contains Snd source code.
If it's loaded into a buffer that is in one of these major modes, it's
considered a Snd source file by `snd-load-file'.  Used by this command
to determine defaults.  This variable is buffer-local in
`snd-ruby-mode', `snd-forth-mode' and `snd-guile-mode'.")

(defvar snd-inf-kind 'ruby
  "Options are 'ruby, 'forth, and 'guile.
Needed to determine which extension language should be used.
This variable is buffer-local in `snd-ruby-mode',
`snd-forth-mode', and `snd-guile-mode'.")

(defvar snd-prev-l/c-dir/file nil
  "Cache the (directory . file) pair used in the last `snd-load-file'.
Used for determining the default in the next one.")

(define-derived-mode snd-ruby-mode ruby-mode snd-ruby-buffer-name
  "Major mode for editing Snd-Ruby code.

Editing commands are similar to those of `ruby-mode'.

In addition, you can start an inferior Snd process and some
additional commands will be defined for evaluating expressions.
A menu ``Snd/Ruby'' appears in the menu bar.  Entries in this
menu are disabled if no inferior Snd process exist.

You can use the hook variables `ruby-mode-hook' and
`snd-ruby-mode-hook', which will be called in that order.

The current key bindings are:
\\{snd-ruby-mode-map}"
  (make-local-variable 'snd-inf-kind)
  (make-local-variable 'snd-source-modes)
  (setq snd-inf-kind 'ruby)
  (setq snd-source-modes '(snd-ruby-mode))
  (unless inf-snd-ruby-keywords
    (setq inf-snd-ruby-keywords (inf-snd-set-keywords)))
  (snd-set-keys 'snd-ruby-mode snd-ruby-buffer-name)
  (run-hooks 'snd-ruby-mode-hook))

(define-derived-mode snd-forth-mode forth-mode snd-forth-buffer-name
  "Major mode for editing Snd-Forth code.

Editing commands are similar to those of `forth-mode'.

In addition, you can start an inferior Snd process and some
additional commands will be defined for evaluating expressions.
A menu ``Snd/Forth'' appears in the menu bar.  Entries in this
menu are disabled if no inferior Snd process exist.

You can use the hook variables `forth-mode-hook' and
`snd-forth-mode-hook', which will be called in that order.

The current key bindings are:
\\{snd-forth-mode-map}"
  (make-local-variable 'snd-inf-kind)
  (make-local-variable 'snd-source-modes)
  (setq snd-inf-kind 'forth)
  (setq snd-source-modes '(snd-forth-mode))
  (unless inf-snd-guile-keywords
    (setq inf-snd-guile-keywords (inf-snd-set-keywords)))
  (snd-set-keys 'snd-forth-mode snd-forth-buffer-name)
  (run-hooks 'snd-forth-mode-hook))

(define-derived-mode snd-guile-mode scheme-mode snd-guile-buffer-name
  "Major mode for editing Snd-Guile code.

Editing commands are similar to those of `scheme-mode'.

In addition, you can start an inferior Snd process and some
additional commands will be defined for evaluating expressions.
A menu ``Snd/Guile'' appears in the menu bar.  Entries in this
menu are disabled if no inferior Snd process exist.

You can use variables `scheme-mode-hook' and
`snd-guile-mode-hook', which will be called in that order.

The current key bindings are:
\\{snd-guile-mode-map}"
  (make-local-variable 'snd-inf-kind)
  (make-local-variable 'snd-source-modes)
  (setq snd-inf-kind 'guile)
  (setq snd-source-modes '(snd-guile-mode))
  (unless inf-snd-guile-keywords
    (setq inf-snd-guile-keywords (inf-snd-set-keywords)))
  (snd-set-keys 'snd-guile-mode snd-guile-buffer-name)
  (run-hooks 'snd-guile-mode-hook))

(defun snd-send-region (start end)
  "Send the current region to the inferior Snd process.
START and END define the region."
  (interactive "r")
  (if (eq 'ruby snd-inf-kind)
      (progn
	(write-region start end snd-send-eval-file nil 0)
 	(comint-send-string
 	 (snd-proc)
 	 (format "eval(File.open(%S).read, TOPLEVEL_BINDING, \"(emacs-eval-region)\", 1).inspect \
rescue message(\"(emacs-eval-region): %%s (%%s)\\n%%s\", \
$!.message, $!.class, $!.backtrace.join(\"\\n\"))\n"
 		 snd-send-eval-file)))
    (comint-send-region (snd-proc) start end)
    (comint-send-string (snd-proc) "\n")))

(defun snd-send-region-and-go (start end)
  "Send the current region to the inferior Snd process.
Switch to the process buffer.  START and END define the region."
  (interactive "r")
  (snd-send-region start end)
  (snd-switch-to-snd t))

(defun snd-send-definition (&optional cnt)
  "Send the current or CNT definition to the inferior Snd process."
  (interactive "p")
  (save-excursion
    (if (eq 'ruby snd-inf-kind)
	(ruby-beginning-of-defun cnt)
      (beginning-of-defun cnt))
   (let ((beg (point)))
     (if (eq 'ruby snd-inf-kind)
	 (ruby-end-of-defun)
       (end-of-defun))
     (snd-send-region beg (point)))))

(defun snd-send-definition-and-go (&optional cnt)
  "Send the current or CNT definition to the inferior Snd process.
Switch to the process buffer."
  (interactive "p")
  (snd-send-definition cnt)
  (snd-switch-to-snd t))

(defun snd-send-last-sexp (&optional cnt)
  "Send the previous or CNT sexp to the inferior Snd process."
  (interactive "p")
  (snd-send-region (save-excursion
		     (if (eq 'ruby snd-inf-kind)
			 (ruby-backward-sexp cnt)
		       (backward-sexp cnt))
		     (point))
		   (point)))

(defun snd-send-block (&optional cnt)
  "Send the current or CNT block to the inferior Snd-Ruby process.
Works only in `snd-ruby-mode'."
  (interactive "p")
  (save-excursion
    (ruby-beginning-of-block cnt)
    (let ((beg (point)))
      (ruby-end-of-block)
      (end-of-line)
      (snd-send-region beg (point)))))

(defun snd-send-block-and-go (&optional cnt)
  "Send the current or CNT block to the inferior Snd-Ruby process.
Switch to the process buffer.  Works only in `snd-ruby-mode'."
  (interactive "p")
  (snd-send-block cnt)
  (snd-switch-to-snd t))

(defun snd-send-buffer ()
  "Send the current buffer to the inferior Snd process."
  (interactive)
  (snd-send-region (point-min) (point-max)))

(defun snd-send-buffer-and-go ()
  "Send the current buffer to the inferior Snd process.
Switch to the process buffer."
  (interactive)
  (snd-send-buffer)
  (snd-switch-to-snd t))

(defun snd-switch-to-snd (&optional eob-p)
  "If inferior Snd process exists, switch to process buffer, else start Snd.
Non-nil EOB-P positions cursor at end of buffer."
  (interactive "P")
  (let ((buf (snd-proc-buffer)))
    (if (get-buffer buf)
	(pop-to-buffer buf)
      (snd-run-snd))
    (if eob-p
	(push-mark)
      (goto-char (point-max)))))

(defun snd-run-snd ()
  "If inferior Snd process exists, switch to process buffer, else start Snd.
Started from `snd-ruby-mode', `snd-forth-mode' or `snd-guile-mode'."
  (interactive)
  (if (snd-proc-p)
      (progn
	(pop-to-buffer (snd-proc-buffer))
	(push-mark)
	(goto-char (point-max)))
    (cond ((eq 'ruby snd-inf-kind)
	   (run-snd-ruby inf-snd-ruby-program-name))
	  ((eq 'forth snd-inf-kind)
	   (run-snd-forth inf-snd-forth-program-name))
	  (t
	   (run-snd-guile inf-snd-guile-program-name)))))

(defun snd-load-file-protected (filename)
  "Load a Ruby script FILENAME as an anonymous module into the inferior Snd process."
  (interactive (comint-get-source "Load Snd script file: "
				  snd-prev-l/c-dir/file snd-source-modes t))
  (comint-check-source filename)
  (setq snd-prev-l/c-dir/file (cons (file-name-directory filename)
				     (file-name-nondirectory filename)))
  (comint-send-string (snd-proc) (concat "load(\"" filename "\", true)\n")))

(defun snd-load-file (filename)
  "Load a Snd script FILENAME into the inferior Snd process."
  (interactive (comint-get-source "Load Snd script file: "
				  snd-prev-l/c-dir/file snd-source-modes t))
  (comint-check-source filename)
  (setq snd-prev-l/c-dir/file (cons (file-name-directory filename)
				     (file-name-nondirectory filename)))
  (if (eq 'forth snd-inf-kind)
      (comint-send-string (snd-proc) (concat "listener-off include " filename " listener-on\n"))
    (comint-send-string (snd-proc) (concat "(load \"" filename"\"\)\n"))))

(defun snd-save-state ()
  "Synchronize the inferior Snd process with the edit buffer."
  (and (snd-proc)
       (setq inf-snd-kind snd-inf-kind)))
  
(defun snd-file ()
  "Open Snd's view-files-dialog widget."
  (interactive)
  (snd-save-state)
  (inf-snd-file))

(defun snd-play ()
  "Play current sound."
  (interactive)
  (snd-save-state)
  (inf-snd-play))

(defun snd-stop ()
  "Stop playing of all sounds."
  (interactive)
  (snd-save-state)
  (inf-snd-stop))

(defun snd-help (&optional html-help)
  "Receive a string in minibuffer and show corresponding help.
\\<inf-snd-ruby-mode-map>\\<inf-snd-forth-mode-map>\\<inf-snd-guile-mode-map>
This is done via Snd's function snd_help() or html() if HTML-HELP
is non-nil, i.e. it's called by \\[universal-argument]
\\[snd-help], putting result at the end of the inferior Snd
process buffer.  If point is near a function name in inferior Snd
process buffer, that function will be used as default value in
minibuffer; tab-completion is activated.  `inf-snd-ruby-keywords'
and `inf-snd-guile-keywords' hold the help strings, the user
variable `inf-snd-index-path' should point to the correct path of
snd-xref.c."
  (interactive "P")
  (snd-save-state)
  (inf-snd-help html-help))

(defun snd-help-html ()
  "Start html help."
  (interactive)
  (snd-help t))

(defun snd-quit ()
  "Send exit to current inferior Snd process."
  (interactive)
  (snd-save-state)
  (save-excursion
    (snd-switch-to-snd t)
    (inf-snd-quit)))

(defun snd-kill ()
  "Kill current inferior Snd process buffer."
  (interactive)
  (snd-save-state)
  (save-excursion
    (snd-switch-to-snd t)
    (inf-snd-kill)))

(defun snd-proc-buffer ()
  "Return the current process buffer."
  (cond ((eq 'ruby snd-inf-kind)
	 inf-snd-ruby-buffer)
	((eq 'forth snd-inf-kind)
	 inf-snd-forth-buffer)
	(t
	 inf-snd-guile-buffer)))

(defun snd-proc ()
  "Return the process buffer."
  (let* ((buf (snd-proc-buffer))
	 (proc (get-buffer-process (if (eq major-mode
					   (cond ((eq 'ruby snd-inf-kind)
						  'inf-snd-ruby-mode)
						 ((eq 'forth snd-inf-kind)
						  'inf-snd-forth-mode)
						 ('
						  'inf-snd-guile-mode)))
				       (current-buffer)
				     buf))))
    (or proc
	(error "No current process.  See variable inf-snd-ruby|inf-snd-forth|guile-buffer"))))

(defun snd-proc-p ()
  "Return non-nil if no process buffer available."
  (save-current-buffer
    (comint-check-proc (snd-proc-buffer))))

(defun snd-set-keys (mode name)
  "Set the key bindings and menu entries for MODE.
Menu name is NAME.  You can extend the key bindings and menu entries
here or via hook variables in .emacs file."
  (define-key (current-local-map) "\M-\C-x"  'snd-send-definition)
  (define-key (current-local-map) "\C-x\C-e" 'snd-send-last-sexp)
  (define-key (current-local-map) "\C-c\M-e" 'snd-send-definition)
  (define-key (current-local-map) "\C-c\C-e" 'snd-send-definition-and-go)
  (define-key (current-local-map) "\C-c\M-r" 'snd-send-region)
  (define-key (current-local-map) "\C-c\C-r" 'snd-send-region-and-go)
  (define-key (current-local-map) "\C-c\M-o" 'snd-send-buffer)
  (define-key (current-local-map) "\C-c\C-o" 'snd-send-buffer-and-go)
  (define-key (current-local-map) "\C-c\C-z" 'snd-switch-to-snd)
  (define-key (current-local-map) "\C-c\C-s" 'snd-run-snd)
  (define-key (current-local-map) "\C-c\C-l" 'snd-load-file)
  (define-key (current-local-map) "\C-c\C-f" 'snd-file)
  (define-key (current-local-map) "\C-c\C-p" 'snd-play)
  (define-key (current-local-map) "\C-c\C-t" 'snd-stop)
  (define-key (current-local-map) "\C-c\C-i" 'snd-help)
  (define-key (current-local-map) "\C-c\C-k" 'snd-kill)
  (define-key (current-local-map) "\C-c\C-q" 'snd-quit)
  (define-key (current-local-map) "\e\C-i"   'snd-completion)
  (if (eq 'ruby snd-inf-kind)
      (progn
	(define-key (current-local-map) "\C-c\M-b" 'snd-send-block)
	(define-key (current-local-map) "\C-c\C-b" 'snd-send-block-and-go)
	(define-key (current-local-map) "\C-cb"    'undefined) ;overwrite inf-ruby-commands
	(define-key (current-local-map) "\C-cr"    'undefined) ;C-c + single letter key
	(define-key (current-local-map) "\C-ce"    'undefined) ;is reserved for user
	(define-key (current-local-map) "\C-c\C-x" 'undefined) ;key bindings
	(define-key (current-local-map) "\C-c\M-x" 'undefined))
    (define-key (current-local-map) "\C-c\C-c" 'undefined) ;no compile
    (define-key (current-local-map) "\C-c\M-c" 'undefined))
  (define-key (current-local-map) [menu-bar mode]
    (cons name (make-sparse-keymap name)))
  (define-key (current-local-map) [menu-bar mode kill]
    '(menu-item "Kill Snd Process and Buffer" snd-kill
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode quit]
    '(menu-item "Send exit to Snd Process" snd-quit
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-quit] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode desc]
    '(menu-item "Describe Mode" describe-mode))
  (define-key (current-local-map) [menu-bar mode help-html]
    '(menu-item "Describe Snd Function (html) ..." snd-help-html
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode help]
    '(menu-item "Describe Snd Function (snd-help) ..." snd-help
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-desc] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode stop]
    '(menu-item "Stop Playing" snd-stop
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode play]
    '(menu-item "Start Playing" snd-play
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode file]
    '(menu-item "Open Snd-File Dialog" snd-file
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-load] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode start-r]
    '(menu-item "Start Snd-Ruby Process" snd-run-snd
		:enable (not (snd-proc-p))
		:visible (eq 'ruby snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode start-f]
    '(menu-item "Start Snd-Forth Process" snd-run-snd
		:enable (not (snd-proc-p))
		:visible (eq 'forth snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode start-g]
    '(menu-item "Start Snd-Guile Process" snd-run-snd
		:enable (not (snd-proc-p))
		:visible (eq 'guile snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode switch]
    '(menu-item "Switch to Snd Process" snd-switch-to-snd
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-proc] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode block-go]
    '(menu-item "Send Block and Go" snd-send-block-and-go
		:enable (snd-proc-p)
		:visible (eq 'ruby snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode block]
    '(menu-item "Send Block" snd-send-block
		:enable (snd-proc-p)
		:visible (eq 'ruby snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode buffer-go]
    '(menu-item "Send Buffer and Go" snd-send-buffer-and-go
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode buffer]
    '(menu-item "Send Buffer" snd-send-buffer
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode region-go]
    '(menu-item "Send Region and Go" snd-send-region-and-go
		:enable (and (snd-proc-p) mark-active)))
  (define-key (current-local-map) [menu-bar mode region]
    '(menu-item "Send Region" snd-send-region
		:enable (and (snd-proc-p) mark-active)))
  (define-key (current-local-map) [menu-bar mode def-go]
    '(menu-item "Send Definition and Go" snd-send-definition-and-go
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode def]
    '(menu-item "Send Definition" snd-send-definition
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode last-sexp]
    '(menu-item "Send last Sexp" snd-send-last-sexp
		:enable (snd-proc-p)))
  (define-key (current-local-map) [menu-bar mode sep-load] '(menu-item "--"))
  (define-key (current-local-map) [menu-bar mode load-sec]
    '(menu-item "Load Ruby Script (protected) ..." snd-load-file-protected
		:enable (snd-proc-p)
		:visible (eq 'ruby snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode load-r]
    '(menu-item "Load Ruby Script ..." snd-load-file
		:enable (snd-proc-p)
		:visible (eq 'ruby snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode load-f]
    '(menu-item "Load Forth Script ..." snd-load-file
		:enable (snd-proc-p)
		:visible (eq 'forth snd-inf-kind)))
  (define-key (current-local-map) [menu-bar mode load-g]
    '(menu-item "Load Guile Script ..." snd-load-file
		:enable (snd-proc-p)
		:visible (eq 'guile snd-inf-kind))))

(provide 'inf-snd)

;;; inf-snd.el ends here

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