{"id":795,"date":"2018-02-12T22:45:22","date_gmt":"2018-02-12T22:45:22","guid":{"rendered":"http:\/\/abcnotation.com\/blog\/?p=795"},"modified":"2021-07-07T07:08:42","modified_gmt":"2021-07-07T06:08:42","slug":"can-i-host-tunegraphs-on-my-own-site","status":"publish","type":"post","link":"https:\/\/abcnotation.com\/blog\/2018\/02\/12\/can-i-host-tunegraphs-on-my-own-site\/","title":{"rendered":"Can I host TuneGraphs on my own site?"},"content":{"rendered":"<p>A number of people have seen the <a href=\"\/searchHelp#TuneGraph\">TuneGraphs<\/a> on abcnotation.com\u00a0and asked if they could include them on their own website.<\/p>\n<p>The short answer is yes, although there are a number of restrictions.<\/p>\n<p>If you are interested in this possibility, read on.<\/p>\n<p><!--more--><\/p>\n<h3>Requirements<\/h3>\n<p>First check the requirements. You must have:<\/p>\n<ol>\n<li><strong>Sufficient similarities within your collection of tunes<\/strong> in order that the TuneGraph engine can find similar tunes. This may be possible even in a small collection of tunes: for example the <a href=\"\/dev\/TuneGraphDemonstrator\/\">TuneGraph demonstrator<\/a> has been built with ~300 morris tunes; only a relatively small collection, but with lots of similar versions of the same tune.<\/li>\n<li><strong>Abc code embedded within HTML pages<\/strong> rather than in downloadable abc files.<\/li>\n<li><strong>A unique URL for every tune.<\/strong>\u00a0The simplest way to achieve this is to have a single tune per page, but\u00a0if there are multiple tunes per page an alternative to use the HTML &#8220;id&#8221; attribute. So for example the 3rd tune on the page http:\/\/example.com\/page could be wrapped with &lt;div id=&#8217;0003&#8242;&gt;&#8230;&lt;\/div&gt; and then its unique URL is http:\/\/example.com\/page#0003.<\/li>\n<\/ol>\n<h3><strong>Checking<\/strong><\/h3>\n<p>Next &#8211; before reconfiguring your site &#8211; check with me that it&#8217;s going to be possible. I will need to check that the abcbot can index your site successfully (and this is always harder with embedded abc code). I will also check that the TuneGraph engine can find sufficient similarities within the site by generating a custom set of TuneGraphs for your site (these will only link to other tunes in your site and not to other tunes on other sites).<\/p>\n<h3>Infrastructure<\/h3>\n<p>Next, you will need to put in the infrastructure for the TuneGraphs to use (although I would recommend trying this on a couple of example pages before applying to the entire site).<\/p>\n<p>The simplest way to do this is to wrap every tune in a &lt;div&gt; element which both gives the TuneGraph viewer something to work with and identifies the tune. The &lt;div&gt; element needs to have the &#8220;class&#8221; attribute set as &#8220;divAbcTuneGraphContainer&#8221; and &#8220;id&#8221; as the number of the tune on the page (starting from 0001 and written with leading zeros so that each id contains 4 digits).<\/p>\n<p>For example, in the <a href=\"\/dev\/TuneGraphDemonstrator\/\">TuneGraph demonstrator<\/a>, each tune displayed has a title element (using an &lt;h3&gt; tag) and then the abc code element (using a &lt;pre&gt; tag to format it). These elements must then be wrapped in the &lt;div&gt; element so that for, say, the third tune on the page would be encoded as<\/p>\n<pre>&lt;div class=\"divAbcTuneGraphContainer\" id=\"0003\"&gt;\n&lt;h3&gt;Tune title&lt;\/h3&gt;\n&lt;pre&gt;\nX:1\nT:Tune title\nK:C\nCDEF GABc|\n&lt;\/pre&gt;\n&lt;\/div&gt;<\/pre>\n<p>You can put whatever HTML elements you like inside the &lt;div&gt; (for example, you might want to display the abc code in a &lt;textarea&gt; or &lt;p&gt; paragraph element).<\/p>\n<p>Furthermore, if you have only one tune per web page you can simplify the &lt;div&gt; by omitting the &#8220;id&#8221; attribute.<\/p>\n<p>In addition, on each page you will need to include the following 4 JavaScript files. I recommend that you download them (from my site, using the links below, or the originating site) and serve them from your own site. It&#8217;s probably best to include them right at the bottom of the page just before the closing &lt;\/body&gt; tag.<\/p>\n<p>The code to include them is<\/p>\n<pre>&lt;script src=\"[path]\/<a href=\"\/dev\/TuneGraphDemonstrator\/js\/TuneGraphViewer.v2.js\">TuneGraphViewer.v2.js<\/a>\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"[path]\/<a href=\"\/dev\/TuneGraphDemonstrator\/js\/d3.v3.min.js\">d3.v3.min.js<\/a>\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"[path]\/<a href=\"\/dev\/TuneGraphDemonstrator\/js\/abcjs_basic_1.10-min.js\">abcjs_basic_1.10-min.js<\/a>\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"[path]\/<a href=\"\/dev\/TuneGraphDemonstrator\/js\/TuneGraphConfig.v2.js\">TuneGraphConfig.v2.js<\/a>\" type=\"text\/javascript\"&gt;&lt;\/script&gt;<\/pre>\n<p>where [path] is the path to the javascript folder on your site.<\/p>\n<p>Finally you will need the following definitions in your CSS file (or somewhere in each page):<\/p>\n<pre>div.divAbcTuneGraphCanvas {\n width: 300px;\n height: 300px;\n}\ndiv.divAbcTuneGraphScore {\n width: 300px;\n}<\/pre>\n<h3>How it works<\/h3>\n<p>The way that the TuneGraphConfig JavaScript code works is to look for all of the elements in the &#8220;divAbcContainer&#8221; class on the page.<\/p>\n<p>It then extracts the contents of this &lt;div&gt; (e.g. the &lt;h3&gt; and &lt;pre&gt; elements in the example above) and replaces them with a &lt;table&gt; element. The table has one row with three cells: the left hand cell contains the original contents of the &lt;div&gt;, the middle cell has the TuneGraph canvas &lt;div&gt; displayed in it, and the right hand cell is a &lt;div&gt; used to display the scores of similar tunes.<\/p>\n<p>You can find examples in the\u00a0<a href=\"\/dev\/TuneGraphDemonstrator\/\">TuneGraph demonstrator<\/a>\u00a0pages showing usages with a <a href=\"\/dev\/TuneGraphDemonstrator\/single\/\">single tune per page<\/a> and <a href=\"\/dev\/TuneGraphDemonstrator\/multiple\/\">multiple tunes per page<\/a>.<\/p>\n<h3>Customisation<\/h3>\n<p>You can customise the TuneGraph usage in a number of ways.<\/p>\n<p>Firstly you can change the size of &#8220;divAbcTuneGraphCanvas&#8221; and &#8220;divAbcTuneGraphScore&#8221; using the CSS definitions, although I&#8217;m not sure they will work if they are much smaller. As you might expect, &#8220;divAbcTuneGraphCanvas&#8221; is the class name for the &lt;div&gt; element containing the canvas &#8211; i.e. where the TuneGraph is displayed; &#8220;divAbcTuneGraphScore&#8221; is the class name for the score element, where the the scores of similar tunes appear.<\/p>\n<p>You may also wish to change the location\/configuration of the canvas and score &lt;div&gt; elements particularly if your site is often viewed on mobile devices, as a table with 3 columns will not display well on such devices.<\/p>\n<p>In order to do this, just include canvas and score elements manually for each tune, with &#8220;id&#8221; attributes that match the tune they are associated with. If the TuneGraphConfig code detects any elements in either class &#8220;divAbcTuneGraphCanvas&#8221; or &#8220;divAbcTuneGraphScore&#8221;, then it won&#8217;t construct the table.<\/p>\n<p>So for example to match the example tune above, with &#8220;id&#8221; set to &#8220;0003&#8221;, include:<\/p>\n<pre>&lt;div class=\"divAbcTuneGraphCanvas\" id=\"0003.canvas\"&gt;&lt;\/div&gt;\n&lt;div class=\"divAbcTuneGraphScore\" id=\"0003.score\"&gt;&lt;\/div&gt;<\/pre>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A number of people have seen the TuneGraphs on abcnotation.com\u00a0and asked if they could include them on their own website. The short answer is yes, although there are a number of restrictions. If you are interested in this possibility, read on.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,30,42,3],"tags":[389,18,448,445],"_links":{"self":[{"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/posts\/795"}],"collection":[{"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/comments?post=795"}],"version-history":[{"count":3,"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/posts\/795\/revisions"}],"predecessor-version":[{"id":852,"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/posts\/795\/revisions\/852"}],"wp:attachment":[{"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/media?parent=795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/categories?post=795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abcnotation.com\/blog\/wp-json\/wp\/v2\/tags?post=795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}