Jump to content

Featured Replies

Posted

 

Given: user defined function: test-foo-lib

in Opusmodus/User Source/Libraries/Def-Unfold-Sets

Opusmodus version: Version 3.0.28766 (3.0.28766)

 

 

(defun test-foo-lib (offset pattern)

(setf pattern-flat (flatten pattern))

(format t "test-foo-lib: ~% offset: ~A ~% pattern: ~A ~% pattern-flat ~A ~%" offset pattern pattern-flat) 

(setf pat-length (omn :length pattern)) ;just for debugging reason

(setf result (pitch-transpose offset pattern-flat))) 

 

;Test

(setf my-pattern '(s bb4 p a4 h. db4 t gs4 mf fs4 c5 b4 q f5 e5))

(setf testresult-1 (test-foo-lib 12 my-pattern)) ;direct call 

 

Listener output: result: just perfect! 

test-foo-lib:

offset: 12 

pattern: (s bb4 p a4 h. db4 t gs4 mf fs4 c5 b4 q f5 e5) 

pattern-flat (s bb4 p a4 h. db4 t gs4 mf fs4 c5 b4 q f5 e5) 

omn

pitch-transpose

(s bb5 p a5 h. cs5 t gs5 mf fs5 c6 b5 q f6 e6)

 

;-----------------------------------------------------------------

Problem:

However if  test-foo-lib is called via 

 

(def-unfold-set dw-om-methods :methods

( :group expansion 

p-exp-patt (:pitch (test-foo-lib 12 x))))

 

with the following call: (in same library file or called from my projects file)

(unfold 'dw-om-methods '(p-exp-patt) my-pattern)

 

 

Listener output: bad result: 

1) pattern becomes a list of list. 

2) only pitch information available! 

Therefore the logical error message: No length information

 

OM 24 > unfold

test-foo-lib:

offset: 12 

pattern: ((bb4 a4 db4 gs4 fs4 c5 b4 f5 e5)) 

pattern-flat (bb4 a4 db4 gs4 fs4 c5 b4 f5 e5) 

 

Error: No length specified before first pitch

1 (abort) Return to top loop level 0.

;-----------------------------------------------------------------

 

What is going on here, what can I do, what is wrong?

Thanks for any hints!

 

Daniel

 

 

 

  • Author

Thank you Stephane!

Yes, :all makes sense. Too bad it does not work: it behaves like I would put :length. 

  :group all
    p-exp-patt (:all (test-foo-lib 12 x))

 

Listener output: 

test-foo-lib:  
 offset: 12 
 pattern:     ((1/16 1/16 3/4 1/32 1/32 1/32 1/32 1/4 1/4)) 
 pattern-flat (1/16 1/16 3/4 1/32 1/32 1/32 1/32 1/4 1/4) 

Error: Cannot coerce 1/16 to type string.

 

P.S. Where are the keys (pitch, length, all etc.) used in def-unfold-set defined ?

 

Daniel

it is on the def-unfold-set documentation:

 

methods a plist containing pairs of the form: (<name><method>),

where <method> is a list of (<omn-type><function>) and where <omn-type>

is NIL (function without type), :all (process on all types),

:length, :pitch, :velocity and :articulation.

  • Author

Oh, of course: sorry I did not pay attention.

 

Now: in def-unfold.set I put the following two function under the group pitch, with both having the same parameter set :

  t-12-dw      (:pitch (pitch-transpose -12 x))   ; A) new, with library function pitch-transpose.
  p-exp-patt (:pitch (test-foo-lib 12 x))             ; B) same function as the original, calling my function

 

A)

I get a good result when called (unfold 'dw-om-methods '(t-12-dw) my-pattern), no loss of length, dynamics:

Listener output:  

OM 23 > unfold
(s bb3 p a3 h. cs3 t gs3 mf fs3 c4 b3 q f4 e4)

 

B)

I get a bad result when called (unfold 'dw-om-methods '(p-exp-patt) my-pattern). Same behavior as usual

Listener output: 

test-foo-lib:  

offset: 12 
pattern:     ((bb4 a4 db4 gs4 fs4 c5 b4 f5 e5)) 
pattern-flat (bb4 a4 db4 gs4 fs4 c5 b4 f5 e5) 

Error: bb5 (of type symbol) is not of type sequence.

 

Therefore, I deduce that the difference must be in the definition of my function, since both operations essentially do the same thing: pitch transpose.

Perhaps someone has the definition of the library function pitch-transpose implemented by opusmodus, then I could see the difference?

OK, within my function  test-foo-lib pitch-transpose is used too. But the error occurs before this call!

I have no other ideas at the moment.

 

Daniel

  • Author

I went on investigating by implementing another simple function.

For tests line by line have been uncommented as follows (see also attached file.pdf, 2nd page, ready to load into opusmodus for tests) :

 

(defun test-foo-lib2 (offset pattern)

     (print offset)                                          ;direct-call      indirect-call (def-unfold-set, unfold)

     (setf res pattern)                                  ;    OK                      OK

    ;(setf res (omn :length pattern))          ;    OK                   Error

    ;(setf res (get-span pattern))               ;    OK                   Error

)

 

Without a solution of the mentioned problem I will not be able to use the opusmodus function "counterpoint" as expected!

Hopefully someone out there can reproduce my observations?

Thanks

 

Daniel

Def-Unfold-Set-Issue.pdf

I highly recommend taking several lessons with Stephane on the basics of building libraries and defining Lisp functions.

The library examples provided in Opusmodus should enable any user to create their own without errors.

The simplest way to start is to copy one of the examples to a new file and replace the names and values with your own.

 

For in-depth understanding of Lisp functions, consider referring to books such as:

  • ANSI Common Lisp
  • Common Lisp: The Language, 2nd Edition
  • Practical Common Lisp
  • On Lisp

These are just a few noteworthy examples.

 

Please note that the Opusmodus Forum does not focus on detailed studies of Common Lisp code.


This is not how a function is written:

(defun test-foo-lib2 (offset pattern)
     (print offset)
     (setf res pattern)
    (setf res (omn :length pattern))
    (setf res (get-span pattern)))

 

The forum is designed for Opusmodus users, providing a platform where they can share and seek help while learning from one another. It does not employ teachers to solve every problem encountered with learning Opusmodus or Lisp. Instead, users decide whether they wish to offer help. We are all in the same boat here; Stephane and I are attempting to answer as many queries as possible, time permitting.

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy