Jump to content
Sign in to follow this  
torstenanders

Improving length-rest-series

Recommended Posts

I sometimes like to turn certain notes into rests. The built-in function length-rest-series is great for that, but it only works with lengths, not full OMN expressions. So, I generalised that function. I can do now, e.g., the following. 

 

(setf melody '((s eb6 < leg f5 < leg c5 < leg f5 < leg) (e e6 f - -q)))

(note-rest-series '(1 1) melody :swallow T :section '(0))

; => ((-s - c5 < leg f5 < leg) (e e6 f - -q))

 

Note that in contrast to the original function length-rest-series, the new function note-rest-series does not only support OMN expressions, but also extra arguments like swallow and section.

 

The definition of this function uses length-rest-series and my function edit-omn for writing such generalisations, and it can therefore be rather short. In fact, the documentation string of the function is much longer than the definition itself :)  Please see below.

 

The function edit-omn is part of my tot library, which is available at GitHub. You can see its definition at starting at (currently) line 24 at https://github.com/tanders/tot/blob/master/sources/OMN-utils.lisp

 

Note that with edit-omn you can also easily turn other functions that expect just a single parameter list (e.g., pitches, or lengths) into functions for OMN expressions by automatically preserving the time signature and very conveniently adding standard arguments like flat or section. 

 

Best,

Torsten

 

(defun note-rest-series (positions sequence &key (flat nil) (swallow nil) (section nil))
  "This function is like the Opusmodus built-in length-rest-series, but supports arbitrary OMN expressions as input and additionally the arguments swallow and section.

  Args:
  - positions (list of ints): positions of notes to be turned into rests
  - sequence (list of lengths or OMN expression): music to process
  - flat (Boolean): whether positions count for sublists (nil) or the whole list (T)
  - swallow (Boolean): whether the pitches of notes turned into rests should be shifted to the next note or omitted (swallowed) 
  - section (list of ints): positions of sublists to process. This argument is ignored if flat is T.

  Example:

;;; (setf melody '((s eb6 < leg f5 < leg c5 < leg f5 < leg) (e e6 f - -q)))
;;; (note-rest-series '(1 1) melody :swallow T :section '(0))
"
  (edit-omn :length sequence 
            #'(lambda (ls) (length-rest-series positions ls))
            :swallow swallow
	    :section section
	    :flat flat))

 

Share this post


Link to post
Share on other sites

Dear Stephane,

 

Did you follow the installation instructions at https://github.com/tanders/tot? Have you installed git? Unfortuantely, the installation is a bit complicated, as there are several dependencies. Therefore I explained it at the link above. The package TU is provided by the library ta-utilities, which you can install with git like everything else. 

 

If you want to only have the function you could also go directly to the library ta-utilities at GitHub and copy out the missing functions (https://github.com/tanders/ta-utilities/blob/master/my-utilities.lisp), e.g., remove-properties which then in turn depends on remove-property in the same file. 

 

Best,

Torsten

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  

×