Work-in-progress repo for ambisonics extensions for OM-SoX
Marlon Schumacher
9 days ago a5c60f014709a1a15b909f08e235fa0fe30fed27
commit | author | age
92c40d 1 ;*********************************************************************
AN 2 ; OM-SoX, (c) 2011-2013 Marlon Schumacher (CIRMMT/McGill University) *
3 ;             http://sourceforge.net/projects/omsox/                 *
4 ;                                                                    *
5 ;  Multichannel Audio Manipulation and Functional Batch Processing.  *
6 ;        DSP based on SoX - (c) C.Bagwell and Contributors           *
7 ;                  http://sox.sourceforge.net/                       *
8 ;*********************************************************************
9 ;
10 ;This program is free software; you can redistribute it and/or
11 ;modify it under the terms of the GNU General Public License
12 ;as published by the Free Software Foundation; either version 2
13 ;of the License, or (at your option) any later version.
14 ;
15 ;See file LICENSE for further informations on licensing terms.
16 ;
17 ;This program is distributed in the hope that it will be useful,
18 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;GNU General Public License for more details.
21 ;
22 ;You should have received a copy of the GNU General Public License
23 ;along with this program; if not, write to the Free Software
24 ;Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,10 USA.
25 ;
26 ;Authors: M. Schumacher
27
28 (in-package :om)
29
30 ; This file contains editors for the sox-input-classes
31
32 (defparameter soxconsole-trackw 100)
33
34
35 ;%%%%%%% Editor for SOX-INPUT %%%%%%%%%%%%%%%%%%%%%
36
37 (defmethod class-has-editor-p ((self sox-input)) t)
38
39 (defclass sox-console-editor (editorview) 
40   ((track-panels :initform nil :accessor track-panels :type list)))
41
42 (defclass sox-track-panel (om-view) 
43   ((sox-object :accessor sox-object :initarg :sox-object :initform nil)
44    (tracknum :accessor tracknum :initarg :tracknum :initform 0)))
45
46 (defmethod get-editor-class ((self sox-input)) 'sox-console-editor)
47
48 (defmethod get-win-ed-size ((self sox-input)) 
49   (om-make-point (+ 2 (* (+ soxconsole-trackw 2) (max 1 (min 32 (length (list! (sound self))))))) 150))
50
51 (defmethod initialize-instance :after ((self sox-console-editor) &rest l)
52    (declare (ignore l))
53    (om-set-bg-color self *om-dark-gray-color*)
54    (initialize-panels self)) ; typo or correct?
55
56 (defmethod initialize-panels ((self sox-console-editor))
57   (om-with-delayed-redraw self
58     (setf (track-panels self)
59           (loop for i from 0 to (1- (length (list! (sound (object self))))) collect
60                 (om-make-view 'sox-track-panel
61                               :tracknum i
62                               :sox-object (object self)
63                               :bg-color *om-light-gray-color*
64                               :position (om-make-point (+ 2 (* i (+ soxconsole-trackw 2))) 2) 
65                               :size (om-make-point soxconsole-trackw (- (h self) 4)))))
66     
67     (apply 'om-add-subviews (cons self (track-panels self)))
68     (let ((size (get-win-ed-size (object self))))
69       (oa::set-not-resizable (window self) (om-point-h size) (om-point-v size))) 
70     ))
71
72 (defmethod update-editor-after-eval ((self sox-console-editor) val)
73   (setf (object self) val)
74   (initialize-panels self))
75
76 (defmethod add-pan-controls ((self sox-track-panel) (object t) posy) nil)
77
78 (defmethod initialize-instance :after ((self sox-track-panel) &rest l)
79   (let ((pos 0) pantxt gaintxt)
80     (setf pos (+ pos 5))
81     (om-add-subviews self (setf pantxt (om-make-dialog-item 'om-static-text
82                                                             (om-make-point 15 pos) 
83                                                             (om-make-point soxconsole-trackw 16)
84                                                             (string+ (pathname-name (nth (tracknum self) (list! (sound (sox-object self)))))
85                                                                      "." (pathname-type (nth (tracknum self) (list! (sound (sox-object self))))))
86                                                             :font *om-default-font1b*
87                                                             )))
88     (setf pos (+ pos 25))    
89     (add-pan-controls self (sox-object self) pos)
90
91     (om-add-subviews self (om-make-view 'graphic-numbox 
92                                         :position (om-make-point 30 pos) 
93                                         :size (om-make-point 45 100)
94                                         :pict (om-load-and-store-picture "fader" 'di)
95                                         :nbpict 77
96                                         :pict-size (om-make-point 31 94)
97                                         :di-action (om-dialog-item-act item
98                                                             (om-set-dialog-item-text gaintxt 
99                                                                                      (format nil "  dB: ~4f" (* (- (value item) 120) 0.5)))
100                                                             (setf (nth (tracknum self) (gains (sox-object self))) (* (- (value item) 120) 0.5))
101                                                             (report-modifications (om-view-container self)))
102                                         :font *om-default-font2*
103                                         :value (+ (* (nth (tracknum self) (gains (sox-object self))) 2) 120)
104                                         :min-val 0
105                                         :max-val 132
106                      ))
107
108         (om-add-subviews self (setf gaintxt (om-make-dialog-item 'om-static-text
109                                              (om-make-point 20 (+ pos 99))
110                                              (om-make-point 60 16)
111                                              (format nil "  dB: ~4f" (nth (tracknum self) (gains (sox-object self))))
112                                              :font *om-default-font1*
113                                              )))
114     ))
115
116 ;%%%%%%% Editor for SOX-PAN %%%%%%%%%%%%%%%
117
118 (defmethod get-win-ed-size ((self sox-pan)) 
119   (om-make-point (+ 2 (* (+ soxconsole-trackw 2) (max 1 (min 32 (length (list! (sound self))))))) 200))
120
121 (defmethod add-pan-controls ((self sox-track-panel) (object sox-pan) posy)
122   (let ((pantxt (om-make-dialog-item 'om-static-text
123                                      (om-make-point 28 (+ posy 148)) 
124                                      (om-make-point 65 16)
125                                      (string+ "pan: " (number-to-string (om-round (panning object) 3)))
126                                      :font *om-default-font1*
127                                      )))
128     (om-add-subviews self pantxt (om-make-view 'graphic-numbox
129                                                :position (om-make-point 40 (+ posy 124))
130                                                :size (om-make-point 26 26) 
131                                                :pict (om-load-and-store-picture "dial" 'di)
132                                                :nbpict 65
133                                                :pict-size (om-make-point 24 24)
134                                                :di-action (om-dialog-item-act item
135                                                             ; perhaps this could be made more efficient by manipulating min-val and max-val rather then as a let statement
136                                                             (let ((val (+ 1 (* (value item) 0.02))))
137                                                               (om-set-dialog-item-text pantxt (format nil "pan: ~3f" val))
138                                                               ;(om-set-dialog-item-text pantxt (string+ "pan: " (number-to-string (om-round val 2))))
139                                                               (setf (panning object) val)
140                                                               (report-modifications (om-view-container self))))
141                                                :font *om-default-font2*
142                                                :value (* 50 (1- (panning object)))
143                                                :min-val 0
144                                                :max-val (max 10 (* 50 (1- (numchannels object))))))
145     ))
146
147
148
149 ;%%%%%%% Editor for SOX-MIX-CONSOLE %%%%%%%%%%%%%%%
150
151 (defmethod get-win-ed-size ((self sox-mix-console)) 
152   (om-make-point (+ 2 (* (+ soxconsole-trackw 2) (max 1 (min 32 (length (list! (sound self))))))) 200))
153
154 (defmethod add-pan-controls ((self sox-track-panel) (object sox-mix-console) posy)
155   (let ((pantxt (om-make-dialog-item 'om-static-text
156                                      (om-make-point 28 (+ posy 148)) 
157                                      (om-make-point 65 16)
158                                      (string+ "pan: " (number-to-string (om-round (nth (tracknum self) (panning object)) 2)))
159                                      :font *om-default-font1*
160                                      )))
161     (om-add-subviews self pantxt (om-make-view 'graphic-numbox
162                                                :position (om-make-point 40 (+ posy 124))
163                                                :size (om-make-point 26 26) 
164                                                :pict (om-load-and-store-picture "dial" 'di)
165                                                :nbpict 65
166                                                :pict-size (om-make-point 24 24)
167                                                :di-action (om-dialog-item-act item
168                                                             ; perhaps this could be made more efficient by manipulating min-val and max-val rather then as a let statement
169                                                             (let ((val (+ 1 (* (value item) 0.02))))
170                                                               (om-set-dialog-item-text pantxt (format nil "pan: ~3f" val))
171                                                               ;(om-set-dialog-item-text pantxt (string+ "pan: " (number-to-string (om-round val 2))))
172                                                               (setf (nth (tracknum self) (panning object)) val)
173                                                               (report-modifications (om-view-container self))))
174                                                :font *om-default-font2*
175                                                :value (* 50 (1- (nth (tracknum self) (panning object))))
176                                                :min-val 0
177                                                :max-val (max 10 (* 50 (1- (numchannels object))))))
178     ))
179
180
181 ;%%%%%%% Editor for SOX-REMIX %%%%%%%%%%%%%%%%%%%%%
182
183 (defclass sox-remix-editor (editorview) 
184   ((channel-panels :initform nil :accessor channel-panels :type list)))
185
186 (defclass sox-channel-panel (om-view) 
187   ((sox-object :accessor sox-object :initarg :sox-object :initform nil)
188    (panel-id :accessor panel-id :initarg :panel-id :initform nil)
189    (channel :accessor channel :initarg :channel :initform nil)
190    (gain :accessor gain :initarg :gain :initform nil)))
191
192 (defmethod get-editor-class ((self sox-remix)) 'sox-remix-editor)
193
194 (defmethod get-win-ed-size ((self sox-remix))
195   (om-make-point  (+ 2 (* 102 (max 1 (min 32 (length (channel-matrix self))))))
196                   (+ 0 (* (+ soxconsole-trackw 2) (max 1 (min 32 (or (list-max 
197                                                                       (loop for item in (channel-matrix self) collect
198                                                                             (length item))) 0)
199                                                               ))
200
201                           ))))
202
203 (defmethod initialize-instance :after ((self sox-remix-editor) &rest l)
204    (declare (ignore l))
205    (om-set-bg-color self *om-dark-gray-color*)
206    (initialize-panels self))
207
208 (defmethod initialize-panels ((self sox-remix-editor))
209   ;(if (sound (object self))
210  (om-with-delayed-redraw self
211    (when (sound (object self))
212       (setf (channel-panels self)
213             (loop for subchannellist in  (channel-matrix (object self))
214                   for subgainlist in (gain-matrix (object self))
215                   for i from 0 to (length (channel-matrix (object self))) collect ; i = y position
216                   
217                   (loop for channel in subchannellist
218                         for gain in subgainlist
219                         for j from 0 to (length subchannellist) collect ; j = x position
220                         
221                         (om-make-view 'sox-channel-panel
222                                       :channel channel ; maybe 'panel-nr' would be less ambiguous here
223                                       :gain gain
224                                       :panel-id (list i j) ; i = rows, j = columns
225                                       :sox-object (object self)
226                                       :bg-color *om-light-gray-color*
227                                       :position (om-make-point (+ 2 (* i (+ soxconsole-trackw 2))) (* j (+ soxconsole-trackw 2)))
228                                     ;(om-make-point (+ 2 (* j (+ soxconsole-trackw 2))) (* i (+ soxconsole-trackw 2)))
229                                       :size (om-make-point soxconsole-trackw 101 )) ;4 (- (h self) 205)
230                         )
231                   )
232             )
233       )
234     (loop for panel in (channel-panels self) do
235           (apply 'om-add-subviews (cons self panel)))
236
237     (let ((size (get-win-ed-size (object self))))
238       (oa::set-not-resizable (window self) (om-point-h size) (om-point-v size)))
239     )
240     ;(om-beep-msg "Please specify a sound to be processed"))
241     )
242
243 (defmethod update-editor-after-eval ((self sox-remix-editor) val)
244   (setf (object self) val)
245   (initialize-panels self))
246
247 (defmethod initialize-instance :after ((self sox-channel-panel) &rest l)
248   (let ((pos 0)
249         label
250         gaintxt)
251
252 #|
253     (setf pos (+ pos 5))
254     (om-add-subviews self (setf label (om-make-dialog-item 'om-static-text
255                                                             (om-make-point 15 pos) 
256                                                             (om-make-point soxconsole-trackw 16) ;16
257                                                             (string+ (pathname-name (sound (sox-object self)))
258                                                                      "." (pathname-type (sound (sox-object self)))
259                                                                      )
260                                                             :font *om-default-font1b*
261                                                             )))
262 |#
263
264     (setf pos (+ pos 5))
265     (om-add-subviews self (setf label (om-make-dialog-item 'om-static-text
266                                                            (om-make-point 20 pos) 
267                                                            (om-make-point soxconsole-trackw 16) ;16
268                                                            (string+ "Channel-" (number-to-string (channel self)))
269                                                            :font *om-default-font1b*
270                                                            )))
271
272     (setf pos (+ pos 30))
273     (om-add-subviews self (om-make-view 'graphic-numbox 
274                                         :position (om-make-point 35 pos) 
275                                         :size (om-make-point 35 35)
276                                         :pict (om-load-and-store-picture "dial" 'di)
277                                         :nbpict 65
278                                         :pict-size (om-make-point 24 24)
279                                         :di-action (om-dialog-item-act item
280                                                      (om-set-dialog-item-text gaintxt 
281                                                                                       ;(format nil "  dB: ~4f" (* (- (value item) 240) 0.25)))
282                                                                               (string+ "  dB: " (number-to-string (om-round (* (value item) 0.5) 2))))
283                                                      (setf (nth (second (panel-id self)) (nth (first (panel-id self)) (gain-matrix (sox-object self)))) (* (value item) 0.5))
284                                                      (report-modifications (om-view-container self)))
285                                         :font *om-default-font2*
286                                         :value (* (gain self) 2)
287                                         :min-val -72
288                                         :max-val 72
289                                         ))
290
291     (om-add-subviews self (setf gaintxt (om-make-dialog-item 'om-static-text
292                                                              (om-make-point 20 80) ;(+ pos 99)
293                                                              (om-make-point 70 16)
294                                                              (format nil "  dB: ~4f" (gain self))
295                                                              :font *om-default-font1*
296                                                              )))
297     
298     ))
299
300
301
302 ;%%%%%%% Editor for SOX-SPLIT %%%%%%%%%%%%%%%%%%%%%%
303
304 (defclass sox-split-console-editor (editorview) 
305   ((track-panels :initform nil :accessor track-panels :type list)))
306
307 (defclass sox-split-panel (om-view) 
308   ((sox-object :accessor sox-object :initarg :sox-object :initform nil)
309    (panel-id :accessor panel-id :initarg :panel-id :initform nil)
310    (channel :accessor channel :initarg :channel :initform nil)
311    (gain :accessor gain :initarg :gain :initform nil)))
312
313 (defmethod get-editor-class ((self sox-split)) 'sox-split-console-editor)
314
315 (defmethod get-win-ed-size ((self sox-split)) 
316   (om-make-point (+ 2 (* (+ soxconsole-trackw 2) (max 1 (min 32 (length (channels self)))))) 150))
317
318 (defmethod initialize-instance :after ((self sox-split-console-editor) &rest l)
319    (declare (ignore l))
320    (om-set-bg-color self *om-dark-gray-color*)
321    (when (sound (object self))
322    (initialize-panels self)))
323
324 (defmethod initialize-panels ((self sox-split-console-editor))
325   (om-with-delayed-redraw self
326     (setf (track-panels self)
327           (loop for channel in (channels (object self)) 
328                 for gain in (gains (object self)) 
329                 for i from 0 to (- (length (channels (object self))) 1) collect       
330                 (om-make-view 'sox-split-panel
331                               :channel channel ; maybe 'panel-nr' would be less ambiguous here
332                               :gain gain
333                               :panel-id i ; i = rows, j = columns
334                               :sox-object (object self)
335                               :bg-color *om-light-gray-color*
336                               :position (om-make-point (+ 2 (* i (+ soxconsole-trackw 2))) 2)
337                                     ;(om-make-point (+ 2 (* j (+ soxconsole-trackw 2))) (* i (+ soxconsole-trackw 2)))
338                               :size (om-make-point soxconsole-trackw (- (h self) 4) )) ;4 (- (h self) 205)
339                 ))
340     (apply 'om-add-subviews (cons self (track-panels self)))
341     (let ((size (get-win-ed-size (object self))))
342       (oa::set-not-resizable (window self) (om-point-h size) (om-point-v size))) 
343     ))
344
345 (defmethod initialize-instance :after ((self sox-split-panel) &rest l)
346   (let ((pos 0) pantxt gaintxt)
347
348     (setf pos (+ pos 5))
349     (om-add-subviews self (setf label (om-make-dialog-item 'om-static-text
350                                                             (om-make-point 20 pos) 
351                                                             (om-make-point soxconsole-trackw 16) ;16
352                                                             (string+ "Channel-" (number-to-string (channel self)))
353                                                             :font *om-default-font1b*
354                                                             )))
355
356     (setf pos (+ pos 25))    
357     (om-add-subviews self (om-make-view 'graphic-numbox 
358                                         :position (om-make-point 30 pos) 
359                                         :size (om-make-point 45 100)
360                                         :pict (om-load-and-store-picture "fader" 'di)
361                                         :nbpict 77
362                                         :pict-size (om-make-point 31 94)
363                                         :di-action (om-dialog-item-act item
364                                                             (om-set-dialog-item-text gaintxt 
365                                                                                      (format nil "  dB: ~4f" (* (- (value item) 120) 0.5)))
366                                                             (setf (nth (panel-id self) (gains (sox-object self))) (* (- (value item) 120) 0.5))
367                                                             (report-modifications (om-view-container self)))
368                                         :font *om-default-font2*
369                                         :value (+ (* (nth (panel-id self) (gains (sox-object self))) 2) 120)
370                                         :min-val 0
371                                         :max-val 132
372                      ))
373
374         (om-add-subviews self (setf gaintxt (om-make-dialog-item 'om-static-text
375                                              (om-make-point 20 (+ pos 99))
376                                              (om-make-point 60 16)
377                                              (format nil "  dB: ~4f" (nth (panel-id self) (gains (sox-object self))))
378                                              :font *om-default-font1*
379                                              )))
380     ))
381
382
383 ;###########################
384 ;; the editor for SOX-RECORD
385
386 (defmethod class-has-editor-p ((self sox-record)) t); not a subclass of sox-input
387
388 (defclass sox-record-console-editor (editorview) 
389   ((track-panels :initform nil :accessor track-panels :type list)))
390
391 (defclass sox-record-channel-panel (om-view) 
392   ((sox-object :accessor sox-object :initarg :sox-object :initform nil)
393    (panel-id :accessor panel-id :initarg :panel-id :initform nil)
394    (channel :accessor channel :initarg :channel :initform nil)
395    (gain :accessor gain :initarg :gain :initform nil)))
396
397 (defmethod get-editor-class ((self sox-record)) 'sox-record-console-editor)
398
399 (defmethod get-win-ed-size ((self sox-record)) 
400   (om-make-point (+ 2 (* (+ soxconsole-trackw 2) (max 1 (min 32 (length (list! (gains self))))))) 100))
401
402 (defmethod initialize-instance :after ((self sox-record-console-editor) &rest l)
403    (declare (ignore l))
404    (om-set-bg-color self *om-dark-gray-color*)
405    (initialize-panels self))
406
407 (defmethod initialize-panels ((self sox-record-console-editor))
408   (om-with-delayed-redraw self
409     (setf (track-panels self)
410           (loop for channel in (channels (object self)) 
411                 for gain in (gains (object self)) 
412                 for i from 0 to (- (length (channels (object self))) 1) collect       
413                 (om-make-view 'sox-record-channel-panel
414                               :channel channel ; maybe 'panel-nr' would be less ambiguous here
415                               :gain gain
416                               :panel-id i ; i = rows, j = columns
417                               :sox-object (object self)
418                               :bg-color *om-light-gray-color*
419                               :position (om-make-point (+ 2 (* i (+ soxconsole-trackw 2))) 2)
420                                     ;(om-make-point (+ 2 (* j (+ soxconsole-trackw 2))) (* i (+ soxconsole-trackw 2)))
421                               :size (om-make-point soxconsole-trackw (- (h self) 4) )) ;4 (- (h self) 205)
422                 ))
423     (apply 'om-add-subviews (cons self (track-panels self)))
424     (let ((size (get-win-ed-size (object self))))
425       (oa::set-not-resizable (window self) (om-point-h size) (om-point-v size))) 
426     ))
427
428 (defmethod initialize-instance :after ((self sox-record-channel-panel) &rest l)
429   (let ((pos 0)
430         label
431         gaintxt)
432
433     (setf pos (+ pos 5))
434     (om-add-subviews self (setf label (om-make-dialog-item 'om-static-text
435                                                            (om-make-point 20 pos) 
436                                                            (om-make-point soxconsole-trackw 16) ;16
437                                                            (string+ "Channel-" (number-to-string (channel self)))
438                                                            :font *om-default-font1b*
439                                                            )))
440
441     (setf pos (+ pos 30))
442     (om-add-subviews self (om-make-view 'graphic-numbox 
443                                         :position (om-make-point 35 pos) 
444                                         :size (om-make-point 35 35)
445                                         :pict (om-load-and-store-picture "dial" 'di)
446                                         :nbpict 65
447                                         :pict-size (om-make-point 24 24)
448                                         :di-action (om-dialog-item-act item
449                                                      (om-set-dialog-item-text gaintxt 
450                                                                                       ;(format nil "  dB: ~4f" (* (- (value item) 240) 0.25)))
451                                                                               (string+ "  dB: " (number-to-string (om-round (* (value item) 0.5) 2))))
452                                                      (setf (nth (panel-id self) (gains (sox-object self))) (* (value item) 0.5))
453                                                      (report-modifications (om-view-container self)))
454                                         :font *om-default-font2*
455                                         :value (* (gain self) 2)
456                                         :min-val -72
457                                         :max-val 72
458                                         ))
459
460     (om-add-subviews self (setf gaintxt (om-make-dialog-item 'om-static-text
461                                                              (om-make-point 20 80) ;(+ pos 99)
462                                                              (om-make-point 70 16)
463                                                              (format nil "  dB: ~4f" (gain self))
464                                                              :font *om-default-font1*
465                                                              )))
466     
467     ))