processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.65k stars 3.32k forks source link

Support for musicXML files with loadXML() #5318

Open patricio1979 opened 3 years ago

patricio1979 commented 3 years ago

How would this new feature help increase access to p5.js?

Most appropriate sub-area of p5.js?

Feature enhancement details:

musicXML is an XML file, at least is structured like one. Can't seem to be able to open this file and be treated like a normal XML file.

limzykenneth commented 3 years ago

If it is a valid XML file it should be able to load. Can you try passing the file to a XML validator (this one for example) and made sure there are no issues?

patricio1979 commented 3 years ago

Hello Kenneth, I rethinking the problem.I'm using createInputFile for loading the musicXML files. Here's the editor.p5.js Web Editor

p5.js Web Editor

A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, ed... |

|

|

I attach the musicXML validated in the website that you gave me. Thank you for the quick response.Patricio

El miércoles, 16 de junio de 2021 18:49:55 GMT-5, Kenneth Lim ***@***.***> escribió:  

If it is a valid XML file it should be able to load. Can you try passing the file to a XML validator (this one for example) and made sure there are no issues?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

limzykenneth commented 3 years ago

@scoresmexico Were you trying to attach a link to the web editor? It isn't show up here on GitHub, can you try again?

patricio1979 commented 3 years ago

Oh sorry, the mail was sent from google.

https://editor.p5js.org/patricio1979/sketches/FGisDe1bb

I tried to upload the file but Screen Shot 2021-06-17 at 7 22 59 AM

The musicXML file has this structure and was validated on the website that you mentioned: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">

L.v.Beethoven 2mov - Piano Concerto No.3 in C Minor Op.37 Copyright(C) 1995-2010, Suzuki Software MuseScore 2.3.0 2021-05-26 4 40 2159 2794 150 150 100 100 Copyright(C) 1995-2010, Suzuki Software Piano Piano Left Piano (2) (3) 1 1 78.7402 0 21.00 0.00 170.00 89.36 16 4 major 2 G 2 F 4

1 eighth 33 1 E 5 4 1 16th down 1 begin begin G 1 5 4 1 16th down 1 C 2 5 3 1 32nd double-sharp down 1 continue continue begin E 1 5 3 1 32nd sharp down 1 D 1 5 1 1 64th down 1 end end end backward hook F 1 5 1 1 64th down 1 D 1 5 4 1 16th down 1 F 1 5 4 1 16th down 1 D 1 5 1 1 64th down 1 begin begin begin begin F 1 5 1 1 64th down 1 1 C 1 5 1 1 64th sharp down 1 continue continue continue continue E 5 1 1 64th natural down 1 B 4 1 1 64th down 1 continue continue continue continue D 1 5 1 1 64th down 1 C 1 5 1 1 64th down 1 end end end end E 5 1 1 64th down 1 B 4 1 1 64th down 1 begin begin begin begin D 1 5 1 1 64th down 1 C 1 5 1 1 64th down 1 continue continue continue continue E 5 1 1 64th down 1 D 1 5 1 1 64th down 1 continue continue continue continue F 1 5 1 1 64th down 1 E 5 1 1 64th down 1 continue continue continue continue G 1 5 1 1 64th down 1 D 1 5 1 1 64th down 1 continue continue continue continue F 1 5 1 1 64th down 1 E 5 1 1 64th down 1 continue continue continue continue G 1 5 1 1 64th down 1 F 1 5 1 1 64th down 1 continue continue continue continue A 5 1 1 64th down 1 G 1 5 1 1 64th down 1 end end end end B 5 1 1 64th down 1 24 B 1 4 5 16th up 2 B 2 4 5 16th down 2 begin begin D 1 3 4 5 16th down 2 D 1 3 4 5 16th down 2 continue continue F 1 3 4 5 16th down 2 F 1 3 4 5 16th down 2 continue continue B 3 4 5 16th down 2 B 3 4 5 16th down 2 continue continue D 1 4 4 5 16th down 2 D 1 4 4 5 16th down 2 end end F 1 4 4 5 16th down 2 A 5 4 1 16th down 1 C 1 6 4 1 16th down 1 A 5 1 1 64th down 1 begin begin begin begin C 1 6 1 1 64th down 1 A 5 1 1 64th down 1 continue continue continue continue C 1 6 1 1 64th down 1 G 1 5 1 1 64th down 1 continue continue continue continue B 1 5 1 1 64th sharp down 1 A 5 1 1 64th down 1 end end end end C 1 6 1 1 64th down 1 A 5 1 1 64th down 1 begin begin begin begin C 1 6 1 1 64th down 1 G 1 5 1 1 64th down 1 continue continue continue continue B 5 1 1 64th natural down 1 F 2 5 1 1 64th double-sharp down 1 continue continue continue continue A 1 5 1 1 64th sharp down 1 G 1 5 1 1 64th down 1 end end end end B 5 1 1 64th down 1 F 2 5 1 1 64th down 1 begin begin begin begin A 1 5 1 1 64th down 1 G 1 5 1 1 64th down 1 continue continue continue continue B 5 1 1 64th down 1 A 5 1 1 64th natural down 1 continue continue continue continue C 1 6 1 1 64th down 1 G 1 5 1 1 64th down 1 end end end end B 5 1 1 64th down 1 G 1 5 1 1 64th down 1 begin begin begin begin B 5 1 1 64th down 1 1 F 1 5 1 1 64th sharp down 1 continue continue continue continue A 5 1 1 64th down 1 E 1 5 1 1 64th sharp down 1 continue continue continue continue G 1 5 1 1 64th down 1 F 1 5 1 1 64th down 1 end end end end A 5 1 1 64th down 1 E 1 5 1 1 64th down 1 begin begin begin begin G 1 5 1 1 64th down 1 F 1 5 1 1 64th down 1 continue continue continue continue A 5 1 1 64th down 1 G 1 5 1 1 64th down 1 continue continue continue continue B 5 1 1 64th down 1 F 1 5 1 1 64th down 1 end end end end A 5 1 1 64th down 1 24 B 2 4 5 16th down 2 begin begin B 3 4 5 16th down 2 end end D 1 4 4 5 16th down 2 B 2 4 5 16th down 2 begin begin C 1 4 4 5 16th down 2 end end E 4 4 5 16th down 2 B 2 4 5 16th down 2 begin begin D 1 4 4 5 16th down 2 end end F 1 4 4 5 16th down 2 F 1 5 4 1 16th down 1 begin begin A 5 4 1 16th down 1 D 1 5 3 1 32nd down 1 continue continue begin F 2 5 3 1 32nd double-sharp down 1 E 5 1 1 64th down 1 continue continue end forward hook G 1 5 1 1 64th down 1 E 5 4 1 16th down 1 end end G 1 5 4 1 16th down 1 4 1 16th 1 4 1 16th 1 G 1 5 4 1 16th down 1 24 E 3 4 5 16th up 2 begin begin G 2 E 4 4 5 16th up 2 continue continue G 1 4 4 5 16th up 2 E 4 4 5 16th up 2 end end G 1 4 4 5 16th up 2 4 5 16th 2 4 5 16th 2 G 1 4 4 5 16th up 2 G 1 5 2 1 32nd down 1 begin begin begin E 6 2 1 32nd down 1 continue continue continue E 6 2 1 32nd down 1 continue continue continue E 6 2 1 32nd down 1 end end end E 6 2 1 32nd down 1 begin begin begin D 1 6 2 1 32nd down 1 continue continue continue D 1 6 2 1 32nd down 1 continue continue continue D 1 6 2 1 32nd down 1 end end end D 1 6 1 1 64th down 1 begin begin begin begin C 1 6 1 1 64th down 1 continue continue continue continue E 6 1 1 64th down 1 continue continue continue continue D 1 6 1 1 64th down 1 continue continue continue continue F 1 6 1 1 64th sharp down 1 continue continue continue continue E 6 1 1 64th down 1 continue continue continue continue D 1 6 1 1 64th down 1 continue continue continue continue C 1 6 1 1 64th down 1 end end end end 24 G 1 4 2 5 32nd down 2 begin begin begin E 5 2 5 32nd down 2 continue continue continue E 5 2 5 32nd down 2 continue continue continue E 5 2 5 32nd down 2 end end end E 5 2 5 32nd down 2 begin begin begin D 1 5 2 5 32nd down 2 continue continue continue D 1 5 2 5 32nd down 2 continue continue continue D 1 5 2 5 32nd down 2 end end end D 1 5 1 5 64th down 2 begin begin begin begin C 1 5 1 5 64th down 2 continue continue continue continue E 5 1 5 64th down 2 continue continue continue continue D 1 5 1 5 64th down 2 continue continue continue continue F 1 5 1 5 64th down 2 continue continue continue continue E 5 1 5 64th down 2 continue continue continue continue D 1 5 1 5 64th down 2 continue continue continue continue C 1 5 1 5 64th down 2 end end end end

patricio1979 commented 3 years ago

That didn't went well... https://pastebin.com/W691kaSE

limzykenneth commented 3 years ago

You can enclose code blocks with three backticks (`) which will keep the tags in markdown.

loadXML() accepts a URL string to load the XML data and does not accept XML strings directly. What you want would be something like the following

const parser = new DOMParser();
const xml = parser.parseFromString(xmlString, 'text/xml');
const xmlObject = new p5.XML(xml.documentElement);

It's not documented though but I think a new function for parsing XML strings could be helpful to add. In any case you can use the snippet above to get around your problem.

patricio1979 commented 3 years ago

It still gives me an error. It builds a XML file with this info

<html>
<head></head>
<body xmlns="http://www.w3.org/1999/xhtml">
<parsererror style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black">…</parsererror>
</body>
</html>
limzykenneth commented 3 years ago

Actually if you are using createFileInput() you can skip a few steps and just do

function fileHandler(file){
  const xmlObject = new p5.XML(file.data.DOM);
}
patricio1979 commented 3 years ago

¡It works with files with XML extension! ...but no with musicXML file extension... Is there a way to correct this or is it the browser itself that throws error? El jueves, 17 de junio de 2021 11:36:02 GMT-5, Kenneth Lim @.***> escribió:

Actually if you are using createFileInput() you can skip a few steps and just do function fileHandler(file){ const xmlObject = new p5.XML(file.data.DOM); } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

patricio1979 commented 3 years ago

So I guess the "Support for musicXML file" that i requested is still good?

El jueves, 17 de junio de 2021 11:36:02 GMT-5, Kenneth Lim ***@***.***> escribió:  

Actually if you are using createFileInput() you can skip a few steps and just do function fileHandler(file){ const xmlObject = new p5.XML(file.data.DOM); } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

limzykenneth commented 3 years ago

It's not specifically musicXML file that is the problem but rather a way to create p5.XML object. But I think in your case it isn't really that much of a step, just the data returned from createFileInput() can be better documented.

Edit: if your musicXML file is valid XML it can be renamed with the .xml extension otherwise the browser won't recognized it as an XML file.

patricio1979 commented 3 years ago

Hopefully there will be support for musicXML files and other types of XML.

Thanks for the help!