Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 43 minutes ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

exporting bpf-lib to svg

Author 2 Subscribed Users |
Profile photo of Francesco Vitale
Francesco Vitale

Hi all,
is there a way to export a bpf-lib (and not only a simple bpf) to svg? Moreover, if someone has figured out how to import svg as a bpf (or a bpf-lib) it would be great news too. Thanks for your kind attention.
Best,
Francesco Vitale

April 22, 2018 at 14:33 #26362
Profile photo of anders
anders

Hi Francesco.

Here’s some code which exports all paths from a bpf-lib to one svg.

I’ve removed the various formatting arguments to svg-export (width, height, margins…), as they edit the numerici values before export, and i can’t see how they make any sense in the context of an svg. Kept the flipping of the y-axis however.

I’ll add the method for bpf-lib (with the changed arguments) in OMs core, unless someone cries out loud.

-anders

April 23, 2018 at 16:41 #26365
Profile photo of anders
anders

Forgot the import part :-) There’s code in “externals/XML/xml-api.lisp” to parse xml-files.

You can use (oa::om-list-from-xml-file “myfile.svg”) to get the xml structure as nested lists, then just dig through to pick whatever you need using standard list programming.

April 23, 2018 at 16:46 #26368
Profile photo of Francesco Vitale
Francesco Vitale

Dear Anders,
I cannot thank you enough for your precious help. I’m trying to use your .lisp file, which I have located in the “patches” folder, but I have this error that immediately pops up whenever I try to start OM: ERROR: Lambda list (SELF FILE-PATH &KEY :WITH-POINTS) is not congruent with the lambda list (SELF FILE-PATH &KEY WITH-POINTS W H MARGINS LINE-SIZE) of #<OMGENERICFUNCTION EXPORT-SVG 40E0BBEC74>. Maybe there’s something wrong in the lisp code you kindly gave me? Thanks again for your support.
Best,
Francesco

Attachments:
  1. error-svg

    error-svg.png

April 23, 2018 at 18:08 #26369
Profile photo of Francesco Vitale
Francesco Vitale

Nevermind Anders,
sorry for having bothered you: of course, my mistake was having not replaced your code in the “basicproject” file “export-svg” (putting the .lisp in the “patches” folder was wrong). Now everything loads without any error. Thanks for all.
Best,
Francesco

April 23, 2018 at 19:27 #26372
Profile photo of anders
anders

Sorry, that was clumsy, sending along a file with incompabilities in :-/ Changing the arguments of an existing method makes lisp whine. Putting them in 01-basicproject will probably hit other problems.

Just add the missing arguments back again in the lambda list of the two methods, then lisp will stop complaining. Ie. something like this, for each of the two methods:

(defmethod* export-svg ((self bpf) file-path &key with-points (w 300) (h 300) (margins 20) (line-size 1))

and

(defmethod* export-svg ((self bpf-lib) file-path &key with-points (w 300) (h 300) (margins 20) (line-size 1))

Sorry for the bother. I’ll change the code, but then you’ll have to wait for the next release.

-anders

Which ‘patches’ folder are you referring to?

April 23, 2018 at 20:44 #26373
Profile photo of Francesco Vitale
Francesco Vitale

Dear Anders,
the “patches” folder I mentioned before is the one no longer visible in OM 6.13, but it still present in OM 6.12 (the version I’m currently using). It appeared along with the “code” and the “libraries” folders accompanying the OM app.
Now the code I have stored in the /Applications/OM 6.12/code/projects/basicproject/functions/file.lisp, according to your new rewritten lines, is arranged like in the .lisp here attached, but evaluating the export-svn object all I get is always the same message: No method is defined for these types in box EXPORT-SVG. So maybe there’s something more that needs to be adjusted…
Best,
Francesco

April 23, 2018 at 22:15 #26374
Profile photo of anders
anders

Hi Francesco. Use the attached file, and make sure to place it in you “patches” folder, not in basicproject.

The next release will have this support built-in, so please delete this extra file from your workspace if/when you upgrade.

April 23, 2018 at 22:41 #26379
Profile photo of Francesco Vitale
Francesco Vitale

Hi Anders,
shall I restore the file.lisp in /Applications/OM 6.12/code/projects/basicproject/functions/file.lisp to its original form, or keep it modified (like in the file.lisp I attached to my previous message)? I’m asking this because the “No method is defined for these types in box EXPORT-SVG” keeps appearing even with your new code (the export-bpfs-to-svg1.lisp file) in the “patches” folder. Thanks for your patience.
Best,
Francesco

April 24, 2018 at 10:42 #26385
Profile photo of Francesco Vitale
Francesco Vitale

I tried also with the original, unmodified file.lisp in /Applications/OM 6.12/code/projects/basicproject/functions/file.lisp and your export-bpfs-to-svg1.lisp but the result is the same: cfr. the attached screenshot

Attachments:
  1. error-export

    error-export.png

April 24, 2018 at 10:56 #26386
Profile photo of anders
anders

You’ll need to connect the leftmost output from your bpf-lib into the export-svg box.

Use the original file.lisp, and put the second (last) version of export-bpfs-to-svg.lisp i sent you in you “user” or “patches” folder.

April 24, 2018 at 11:14 #26390
Profile photo of Francesco Vitale
Francesco Vitale

Thanks Anders,
now I can evaluate the export-svg object, but the resulting svg file is blank! I attach here the .omp and the output file. Am I doing something wrong again?

Attachments:
  1. Patch-7.omp
April 24, 2018 at 11:57 #26391
Profile photo of Francesco Vitale
Francesco Vitale

Here’s the blank svg in a .zip

Attachments:
  1. svg.zip
April 24, 2018 at 12:00 #26394
Profile photo of anders
anders

Your patch works here.

There’s already too much confusion from this thread. You’ll need to rewind back to zero. Make sure to:

  1. quit OM
  2. delete all versions of export-bpfs-to-svg.lisp or export-bpfs-to-svg1.lisp everywhere
  3. take care that the file “functions/file.lisp” is back to the original coming with your OM release
  4. start OM
  5. open the “Lisp Editor” (from the workspace: “Windows”->”Lisp Editor”)
  6. download the attached file
  7. copy/paste the content of the attached file in the Lisp Editor
  8. Eval the buffer (Ctrl-Y)

Check your patch-7 again.

April 24, 2018 at 12:32 #26397
Profile photo of Francesco Vitale
Francesco Vitale

Ok Anders,
I’ve followed your instructions carefully, and this is the OM Listener output that results from
1) evaluating the buffer of the Lisp Editor with the code contained in temp-bpf-to-svg.lisp and
2) evaluating the patch-7:
====================
OpenMusic v. 6.12
r. 2018/04/24
(c) IRCAM – Representations Musicales
http://repmus.ircam.fr/openmusic/
====================

OM > #<The OpenMusic package, 18315/32768 internal, 425/1024 external>
OM > with-svg-scene-to-file
OM > #<ommethod export-svg (bpf t) 41601EFC5B>
OM > #<ommethod export-svg (bpf-lib t) 41601F1AC3>
Loading patch: /Users/francescovitale/Desktop/workspace1/elements/Patch 7.omp
OM => #P”/Users/francescovitale/Desktop/workspace1/out-files/Untitled.svg”
Of course all versions of export-bpfs-to-svg.lisp or export-bpfs-to-svg1.lisp have been deleted everywhere and the “functions/file.lisp” is the one coming with the OM 6.12 for OS X (I’m on El capitan).
Sadly the svg file is still blank. Now I really don’t have the slightest idea about what could be the issue right now…

April 24, 2018 at 13:24 #26403
Profile photo of anders
anders

Hmm, this was a hard one, but let’s continue until we get it working.

Your “Untitled.svg” is not empty (check in an editor). But for some reason the coordinates are written to the .svg-file using an explicit single-float floating point representation:

path d=”M0.0F0 100.0F0…

which is used inside your bpf, and is fine inside lisp, but not compatible with the svg spec.

The cl-svg library used internally in OM uses “~A” to format the numbers to the svg-file, which should yield the wanted representation.

I have no idea why this occurs in your OM/machine (works fine here with your Patch7.omp). Could you do a test: in your Lisp Editor, try to enter (princ 0.5F0) and send me what is printed out in the Lisp Listener?

April 24, 2018 at 14:22 #26405
Profile photo of Francesco Vitale
Francesco Vitale

Well Anders,
thanks to your insights I found and resolved the problem. For an unknown reason, OM formats by default the floats with the “F0″, and I had to use the command (setf *read-default-float-format* ‘single-float) to get a standard readable svg. By the way, the “F0″ floats issue in OM is very annoying for all kinds of data managing, and if someone finds a fix to get the command (setf *read-default-float-format* ‘single-float) by default when starting OM it would be surely great. Thank you again for your indispensable help.
Best,
Francesco

April 24, 2018 at 15:05 #26406
Profile photo of anders
anders

‘single-float is the default for *read-default-float-format* in CL, and should be so in OM as well.

Please send me the value of *read-default-float-format* after startup in your OM. Also, what does this print to the listener:

(read-from-string “(1.0F0 0.112233445566778899 1.0e0 1.0s0 1.0f0 1.0d0 1.0L0)”)

Thanks,

-anders

April 24, 2018 at 15:54 #26408
Profile photo of Francesco Vitale
Francesco Vitale

Dear Anders,
sorry for the late reply. As I suspected, the default here (on each of my computers, i.e. a MacBook Pro, an iMac and a MacPro, with different OM versions) is the double float, in fact:

OpenMusic 1 > *read-default-float-format*
double-float

The second output you requested by consequence is:
OpenMusic 2 > (read-from-string “(1.0F0 0.112233445566778899 1.0e0 1.0s0 1.0f0 1.0d0 1.0L0)”)
(1.0F0 0.1122334455667789 1.0 1.0F0 1.0F0 1.0 1.0)
58

April 24, 2018 at 16:28 #26409
Profile photo of anders
anders

None of the standard omlibraries set the read-format permanently to double-float, and OM for sure does not. Either it’s something in an init-file you’re loading, or you’re loading some other software into OM changing this globally.

Check with a ‘clean’ OM, ie. no libraries, and add things back while peeking at the value of *read-default-float-format* to find the sinner.

April 24, 2018 at 17:49 #26412
Profile photo of Francesco Vitale
Francesco Vitale

Hi Anders,
until now, I haven’t found anything that makes OM change the default format, but surely I have to perform a deeper research. Now with (setf *read-default-float-format* ‘single-float) everything seems to work, except for the case included in the attachments. Here I have a simple spline bpf, but the svg encoding, again, gives me a blank document (even if the numerical data appears to be written in it. Do you have any explanation for that?
Best,
Francesco

April 24, 2018 at 20:13 #26413
Profile photo of Francesco Vitale
Francesco Vitale

Here you have also the svg output

Attachments:
  1. svg-2.zip
  2. svg-2.zip
April 24, 2018 at 20:23 #26416
Profile photo of anders
anders

Probably the extreme range of your numbers (100k-1M) make most svg-viewers choke?

This has nothing to do with OM.

If you want to scale your bpf’s upon output you can use the bpf-scale or om-scale or similar.

April 24, 2018 at 21:23 #26422

You must be logged in to reply to this topic.

Log in now