download edit123.scm
Language: Scheme
LOC: 359
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
; easy edit
;
;version 0.8
;keybindings and functions to make sound editing as easy and convenient
;as pressing 1 2 3
;1 set mark
;2 move mark backward
;3 move mark backward by a fraction
;C-2 move mark forward
;C-3 move mark forward by a fraction
;p set mark fixed and play (important: you have to use this key to finalize the setting of the  start mark )
;f fade
;c crop delete the part before and after the marks
;C-1 toggles start and end status 
; keys have multiple actions assigned depending on the status of the editing process
; p is a customized playfunction
; P (thats Shift P) plays the end of the track and sets the system for setting an end mark
; after having set the start mark pressing P (Shift-P) and then M-2 and M-3 is a good approach to quickly get to the desired area.
; there are some more keybindings, that i commented out.
; you can suit them to your taste.
; for a more in depth description have a look at 
; http://www.users.startplus.de/rawdlite/sound/HOWTO_record_from_radio_to_mp3.html
; enjoy

; tom@tomroth.de

(provide 'snd-edit123.scm)

;channels have to be synced. Uncomment this lines and _all_ your sounds will start synced and combined (i wish there would be mode specific settings)

;(add-hook! after-open-hook
;  (lambda (snd)
;      (if (> (channels snd) 1)
;        (begin
;        (set! (sync snd) (1+ snd)) ; 0 = #f
;         (set! (channel-style snd) channels-combined)
;))

(define status 0)
(define curpos 0)
(define is-playing 0)

(define open-next-file-in-directory
  (let ((last-file-opened #f)
	(current-directory #f)
	(current-sorted-files #f))

    (define (file-from-path curfile)
      (let ((last-slash 0))
	(do ((i 0 (1+ i)))
	    ((= i (string-length curfile)))
	  (if (char=? (string-ref curfile i) #\/)
	      (set! last-slash i)))
	(substring curfile (1+ last-slash))))

    (define (directory-from-path curfile)
      (let ((last-slash 0))
	(do ((i 0 (1+ i)))
	    ((= i (string-length curfile)))
	  (if (char=? (string-ref curfile i) #\/)
	      (set! last-slash i)))
	(substring curfile 0 last-slash)))

    (define (find-next-file)
      ;; find the next file in the sorted list, with wrap-around
      (let ((choose-next (not (string? last-file-opened)))
	    (just-filename (file-from-path last-file-opened)))
	(call-with-current-continuation
	 (lambda (return)
	   (for-each
	    (lambda (file)
	      (if choose-next
		  (return file)
		  (if (string=? file just-filename)
		      (set! choose-next #t))))
	    current-sorted-files)
	   ;; if we get here we wrapped around
	   (car current-sorted-files)))))

    (define (get-current-files dir)
      (set! current-directory dir)
      (set! current-sorted-files (sort (sound-files-in-directory dir) string<?)))

    (define (get-current-directory filename)
      (set! last-file-opened filename)
      (display last-file-opened)
      (let ((new-path (directory-from-path (mus-expand-filename filename))))
	(if (or (not (string? current-directory))
		(not (string=? current-directory new-path)))
	    (get-current-files new-path)))
      #f)

    (lambda ()
      (if (not (member get-current-files (hook->list open-hook)))
	  (add-hook! open-hook get-current-directory))
      (if (and (not (string? last-file-opened))
	       (not (null? (sounds))))
	  (set! last-file-opened (file-name (or (selected-sound)
						(car (sounds))))))
      (if (not current-directory)
	  (if (null? (sounds))
	      (get-current-files (getcwd))
	      (get-current-files (directory-from-path last-file-opened))))
      (if (null? current-sorted-files)
	  (throw 'no-such-file (list "open-next-file-in-directory" current-directory))
	  (let ((next-file (find-next-file)))
	    (if (find-sound next-file)
		(throw 'file-already-open (list "open-next-file-in-directory" next-file))
		(begin
		  (if (not (null? (sounds)))
		      (close-sound (or (selected-sound)  ; not sure this is what you want -- closes current file
				       (car (sounds)))))
		  (open-sound next-file)))))
      #t)))

(define (click-middle-button-to-open-next-file-in-directory)
  (add-hook! mouse-click-hook
	     (lambda (snd chn button state x y axis)
	       (if (= button 2)
		   (open-next-file-in-directory)
		   #f)))) ; else handle it normally

;; or you could bind this (i.e. "(open-next-file-in-directory)") to some key.



(add-hook! after-open-hook
  (lambda (snd)
  (set! status 0)
))

(add-hook! start-playing-hook 
               (lambda (snd)
               (set! is-playing 1)))


 (add-hook! stop-playing-hook 
               (lambda (snd)
               (set! is-playing 0)))

(define (eos )
(set! (cursor) (+ (selection-position) (selection-frames))))

(define (mark-named name)
(select-channel 0)
(set! (mark-name (add-mark (cursor) )) name)
)

(define (goto-named-mark name)
(select-channel 0)
(if (find-mark name)
(set! (cursor) (mark-sample (find-mark name))))
)

(define (delete-named-mark name)
(select-channel 0)
(if (find-mark name)
(delete-mark (find-mark name))))

(define (my-play-selection pos1 pos2)
(stop-playing)
 (make-selection pos1 pos2)
;(set! (x-bounds) 
;    (list (/ (selection-position) (srate))
;          (/ (+ (selection-position) (selection-frames)) (srate))))
(play-selection))

(define (test-mark-forw name  length)
(stop-playing)
(select-channel 0)
(goto-named-mark name)
(make-selection (cursor)  (+ (cursor) length))
(play-selection))

(define (test-mark-backw name  length)
(stop-playing)
(select-channel 0)
(goto-named-mark name)
(make-selection (- (cursor) length) (cursor)  )
(play-selection))



(define (move-start dif length)
(stop-playing)
(select-channel 0)
(goto-named-mark "start")
(delete-named-mark "start")
(set! (cursor) (+ (cursor) dif))
(mark-named "start")
(make-selection (cursor)  (+ (cursor) length))
(play-selection))

(define (move-end dif length)
(stop-playing) 
(select-channel 0)
(goto-named-mark "end")
(delete-named-mark "end")
(set! (cursor) (+ (cursor) dif))
(mark-named "end")
(make-selection (- (cursor) length) (cursor))
(play-selection))



(define (my-play-selection-forw dif length)
(stop-playing)
(select-channel 0)
(set! (cursor) (+ (cursor) dif))
(make-selection (cursor)  (+ (cursor) length))
;(set! (x-bounds) 
;    (list (/ (selection-position) (srate))
;          (/ (+ (selection-position) (selection-frames)) (srate))))
(play-selection))



(define (my-play-selection-backw dif length)
(stop-playing)
(select-channel 0)
(set! (cursor) (- (cursor) dif))
(make-selection (cursor)  (+ (cursor) length))
(play-selection))



(define (forward-selection)
  (if (not (selection?)) (make-selection (cursor)  (+ (cursor) 20000)))
 (if (< (selection-frames) 2000) (make-selection  (- (cursor) 2000) (cursor)))
 ; is cursor inside of selection ?
 (if  (or (< (cursor) (selection-position)) (> (cursor) (+ (selection-position) (selection-frames))))
      (begin
	(make-selection (cursor)  (+ (cursor) (selection-frames)))
	(stop-playing)
        (eos)))
 (if  (and (>= (cursor) (selection-position)) (<= (cursor) (+ (selection-position) (selection-frames))))  
      (begin  
	(stop-playing)
	(eos)
	(make-selection (cursor)  (+ (cursor) (selection-frames)))))
 (play-selection))


(define (backward-selection)
  (if (not (selection?)) (make-selection  (- (cursor) 20000) (cursor)))
  (if (< (selection-frames) 2000) (make-selection  (- (cursor) 2000) (cursor)))
 (if  (or (< (cursor) (selection-position)) (> (cursor) (+ (selection-position) (selection-frames))))
      (begin
	(make-selection (cursor)  (- (cursor) (selection-frames)))
	(stop-playing)
	(set! (cursor) (selection-position))))

 (if  (and (>= (cursor) (selection-position)) (<= (cursor) (+ (selection-position) (selection-frames))))  
      (begin  
	(stop-playing)
	(set! (cursor) (selection-position))))
 (make-selection  (- (cursor) (selection-frames)) (cursor) )
 (play-selection))


(define (mark-start  length)
(select-channel 0)
(if (find-mark "start")
    (delete-named-mark "start")
)
(mark-named "start")
(stop-playing)
(goto-named-mark "start")
(set! status 1)
(make-selection (cursor)  (+ (cursor) length))
(stop-playing)
(key (char->integer #\t) 4)
(play-selection))

(define (mark-end  length)
(select-channel 0)
(if (find-mark "end")
    (delete-named-mark "end")
)
(mark-named "end")
(stop-playing)
(goto-named-mark "end")
(set! status 3)
(make-selection  (- (cursor) length) (cursor) )
(key (char->integer #\t) 4)
(play-selection))

(define (stop-song)
(set! curpos (cursor))
(stop-playing)
(set! (cursor) curpos))

(define (play-song)
(stop-playing)
(select-channel 0)
;(if (eq? status 1)(set! status 2))
;(if (eq? status 3)(set! status 0))
(let ((old-tracking (cursor-follows-play)))
    (set! (cursor-follows-play) #t)
    (add-hook! stop-playing-hook 
               (lambda (snd)
                 (set! (cursor-follows-play) old-tracking))))

(let ((old-channel-style(channel-style (selected-sound))))
(lambda (snd)
    
        (set! (channel-style snd) channels-superimposed)))
    (play (cursor)))

(define (play-end)
(key (char->integer #\>) 1)
(stop-playing)
(key (char->integer #\t) 4)
(set! status 2)
(set! (cursor) (- (cursor) 100000))
(play (cursor))
)

(define (toggle-play)
(lambda () (case is-playing
((1) (stop-playing))
((0) (play))
)))

;double-selection
(define (double-selection)
(set! (cursor) (selection-position))
(make-selection (selection-position) (+ (selection-position)(*  (selection-frames) 2)))
)


;half-selection
(define (half-selection)
(set! (cursor) (selection-position))
(make-selection (selection-position) (+ (selection-position)(/  (selection-frames) 2)))
)

;play-selection



; to lazy to code ;-)

(define (my_crop)
(select-channel 0)
(if (find-mark "start")
(begin
  (key (char->integer #\<) 4)
  (key (char->integer #\ ) 4)
  (key (char->integer #\j) 4)
  (key (char->integer #\d) 0)
))
(if (find-mark "end")
(begin
  (key (char->integer #\j) 4)
  (key (char->integer #\ ) 4)
  (key (char->integer #\>) 5)
  (key (char->integer #\d) 0)
))
  (key (char->integer #\<) 0)
)

(define (my_save)
(save-sound )
(open-next-file-in-directory)
)

(bind-key (char->integer #\d) 0  (lambda ()(delete-selection)))
(bind-key (char->integer #\s) 0  (lambda () ( my_save)))
(bind-key (char->integer #\c) 0  (lambda () (my_crop)))
(bind-key (char->integer #\n) 0  (lambda () (open-next-file-in-directory)))
(bind-key (char->integer #\ ) 8  (lambda () (stop-song)))
(bind-key (char->integer #\c) 0  (lambda () (my_crop)))
(bind-key (char->integer #\x) 0  (lambda () (half-selection)))
(bind-key (char->integer #\X) 1  (lambda () (double-selection)))
(bind-key (char->integer #\y) 0  (lambda () (double-selection)));german version
(bind-key (char->integer #\z) 0  (lambda () (double-selection)));english version
(bind-key (char->integer #\^) 0 (lambda () (my-play-selection-forw 50000 50000)))
(bind-key (char->integer #\^) 4 (lambda () (my-play-selection-backw 50000 50000)))
(bind-key (char->integer #\t) 8 (lambda () (play-selection)))
(bind-key (char->integer #\p) 0 (lambda () (play-song)))
(bind-key (char->integer #\P) 1 (lambda () (play-end)))
(bind-key (char->integer #\p) 8 (lambda () (toggle-play)))
(bind-key (char->integer #\3) 8 (lambda () (forward-selection)))
(bind-key (char->integer #\2) 8 (lambda () (backward-selection)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; status 
;;;;             0 = new
;;;              1 = start is set
;;;              2 = playing
;;;              3 = end is set
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(bind-key #xFFBE 0 (lambda () (case status
				((0) (mark-start 50000))
				((1) (mark-start 50000))
				((2) (mark-end   50000))
				((3) (mark-end   40000))
				(else (set! status 0))
)))


(bind-key (char->integer #\1) 0 (lambda () (case status
				((0) (mark-start 50000))
				((1) (mark-start 50000))
				((2) (mark-end   50000))
				((3) (mark-end   40000))
				(else (set! status 0))
)))

(bind-key (char->integer #\1) 4 (lambda () (case status
				((0) (mark-end 50000))
				((1) (set! status 3))
				((2) (mark-start   50000))
				((3) (set! status 1))
				(else (set! status 0))
)))

(bind-key (char->integer #\1) 8 (lambda () (case status
				((0) (set! status 2))
				((1) (set! status 3))
				((2) (set! status 0))
				((3) (set! status 1))
				(else (set! status 0))
)))

(bind-key (char->integer #\2) 4 (lambda () (case status
				((0) (mark-start 30000))
				((1) (move-start 2000 50000))
				((2) (mark-end   50000))
				((3) (move-end 2000 50000))
				(else (set! status 0))
)))

(bind-key (char->integer #\2) 0 (lambda ()(case status
				((0) (mark-start 30000))
				((1) (move-start -2000 50000))
				((2) (mark-end   50000))
				((3) (move-end -2000 50000))
				(else (set! status 0))
)))

(bind-key (char->integer #\3) 4 (lambda () (case status
				((0) (mark-start 20000))
				((1) (move-start 300 20000))
				((2) (mark-end   20000))
				((3) (move-end 300 20000))
				(else (set! status 0))
)))

(bind-key (char->integer #\3) 0 (lambda () (case status
				((0) (mark-start 20000))
				((1) (move-start -300 20000))
				((2) (mark-end   20000))
				((3) (move-end -300 20000))
				(else (set! status 0))
)))

(bind-key (char->integer #\p) 4 (lambda () (toggle-play)))
(bind-key (char->integer #\p) 0 (lambda () (play-song)))
(bind-key (char->integer #\P) 1 (lambda () (play-end)))

; f fade in or out  selection
(bind-key (char->integer #\f) 0  (lambda()  (case status
				((0) (mark-start 50000))
				((1) (env-selection '(0 0  2 1)))
				((2) (mark-end   50000))
				((3) (env-selection '(0 1  2 0)))
				(else (set! status 0))
))) 

(bind-key (char->integer #\t) 0 (lambda () (case status

				((1) (goto-named-mark "start") (my-play-selection (cursor) (+ (cursor) 100000)))
                                
				
				((3)  (goto-named-mark "end") (my-play-selection (- (cursor) 100000) (cursor)))
;				(else (report-in-minibuffer "status:" (status) ) )
				)
			)
)
;  change status



; + zoom in 
(bind-key (char->integer #\+) 0 (lambda () (set! (x-bounds) 
	                                                           (list (/ (selection-position) (srate))
                                                                              (/ (+ (selection-position) (selection-frames)) (srate))) 
								                                                              (cursor-on-left)
                                                                         )
			)
)

; - zoom out
(bind-key (char->integer #\-) 0 (lambda () (let* ((curs (cursor)))
                                                               (set! (x-bounds) (list 0 5))
                                                               (set! (cursor) curs))
			)
)

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