Parsing Digital Sheet Music MXL Files – Stranger Things Theme Song on Arduino

Arduino Stranger ThingsI’ve been toying around with playing music using simple tones on the Arduino. I’m no composer or musician so looking around for sheet music I eventually stumbled across MXL files on a few sites like MuseScore.com. Below I have posted a sample of the Arduino playing the Stranger Things theme song.

MXL is a compressed XML file that contains the Sheet Music data, Credits, Parts, Voice Definitions, Notes, Tempo and Durations along with other information. Basically a universal format designed for composing music, project sharing and several additional applications.

Ok so MXL files, what I keyed in on was that the MXL file contained the Notes and their Durations. This is perfect because you can create a simple Arduino code to play notes if you have this information. Sorting through these files is very daunting and time consuming so I decided to create a simple app to parse this information to use it more easily.

This app was banged out pretty quickly so please forgive possible errors. Because some MXL files are compressed and others are not I built in the code necessary to unpackage the XML before parsing. The app allows me to separate the notes by voice with their durations. In addition I placed a numeric control that limits the amount of notes that get parsed. A screenshot example is on the left.

Huge thanks to Shvelo who’s Ruby code got me pointed in the right direction.

I have this project posted on GitHub where you can obtain the code for the app as well as the Arduino sample code.

You can download the compiled app from GitHub.

Arduino SetupPlaying the Stranger Things theme song on the Arduino was a bit tricky tweaking the tempo to make it sound right but way easier without having to manually extract the notes and durations. To the left is the simple Arduino setup using piezo from a walkie talkie wired to pin 8 and ground on the controller. Ignore the other wires because they’re not used here.

A thanks to Riley Apperson on MuseScore for his/her Composition of the Stranger Things Theme.

Opensource CAD Software

Archimedes OpenCAD
Archimedes OpenCAD

Archimedes is a free and opensource CAD software. The interface is comfortable, fairly easy to use and is similar to commercial platforms. Exportable formats are svg (vector), pdf, xml and arc which is Archimedes’ native format. The downside is that documentation seems to be lacking and I maybe wrong here but there doesn’t seem to be a way to change the unit of measurement. With that said I still love it and will be using it.

You can learn more and download Archimedes here http://archimedescad.github.io/Archimedes/

Combine 2 or more xml files, sort, dedup and display with php

Want to combine 2 or more xml/rss files with php? This commented code should get you started.

The 2 xml files will need to be structured the same in order for this to work without adding more code. The 2 in this example are from the same source with different filters selected. This allows me to sort, filter and dedup using my own methods. You can then re-create the xml or simply display it on the screen like the example does below.

If you still need help feel free to comment below.

Code and Example below

<?php
//Sort Function by title
function sortFunction( $a, $b )
{
return strtotime($b["title"]) - strtotime($a["title"]);
}

$urllist = array();
//Define new xml files here by adding a new line with different urls
$urllist[] = “http://www.instructables.com/tag/type-question/rss.xml?count=100&sort=RECENT”;
$urllist[] = “http://www.instructables.com/tag/type-question/rss.xml?count=100&sort=UNANSWERED”;

//Loop through urllist array adding each item to one multidimensional array
//Define array before populating
$items = array();
foreach($urllist as $url)
{
$feed = simplexml_load_file($url);

//these item names are the child names in the xml
//channel is the wrapper in the xml
foreach($feed->channel->item as $item)
{
$items[] = array(
‘link’ => (string)$item->link,
‘image’ => (string)$item->imageThumb,
‘title’ => (string)$item->title,
‘pubdate’ => (string)$item->pubDate,
‘author’ => (string)$item->author
);
}
}

//Sort by Title
usort($items, “sortFunction”);

//Remove Duplicates
$items = array_map(“unserialize”, array_unique(array_map(“serialize”, $items)));

//Loop through the list and display them
$ictr = 0;
foreach ($items as $item)
{
echo “<div style=’float:left; width:200px; height:300px; margin-right:15px; text-align:center;’>”;
echo “<a href='” . $item[‘link’] . “‘ target=’_blank’>”;

if(strpos($item[‘image’],”defaultIMG”))
{
echo “<img src=’http://www.instructables.com/static/img/footer/footer-robot.png’ />”;
}
elseif(strpos($item[‘image’],”com”))
{
echo “<img src='” . $item[‘image’] . “‘ />”;
}
else
{
echo “<img src=’http://www.instructables.com” . $item[‘image’] . “‘ />”;
}
echo ‘<br />’ . $item[‘title’] . ‘<br />’;
echo ‘By: ‘ . $item[‘author’] . ‘ On ‘ . $item[‘pubdate’] . ‘</a></div>’;
}
echo “<div style=’clear: both;’>&nbsp;</div>”;
?>


Example of the output:

[phpCombineXMLArticle1][/phpCombineXMLArticle1]
Top