<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/introducing-tabr-guitar-tabs-with-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.snap.uaf.edu/2018/03/20/introducing-tabr-guitar-tabs-with-r/"> rbloggers – SNAP tech blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span></span></p>
<p>
<a rel="nofollow" href="https://github.com/leonawicz/tabr" target="_blank"><img src="https://i2.wp.com/github.com/leonawicz/tabr/blob/master/data-raw/tabr_logo.png?w=100%25&ssl=1" data-recalc-dims="1"></a>
</p>
<p>This post introduces a new R package I am working on called <a rel="nofollow" href="https://github.com/leonawicz/tabr" target="_blank">tabr</a> for creating guitar tablature (“tabs”) from R code. The <code>tabr</code> package provides programmatic music notation and a wrapper around <a rel="nofollow" href="http://lilypond.org/" target="_blank">LilyPond</a> for creating quality guitar tablature.</p>
<p>[<a rel="nofollow" href="https://leonawicz.github.io/blog/post/introducing-tabr-guitar-tabs-with-r/" target="_blank">Click here for original post</a>] (in process of switching where I post to R-Bloggers from)</p>
<p><code>tabr</code> offers functions for describing and organizing musical structures and wraps around the LilyPond backend. LilyPond is an open source music engraving program for generating high quality sheet music based on markup syntax. <code>tabr</code> generates files following the LilyPond markup syntax to be subsequently processed by LilyPond into sheet music.</p>
<p>A standalone LilyPond (.ly) file can be created or the package can make a system call to LilyPond directly to render the guitar tablature output (pdf or png). While LilyPond caters to sheet music in general, <code>tabr</code> is focused on leveraging it specifically for creating quality guitar tablature.</p>
<p>While music can be quite complex and a full score will be much longer, something as simple as the following code snippet produces the music notation in the accompanying image.</p>
<pre>
p(&quot;r a2 c f d a f c4&quot;, &quot;4 8*6 1&quot;) %>% track %>% score %>% tab(&quot;out.pdf&quot;)
</pre>
<p>
<img src="https://i1.wp.com/github.com/leonawicz/tabr/blob/master/data-raw/staff_with_code.png?w=100%25&ssl=1" data-recalc-dims="1">
</p>
<h2>Installation</h2>
<p>You can install tabr from GitHub with:</p>
<pre>
# install.packages('devtools')
devtools::install_github(&quot;leonawicz/tabr&quot;)
</pre>
<h2>Basic example</h2>
<p>As a brief example, recreate the tablature shown in the <code>tabr</code> logo, which is almost the same as the first measure in the code example above. It has a tiny bit more in the form of metadata and doesn’t take as many shortcuts, but it’s still short. Here are the steps.</p>
<ul>
<li>Define a musical phrase with <code>phrase</code> or the shorthand alias <code>p</code>.</li>
<li>Add the phrase to a <code>track</code>.</li>
<li>Add the track to a <code>score</code>.</li>
<li>Render the score to pdf with <code>tab</code>.</li>
</ul>
<h2>Constructing a musical phrase</h2>
<p>A phrase here does not require a strict definition. Think of it as the smallest piece of musical structure you intend to string together. The first argument to <code>phrase</code> is a string describing notes of a specific pitch (or rests: “r”), separated in time by spaces. For chords, just remove spaces to indicate simultaneous notes. Integers are appended to indicate the octave number so that the pitch is unique. For example, a rest followed by a sequence of notes might be given by <code>notes = &quot;r a2 c3 f3 d3 a3 f3&quot;</code>.</p>
<p>The second argument is a similar string giving note metadata. In this example there is nothing to add but the time durations. Whole notes taking up an entire measure of music are given by 1, half notes by 2, quarter notes 4, eighth notes 8, and so on. To specify a quarter note rest followed by a sequence of eighth notes, use <code>info = &quot;4 8 8 8 8 8 8&quot;</code>. This basic example does not require specifying additional note information such as dotted notes for different fractions of time, staccato notes, ties/slurs, slides, bends, hammer ons and pull offs, etc. These specifications are currently available in <code>tabr</code> to varying degrees of development and are covered in the vignette tutorials.</p>
<p>The third argument, <code>string</code>, is optional but generally important for guitar tablature. In similar format, it specifies the strings of the guitar on which notes are played. Providing this information fixes the fret-string combinations so that LilyPond does not have to guess what position on the neck of the guitar to play a specific note. An inability to specify this in various tablature notation software (or laziness by the user), is a common cause of inaccurate tabs scouring the internet, where even when the notes are correct they are written in the tab suggesting they be played in positions no one would sensibly use. Note that the <code>x</code> shown below is just a placeholder indicating no need to specify a string for the quarter note rest.</p>
<h2>Score metadata and accessing LilyPond</h2>
<p>Finally, specify some song metadata to reproduce the original staff: the key of D minor, common time, and the tempo. If LilyPond is installed on your system (and added to your system PATH variable on Windows systems), <code>tab</code> should call it successfully. Alternatively, on Windows, it can be added explicitly by calling <code>tabr_options</code>. This option to specify the LilyPond path is still available on other systems. An example of this is commented out below.</p>
<h2>R code</h2>
<pre>
library(tabr)
# path &lt;- 'C:/Program Files (x86)/LilyPond/usr/bin/lilypond.exe'
# tabr_options(lilypond = path)

p1 &lt;- p(&quot;r a2 c3 f3 d3 a3 f3&quot;, &quot;4 8 8 8 8 8 8&quot;, &quot;x 5 5 4 4 3 4&quot;)
track1 &lt;- track(p1)
song &lt;- score(track1)
tab(song, &quot;phrase.pdf&quot;, key = &quot;dm&quot;, time = &quot;4/4&quot;, tempo = &quot;4 = 120&quot;)
</pre>
<pre>
#> #### Engraving score to phrase.pdf ####
#> GNU LilyPond 2.18.2
#> Processing `./phrase.ly'
#> Parsing...
#> Interpreting music...
#> Preprocessing graphical objects...
#> Interpreting music...
#> MIDI output to `./phrase.mid'...
#> Finding the ideal number of pages...
#> Fitting music on 1 page...
#> Drawing systems...
#> Layout output to `./phrase.ps'...
#> Converting to `./phrase.pdf'...
#> Success: compilation successfully completed
</pre>
<p>See the pdf result embedded at the <a rel="nofollow" href="https://leonawicz.github.io/tabr/" target="_blank">tabr website</a>.</p>
<h2>Development status, context and caveats</h2>
<p>First, why LilyPond? LilyPond is an exceptional sheet music engraving program. It produces professional, high quality output. It is open source. It offers an access point for a programmatic approach to music notation. It is developed and utilized by a large community. Most GUI-based applications are WYSIWYG and force a greater limitation on what you can do and what it will look like after you do it. On the other hand, I have zero interest in writing LilyPond files. <code>tabr</code> has made it more enjoyable, a bit less ugly, and enables me to stick with LilyPond for its quality as I try to shield myself from its native input structures. I’m sure there are far more LilyPond users who don’t mind it at all and have never heard of R; to each their own.</p>
<p>The <code>tabr</code> package is in early development. Breaking changes could occur in a later version. Many capabilities are missing. Others are incompletely implemented. Others in the R developer community who are probably much better musicians than myself are welcome to contribute. This is the type of package that will only develop in response to specific needs of its contributor(s). There are many things that <code>tabr</code> does not address at this stage of development. For example, <code>tabr</code> assumes standard guitar tuning. It has no ability to recognize or handle non-standard tunings or instruments like bass with a different number of strings. There are essentially countless other aspects of music notation available in LilyPond that <code>tabr</code> does not wrap around. The aim is not to do it all, but certainly to do much more than is currently in place.</p>
<p>I am not an expert in music theory, or in music notation and transcription, or in LilyPond. In fact, my skill in music notation is ironically low enough that I do not find it any more challenging or an impediment to describe a song in R code rather than to just tab it out by hand. The main intent with <code>tabr</code>, however, is simply to be able to generate markup files that LilyPond accepts and understands, without having to write that markup directly.</p>
<p>Finally, there are nonetheless limitations to LilyPond itself. It has been developed for sheet music in general and guitar tablature features were added as a relative afterthought. There are plenty of features I have not yet developed R wrappers around. Then there are other features like string bending that are technically available, but not fully developed yet on the LilyPond side either. Case in point, LilyPond’s bend engraver is still under development; specifying something as common as a bend-release-pull-off is, to put it mildly, challenging.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.snap.uaf.edu/2018/03/20/introducing-tabr-guitar-tabs-with-r/"> rbloggers – SNAP tech blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/8oGhi0KRMJA" height="1"></a></div>