Jump to content

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))

 

Link to comment
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

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