Jump to content

muting every other note


o_e

Recommended Posts

Hi,

 

I want something rather simple, a sort of sieve, how can I achive that?

 

Lets say I have a melody like

(q c4 e d4  e e4  q. f4 e g4 q a4 b4)


and I want to mute every other note, so the result would be:

(q c4 -e e4 -q. e g4 -q b4)

or every third note like:

(q c4 e d4 -e q. f4 e g4 q a4 -q)

and it would be great to have an offset..

 

thanks!

ole

Link to comment
Share on other sites

Hi Ole,

I'm not very into Lisp language so this is just a quick and dirty solution but works for the given example.

;;Original Melody
(setf melo '(q c4 e d4  e e4  q. f4 e g4 q a4 b4))

;;Define Function
(defun skip-notes(original)
  (let ((len (omn :length original)) (pitch (omn :pitch original)))
    (let '(pos (loop for i from 1 to (length len) 
                 when (oddp i)
                 collect i))
      (let '(new-len (flatten (gen-pause (mclist len) :section pos)))
        (let '(new-pitch (gen-swallow new-len pitch))
          (return-from skip-notes (make-omn :pitch new-pitch :length new-len))
        )
      )
    )
  )
)
;;Use it
(skip-notes melo)


I think someone can improve this, hopefully.

Best wishes, 
Yuichi

Link to comment
Share on other sites

Hi Yuichi,

 

Thanks for your efforts!

Unfortunatly the listener gives me a 'no current expression' when I try to evaluate the 'skip-notes' function and I do not find what is wrong at first glance. Maybe you can repost your code using the  '<>' code-brackets in the posting window. Not sure if this helps though.

 

best

 

ole

Link to comment
Share on other sites

  • 2 weeks later...

Dear Ole,

 

I just created something similar for myself. Here the idea is that a binary list expresses whether a note should be kept (value 1) or turned into a rest (value 1). So, you can mute any pattern of notes by creating binary lists with all the tools available for that in Opusmusic.

 

The main function is cut-holes, the rest is just a short demo.

(defun cut-holes (lengths binary-list)
  "Expects a list of lengths and a binary list.
   Every length at a position of a 1 is left untouched,
   while every length at a 0 is turned into a rest.
   NOTE: For now, a flat list is returned, and OMN expressions are not supported."
  (mapcar #'(lambda (l b)
              (if (= b 0)
                (* l -1)
                l))
          (flatten lengths)
          (flatten binary-list)))

(setf pitches (gen-repeat 16 '(c4)))
(setf lengths (span pitches '(1/8)))

(setf melody
      (make-omn
        :length (cut-holes lengths (gen-repeat 16 '(1 0)))
        :pitch pitches))

 

This simple function needs a list of lengths (fractions). If you have already an OMN expression then you can extract the durations with (omn :length melody), e.g., in your  extended version of such a function.

 

Best,

Torsten

Link to comment
Share on other sites

code from another project, but should work in a similar way. take it, modify it, or code it properly :-)

regards

andré

 

;; gen-hoquetus.4
 
https://en.wikipedia.org/wiki/Hocket

;;; andré meier / 27-4-2016
;;; write a instrumentation-list (instrument + techniques + velocity), pitch-list 
;;; and length-list. the gen-hoquetus-function will split the melody 
;;; off... in any possibilities, techniques/articulations/velocities will be added
;;; this is only a function i coded for my actual work... perhaps you could use
;;; it or code it properly :-)
;;; HAVE FUN! regards, andré

(setq instrumentation '(((pno ponte ppp))
                       ((vn pizz p)) 
                       ((vn pizz f) (va ponte f))
                       ((pno tasto ff))
                       ((pno pizz fff))
                       ((vn tasto mf) (pno ord ff) (vc tasto mf) (trp ord pp))
                       ((trp mute pp) (vn ponte mf))))

;; subfunctions
 
(defun generate-events.4 (durations pitches &key (velocity '(mf))
                                    (articulation '(-)) (optional_data 'nil))
  (loop repeat (length durations)
    with cnt-d = 0
    with cnt-rest = 0
    when (> (nth cnt-d durations) 0)
    collect (list (nth cnt-d durations) 
                  (nth cnt-rest pitches) 
                  (nth cnt-rest velocity)
                  (nth cnt-rest articulation) 
                  (nth cnt-rest optional_data))
    and do (incf cnt-rest)
    and do (incf cnt-d)
    else collect (list (nth cnt-d durations) 
                  'nil 
                  'nil
                  'nil 
                  'nil)
    and do (incf cnt-d)))

(generate-events.4 '(1 2 -3 4) '(60 61 62) :optional_data instrumentation)

;;

(defun filtering-color.4 (selected-color event-stream)
  (loop for i in event-stream
    with match = 0
    append (loop for x in (fifth i)             
             when (equal (first x) selected-color)
             do (setq articulation (second x)
                      velocity (third x))
             and do (setq match 1))
    when (and (= match 1)  (> (first i) 0))
    append (list (first i) (second i) velocity articulation)
    else collect (* -1 (abs (first i)))
    do (setq match 0)))

(filtering-color.4 'vn (generate-events.4
                        (gen-length '(1 -100 2 3 4 5) 1/32) '(c4 d4 e4 e5)
                        :optional_data instrumentation))



 
 
;; mainfuction:
 
(defun gen-hoquetus.4 (filtered-instrument &key pitch length  instrument-list)
  (let ((events (generate-events.4 length pitch :optional_data instrument-list)))
    (filtering-color.4 filtered-instrument events)))

(gen-hoquetus.4 'vn :pitch '(c4 d4 e5 f6) :length '(1/32 2/32 3/32 4/32) :instrument-list instrumentation)




;; OMN_EXAMPLE:

(setq pitches (midi-to-pitch '(60 61 62 63 64 65 66 67 68 69 70))) ; only an example
(setq lengths (gen-length '(1 2 3 -4 5 6 5 -4 3 -2 1) 1/16)) ; only an example
(setq instrumentation (loop repeat 10 collect
                        (rnd-pick '(((pno ponte ppp)) ; only an example
                                    ((vn pizz p)) 
                                    ((vn pizz f) (va ponte f))
                                    ((pno tasto ff))
                                    ((pno pizz fff))
                                    ((vn tasto mf) (pno ord ff) (vc tasto mf) (trp ord pp))
                                    ((trp mute pp) (vn ponte mf))))))


(def-score hoquetus.4
           (:key-signature '(c maj)
                           :time-signature '(4 4)
                           :tempo '(120)
                           :layout (bracket-group
                                    (trumpet-layout 'trumpet)
                                    (piano-grand-layout 'piano)
                                    (violin-layout 'violin)
                                    (viola-layout 'viola)
                                    (violoncello-layout 'violoncello)))
  
  (trumpet :omn (gen-hoquetus.4 'trp
                                :pitch pitches
                                :length lengths
                                :instrument-list instrumentation)
           :channel 1)
  
  (piano :omn (gen-hoquetus.4 'pno
                              :pitch pitches
                              :length lengths
                              :instrument-list instrumentation)
         :channel 1)
  
  (violin :omn (gen-hoquetus.4 'vn
                               :pitch pitches
                               :length lengths
                               :instrument-list instrumentation)
          :channel 1)
  
  (viola :omn (gen-hoquetus.4 'va
                              :pitch pitches
                              :length lengths
                              :instrument-list instrumentation)
         :channel 1)
  
  (violoncello :omn (gen-hoquetus.4 'vc
                                    :pitch pitches
                                    :length lengths
                                    :instrument-list instrumentation)
               :channel 1))

 

Link to comment
Share on other sites

Dear Torsten,

 

Thank you very much for your solution. It looks very promising, in a good sense simple.

Unfortunatly, when I tried to eval your "cut-holes" function it throws an error:

Error: ((= b 0) (* l -1) l) can't be destructured against the lambda list (ccl::test true &optional false), because it contains 5 elements, and at most 3 are expected.

and I could not find out whats wrong. What am I missing?

 

ole

Link to comment
Share on other sites

I think I know what the problem was, I can not copy directly from the browser. 'Text Wrangler' shows me lots of otherwise hidden signs that confuses OM and that I have to remove first. Sorry for the noise.

That was probably the same problem with Yuichis Code..

edit: Yes ideed!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy