Jump to content
Sign in to follow this  
AM

binary-filter

Recommended Posts

something i've coded...

 

(defun binary-filter (alist bin-list)
  (let ((event-list (cond ((omn-formp alist)
                           (single-events alist))
                          (t alist))))
    (flatten 
     (loop 
       for i in event-list
       for j in bin-list
       when (= j 1)
       collect i
       else append (cond ((omn-formp i)
                          (list (length-invert (car i))))
                         ((lengthp i)
                          (neg! (omn :length (list i)))))))))


(binary-filter '(q -q -q q) '(0 1 0 1))
=> (-1/4 -q -1/4 q)
(binary-filter '(q q q q -q) '(0 1 0 1 1))
=> (-1/4 q -1/4 q -q)
(binary-filter '(c4 d4 e4 f4) '(1 1 0 1))
=> (c4 d4 f4)
(binary-filter '(q c4 mf  d4 e4 e f4 ppp g4 a4 b4) '(1 0 1 1 0 1 1))
=> (q c4 mf -1/4 q e4 mf e f4 ppp -1/8 e a4 ppp e b4 ppp)

 

Share this post


Link to post
Share on other sites

Hi André

Just investigating your function..
Then I've tried a little cosmetic hack to make it more readable, but it did not work out and I don't understand why. What did I overlook?

Thanks!

 

ole

;;; the orginal function 

(defun binary-filter (alist bin-list)
  (let ((event-list (cond ((omn-formp alist)
                           (single-events alist))
                          (t alist))))
    (flatten 
     (loop 
       for i in event-list
       for j in bin-list
       when (= j 1)
       collect i
       else append (cond ((omn-formp i)
                          (list (length-invert (car i))))
                         ((lengthp i)
                          (neg! (omn :length (list i)))))))))





(binary-filter '(q c4 mf  d4 e4 e f4 ppp g4 a4 b4) '(1 0 1 1 0 1 1))
=> (q c4 mf -1/4 q e4 mf e f4 ppp -1/8 e a4 ppp e b4 ppp)




;;;Why is it not working??



(defun foo-rep (n sequence &key omn)
  (maybe-omn-decode omn
   (binary-filter n sequence)))


(foo-rep '(q c4 mf  d4 e4 e f4 ppp g4 a4 b4) '(1 0 1 1 0 1 1) :omn t)
-->(q c4 mf -1/4 q e4 mf e f4 ppp -1/8 e a4 ppp e b4 ppp);??



 

Share this post


Link to post
Share on other sites
(defun binary-filter (alist bin-list &key (omn t))
  (let ((event-list (cond ((omn-formp alist)
                           (single-events alist))
                          (t alist))))
    (flatten 
     (loop 
       for i in event-list
       for j in bin-list
       when (= j 1)
       collect i
       else append
       (maybe-omn-decode
        omn
        (cond ((omn-formp i) (list (length-invert (car i))))
              ((lengthp i)  (neg! (omn :length (list i))))))))))

(binary-filter '(q c4 mf d4 e4 e f4 ppp g4 a4 b4) '(1 0 1 1 0 1 1))
=> (q c4 mf -q q e4 mf e f4 ppp -e e a4 ppp e b4 ppp)

 

Only one type of parameters can be decoded at a time.

Share this post


Link to post
Share on other sites

i found an internal function 🙂

 

(binary-invert '((1 0) (0 0 1)))
=> ((0 1) (1 1 0))

 

 

 

Share this post


Link to post
Share on other sites

how did you found it, it's not documented..?

And it works only for binary lists, right?

Share this post


Link to post
Share on other sites

I wanted to call my own function like that -

"Error: The function binary-invert is predefined by Opusmodus."

 

also:

(binary-invert '(0 8 0 2 2))
=> (1 0 1 0 0)

 

janusz? 😉

 

Share this post


Link to post
Share on other sites

Predefined functions can't be changed otherwise you would break the system.
I will make a doc for the binary-invert function soon.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×