dub a part



Hi Stefan,
I modified my (three-and-a-half-years-old!) script according to your advice:

* no more silent overwriting because a brand new destination part is now created (the user provides only the source part)
* copies the controls as well.

I now want the user to be able to choose the part from a dropbox at the start of the script. Is it now possible ?
Also, I don't know how to access (and copy) the 5 constant controls (Low,Center,High,Negative Center,Negative High). Can you help me with these ?

Finally, I wonder what is the use of the second argument (the one named options) of the bse-script-register function. I always see it set to "" except in one of your script where it is set to "unstable". Is it an only-for-developpers information or has it the ability to change something in the execution of a script ?


(define max-uint 2147483647)
(define (naturals-to n) (
          letrec ((nats (lambda (i acc) (if (zero? i) (cons i acc) (nats (1- i) (cons i acc))))))
          (if (> n 0) (nats (1- n) (list n)) '(0))))
(define all-controls (
          let* ((prefix->symbol (
                     lambda (p) 
                    (lambda (n) (string->symbol (string-append p (number->string n)))))))
              (append 
                '(program pressure pitch-bend velocity fine-tune parameter non-parameter)
                 (map (prefix->symbol "control-") (naturals-to 127))
                 (map (prefix->symbol "continuous-") (naturals-to 31))
            )))
(bse-script-register 'dub-part
                     ""
                     (N_ "/Song/Parts/Dub a part")
                     (N_ "Copies the content of a source part into a fresh new part. "
                         "\n"
                         "The new part is positionned at the beginning of a track "
                         "containing the source part."
                         "\n"
                         "The name for the source part is the usual one, for instance Part-10.")
                     "Jean Legrand"
                     "GNU General Public License"
                     (bse-param-song (N_ "Song"))
                     (bse-param-string (N_ "Source Part") "Part-"))

(define (dub-part song src-name)
        (let* ((song-name (bse-item-get-name song))
               (project   (bse-item-get-project song ))
               (src       (bse-project-find-item project (string-append song-name ":" src-name)))
               (test-1    (if (not (bse-is-part src))   
                          (bse-exit-error 'text1 (_ "Wrong name for source part"))))
               (track     (bse-song-find-any-track-for-part song src))
               (dest      (bse-song-create-part song))
               (notes     (bse-part-list-notes-crossing src 0 max-uint))
               (copy-note (lambda (note)
                                  (bse-part-insert-note-auto dest
                                                             (bse-rec-get note 'tick)
                                                             (bse-rec-get note 'duration)
                                                             (bse-rec-get note 'note)
                                                             (bse-rec-get note 'fine-tune)
                                                             (bse-rec-get note 'velocity))))
               (controls  (apply append 
                                (map (lambda (c) (bse-part-list-controls src 0 max-uint c))
                                     all-controls)))
               (copy-ctrl (lambda (ctrl) 
                                   (bse-part-insert-control dest
                                                            (bse-rec-get ctrl 'tick)
                                                            (bse-rec-get ctrl 'control-type)
                                                            (bse-rec-get ctrl 'value)))))
              (begin
                (bse-item-group-undo song "dubbing-part")
                (bse-track-insert-part track 0 dest)
                (bse-item-set-name dest (string-append src-name "(Copy)"))
                (for-each copy-note notes)
                (for-each copy-ctrl controls)
                (bse-item-ungroup-undo song))))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]