%% doc_fretplot.tex
%% fretplot v0.0.3
%% Copyright 2025-- Soumendra Ganguly
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This work has the LPPL maintenance status `author-maintained'.
% 
% The Current Maintainer of this work is Soumendra Ganguly.
%
% This work consists of the files fretplot.sty, fretplot.lua,
% doc_fretplot.tex, doc_fretplot.pdf, README.md, and LICENSE.

%----------------------------------------------------------------------------
%% Batch generation of scale and chord diagrams for guitar-like instruments.|
%----------------------------------------------------------------------------

\documentclass[12pt,letterpaper]{article}
\usepackage{./fretplot}

\usepackage[letterpaper,top=1.5cm,bottom=1.5cm]{geometry} % Adjust 'bottom' as needed

\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{ % \circled
    \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{\circled{\tiny\thepage}} % Center page number in footer
\fancyhead{} % Clear header
\renewcommand{\headrulewidth}{0pt} % Remove header line
\renewcommand{\footrulewidth}{0pt} % Remove footer line

\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue]{hyperref} % for links in TOC and web URLs
\usepackage{ulem} % for \uline
\usepackage{float} % for [H] placement specifier in tables and figures
\usepackage{caption} % for caption font size via \captionsetup

\usepackage{listings}
\usepackage{xcolor}

\lstdefinelanguage{fretplot}{
  emph={include,flip,void},
  morekeywords={onf0,sovf,zoom,rotn,numfrt,numstr,frets,strings,notes,barres,fx,sx,bx,nx,fl,sl,nl},
  sensitive=true,
  morecomment=[l]{\#}
}

\lstset{
  keywordstyle=\color{blue}\bfseries,
  emphstyle=\color{brown}\bfseries,
  commentstyle=\color{purple},
  backgroundcolor=\color{white},
  numbers=left,
  columns=flexible,
  basicstyle=\scriptsize\ttfamily
}

% \newcommand{\fpdocexample}[1]{
% \captionsetup{font=scriptsize}

% \begin{minipage}[t]{0.65\textwidth}
% {\scriptsize \uline{Save source below as \texttt{include/#1/src.fp}:}}
% \lstinputlisting[language=fretplot]{include/#1/src.fp}

% {\scriptsize \uline{Run \texttt{lualatex --shell-escape #1.tex} after saving source below as \texttt{#1.tex} to get output on the right:}}
% \lstinputlisting[language={[LaTeX]TeX},emphstyle=]{include/#1/full.tex}
% \end{minipage}
% \hfill
% \begin{minipage}[t]{0.35\textwidth}
% \input{include/#1/body.tex}
% \end{minipage}

% \captionsetup{font=normalsize}
% }

\newcommand{\fpdocexample}[1]{
\captionsetup{font=scriptsize}

{\scriptsize \raisebox{1pt}{\bullet}\ Save source below as \texttt{\color{purple} proj/include/#1/src.fp}:}
\lstinputlisting[language=fretplot]{include/#1/src.fp}
{\scriptsize \raisebox{1pt}{\bullet}\ Save source below as \texttt{\color{purple} proj/#1.tex}:}
\lstinputlisting[language={[LaTeX]TeX},emphstyle=]{include/#1/full.tex}
{\scriptsize \raisebox{1pt}{\bullet}\ Run \texttt{\color{purple} lualatex\,\,\,--shell-escape\,\,\,#1.tex} in \texttt{\color{blue} proj/} to get the following output:}
\input{include/#1/body.tex}

\captionsetup{font=normalsize}
}

\title{The \texttt{fretplot} package\\\large Version 0.0.3}
\author{Author and maintainer: Soumendra Ganguly\\\href{https://soumendraganguly.com}{\texttt{soumendraganguly.com}}}
\date{Copyright 2025-- Soumendra Ganguly}

\begin{document}
\maketitle
\thispagestyle{empty}
\tableofcontents

\newpage

\section{Introduction}

The \textit{fretplot} Lua\TeX\ package provides batch generation of scale and chord diagrams for plucked string instruments, such as the guitar.\\

It is designed for high flexibility, automation, and customization via simple yet powerful custom file formats for describing fretboard diagrams, which allow for easy batch generation of diagrams. To complement the high customizability, the package also comes with sensible yet attractive default settings for the diagrams.\\

The package also provides some easy-to-use \LaTeX\ macros that understand the underlying music theory, allowing one to render, for example, a guitar scale diagram by specifying the musical scale or scale type via built-in macros, or even more directly via degree, pitch class, or interval formulae.

\newpage

\section{\LaTeX\ macros}

This package defines the following user-facing macros:

\begin{itemize}
  \item \verb|\fptotikz|
  \item \verb|\fptemplate|
  \item \verb|\fpstemplate|
  \item \verb|\fpscale|
\end{itemize}

\subsection{\texttt{\textbackslash fptotikz}}

\begin{itemize}
  \item[] \textbf{\color{blue} Syntax:} \texttt{\textbackslash fptotikz[OUTPUT\_TIKZ\_FILE]\{INPUT\_FP\_FILE\}}
  \item[] \textbf{\color{blue} Description:} compile an input fretplot file to Ti\textit{k}Z.
  \item[] \textbf{\color{blue} Arguments:}
    \begin{itemize}
      \item \texttt{INPUT\_FP\_FILE}: path to input fretplot file.
      \item \texttt{OUTPUT\_TIKZ\_FILE} (optional): path to output file to which generated Ti\textit{k}Z will be written. If \texttt{OUTPUT\_TIKZ\_FILE} is not specified, then the output Ti\textit{k}Z code will be included inline at the location of the \texttt{\textbackslash fptotikz} invocation.
    \end{itemize}
\end{itemize}

\subsection{\texttt{\textbackslash fptemplate}}

\begin{itemize}
  \item[] \textbf{\color{blue} Syntax:} \texttt{\textbackslash fptemplate\{OUTPUT\_FP\_FILE\}}
  \item[] \textbf{\color{blue} Description:} generate a template fretplot file.
  \item[] \textbf{\color{blue} Arguments:} \texttt{OUTPUT\_FP\_FILE}: path to output fretplot file.
\end{itemize}

\subsection{\texttt{\textbackslash fpstemplate}}

\begin{itemize}
  \item[] \textbf{\color{blue} Syntax:} \texttt{\textbackslash fpstemplate\{OUTPUT\_FPS\_FILE\}}
  \item[] \textbf{\color{blue} Description:} generate a template fretplot scale style file.
  \item[] \textbf{\color{blue} Arguments:} \texttt{OUTPUT\_FPS\_FILE}: path to output fretplot scale style file.
\end{itemize}

\subsection{\texttt{\textbackslash fpscale}}

\begin{itemize}
  \item[] \textbf{\color{blue} Syntax:} \texttt{\textbackslash fpscale\{ARGS\}}
  \item[] \textbf{\color{blue} Description:} render diagram of (mode of) scale based on input scale formula (degree, pitch class, or interval) or generate corresponding fretplot file or Ti\textit{k}Z code.
  \item[] \textbf{\color{blue} Arguments:} \texttt{ARGS}: \texttt{|} and/or \texttt{|\textbackslash n}-delimited list (possibly empty) of named argument assignments of the form \texttt{key=value} (with no surrounding spaces) in any order. Some of the subsequent pages of this section contain 2 tables:
    \begin{itemize}
    \item A complete table of keys for \texttt{ARGS} and their respective default and possible values. If a key does not have a default value, then the corresponding entry in the table is empty.
        \begin{itemize}
        \item In the table, a \textit{pitch class} refers to any element of the set
\begin{center}
\texttt{\{C, C\#, D, Eb, E, F, F\#, G, Ab, A, Bb, B\}}.
\end{center}
\item In the table, a \textit{degree} is any element of the set
\begin{center}
\texttt{\{1, b2, 2, b3, 3, 4, b5, 5, b6, 6, b7, 7\}}.
\end{center}
\item In the table, an \textit{interval} is a positive integer representing the number of semitones in a musical interval.
        \end{itemize}
    \item A table containing a list of macros that expand to interval formulas for popular scale types.
    \end{itemize}
\end{itemize}

\subsection{Examples}

Create a directory titled \texttt{proj}. Create subdirectories \texttt{proj/include} and \texttt{proj/tikz}. Create a file \texttt{proj/macro-demo.tex}. So your project directory structure is as follows:

\begin{verbatim}
proj/
|-- include/
|-- tikz/
|-- macro-demo.tex
\end{verbatim}

Copy the following code into \texttt{proj/macro-demo.tex}:

\lstinputlisting[language={[LaTeX]TeX},emphstyle=]{include/macro-demo/full.tex}

Run the following command in \texttt{proj/} to compile \texttt{proj/macro-demo.tex}: \begin{center}\texttt{lualatex --shell-escape macro-demo.tex}\end{center}

You should get the following output in the compiled PDF file \texttt{proj/macro-demo.pdf}:

\input{include/macro-demo/body.tex}

Play around with the generated files \texttt{proj/include/sclinclude.fp} and\\\texttt{proj/include/styles.fps} to customize the B Dorian figure. You can also edit the generated Ti\textit{k}Z code \texttt{proj/tikz/sclinclude.tex} directly.

% Old experiments:
%------------------

% \usetikzlibrary{external}
% \tikzexternalize % activate
% \tikzsetexternalprefix{figures/}

% 1 newline allowed immediately after |

% \begingroup
%    \catcode`\#=11
% \directlua{
% fretplot.scale_i([[A]], [[2 2 1 2 2 2 1]], [[E B G D A E]], 12, [[d]], [[d]], [[styles.fps]], [[sclnote.fp]], [[sclinclude.fp]])
% }
% \endgroup

% \scl{root=A|formulatype=d|formula=1 2 3 4 5 6 7|
% tuning=E B G D A E|numfrets=12|styletype=d|
% labeltype=d|stylefile=styles.fps|outfpfile=sclnote.fp|
% includefile=sclinclude.fp}

% \fretplot{sclnote.fp}

% \input{oout.tex}

% \scl{root=A|formulatype=d|formula=1 2 3 4 5 6 7|
% tuning=E B G D A E|numfrets=12|styletype=d|
% labeltype=d|stylefile=styles.fps|outtikzfile=oo.tex|
% includefile=sclinclude.fp}

% \input{oo.tex}

% \begin{figure}[H]
%   \centering
%   \begin{minipage}{0.5\textwidth}
%     \fbox{\fretplot{template.fp}}
%   \end{minipage}
%   \begin{minipage}{0.5\textwidth}
%     \fbox{\scl{root=A|formulatype=d|formula=1 b2 2 b3 3 4 b5 5 b6 6 b7 7|
%       tuning=E B G D A E|numfrets=12|styletype=p|
%       labeltype=p|stylefile=styles.fps|
%       includefile=sclinclude.fp}}
%   \end{minipage}
% \end{figure}

% \begin{figure}[h]
%   \hspace{-0.5in}
%   \begin{minipage}{0.4\textwidth}
%     \fbox{\fretplot{testtemplate.fp}}
%     \caption{A major triad barre chord}
%   \end{minipage}
%   \hspace{1.2in}
%   \begin{minipage}{0.4\textwidth}
%     \fbox{\fretplot{testtemplate.fp}}
%     \caption{A major triad barre chord}
%   \end{minipage}
% \end{figure}

\subsection{Tables}

\begin{table}[H]\tiny\begin{tabular}{|l|l|p{8cm}|}
\hline

&&\\
KEY & DEFAULT VALUE & VALUE\\
&&\\

\hline

&&\\
\texttt{parentroot} & \texttt{C} & Root of parent scale. This can be any pitch class. This is ignored if \texttt{formulatype=p} or if \texttt{moderoot} is specified. Please see the description of \texttt{mode} for more details.\\
&&\\

\hline

&&\\
\texttt{formulatype} & \texttt{d} & Type of the formula specified in the key named \texttt{formula}. Possible values are \texttt{\{d, p, i\}}. Here \texttt{d} stands for \textit{degree}, \texttt{p} stands for \textit{pitch class}, and \texttt{i} stands for \textit{interval}.\\
&&\\

\hline

&&\\
\texttt{formula} & \texttt{1 2 3 4 5 6 7} & Formula of parent scale. This should be a list of degrees or pitch classes or intervals delimited by single ordinary space characters (ASCII 32). The type of this formula is indicated by specifying \texttt{formulatype}.\\
&&\\

\hline

&&\\
\texttt{mode} & \texttt{1} & Mode index of scale. This is specified as a positive integer. This mode will be rendered by \texttt{\textbackslash fpscale}. Examples: if \texttt{formulatype=p}, \texttt{formula=C D E F G A B}, and \texttt{mode=3}, then the 3rd mode of the C major scale (E Phrygian) will be rendered. If \texttt{formulatype=d}, \texttt{formula=1 2 3 4 5 6 7}, \texttt{mode=2}, \texttt{parentroot=A}, and \texttt{moderoot} is not specified, then the 2nd mode of the A major scale (which is B Dorian) will be rendered. In the above scenario, if \texttt{moderoot=A}, then A Dorian will be rendered instead.\\
&&\\

\hline

&&\\
\texttt{moderoot} &  & Optional root of mode of scale. This can be any pitch class. This is ignored if \texttt{formulatype=p}. Please see the description of \texttt{mode} for more details.\\
&&\\

\hline

&&\\
\texttt{tuning} & \texttt{E B G D A E} & Tuning of strings of the instrument. This is specified as a list of pitch classes delimited by single ordinary space characters (ASCII 32).\\
&&\\

\hline

&&\\
\texttt{numfrets} & \texttt{12} & Number of frets on the fingerboard. If the instrument does not have frets, then one can style them to be transparent in the render.\\
&&\\

\hline

&&\\
\texttt{styletype} & \texttt{d} & Specify if the styling of notes should be degree-indexed or pitch class-indexed. Possible values are \texttt{\{d, p\}}. Here \texttt{d} stands for \textit{degree} and \texttt{p} stands for \textit{pitch class}. The user can customize the actual styles by specifying the key \texttt{scalestylefile}.\\
&&\\

\hline

&&\\
\texttt{labeltype} & \texttt{d} & Specify if the labelling of notes should be degree-indexed or pitch class-indexed. Possible values are \texttt{\{d, p\}}. Here \texttt{d} stands for \textit{degree} and \texttt{p} stands for \textit{pitch class}. The user can customize the actual labels by specifying the key \texttt{scalestylefile}.\\
&&\\

\hline

&&\\
\texttt{outfpfile} &  & Optional path to output fretplot file describing (mode of) scale. If this is specified, then no Ti\textit{k}Z code will be generated by \texttt{\textbackslash fpscale} (neither inline nor to \texttt{outtikzfile}). One can then make modifications to the output fretplot file and then generate Ti\textit{k}Z code (inline or external file) from the fretplot file using \texttt{\textbackslash fptotikz}. The keys \texttt{includefpfile} and \texttt{scalestylefile} are used to further customize the rendering. In particular, \texttt{includefpfile} is included at the end of \texttt{outfpfile}. Even if \texttt{outfpfile} is not specified, \texttt{\textbackslash fpscale} still internally creates a temporary fretplot file which is then converted to Ti\textit{k}Z. This temporary fretplot file also includes \texttt{includefpfile} at its end, which allows one to customize their render via \texttt{includefpfile} without specifying \texttt{outfpfile}. The same fretplot file can serve as the \texttt{includefpfile} for multiple \texttt{\textbackslash fpscale} invocations, which allows for batch manipulation of scale plots. Temporary fretplot files created by \texttt{\textbackslash fpscale} internally are deleted later automatically.\\
&&\\

\hline

&&\\
\texttt{outtikzfile} &  & Optional path to output file containing Ti\textit{k}Z code describing (mode of) scale. This will be ignored if \texttt{outfpfile} is specified. If \texttt{outfpfile} is not specified and \texttt{outtikzfile} is specified, then \texttt{\textbackslash fpscale} will not generate inline Ti\textit{k}Z code. One can then make modifications to the output Ti\textit{k}Z code and use \texttt{\textbackslash input} to use it in their document.\\
&&\\

\hline

&&\\
\texttt{includefpfile} &  & Optional path to input fretplot file to be included at the end of \texttt{outfpfile} or an equivalent temporary fretplot file created by \texttt{\textbackslash fpscale} for internal use. If there does not exist a file at the path specified by \texttt{includefpfile}, then a new empty file will be created at that path; one can then edit this new file for use in subsequent compilations. For more details, please see \texttt{outfpfile}.\\
&&\\

\hline

&&\\
\texttt{scalestylefile} &  & Optional path to input fretplot scale style file. This can be used to customize degree and/or pitch class-based styling and labelling for scale notes. Please see \texttt{styletype} and \texttt{labeltype} for additional details.\\
&&\\

\hline
\end{tabular}\caption{Key-value pairs for \texttt{\textbackslash fpscale}}\end{table}
\normalsize

\begin{table}[H]\tiny\begin{tabular}{|l|l|l|}
\hline

&&\\
MACRO & INTERVAL FORMULA IN SEMITONES & DESCRIPTION\\
&&\\

\hline

&&\\
\texttt{\textbackslash fpmpent} & 3 2 2 3 2 & Minor pentatonic scale\\
\texttt{\textbackslash fpblues} & 3 2 1 1 3 2 & Blues scale\\
&&\\

\hline

&&\\
\texttt{\textbackslash fpmaj} & 2 2 1 2 2 2 1 & Major scale\\
\texttt{\textbackslash fpjmin} & 2 1 2 2 2 2 1 & Jazz minor scale (ascending melodic minor scale)\\
\texttt{\textbackslash fphmin} & 2 1 2 2 1 3 1 & Harmonic minor scale\\
&&\\

\hline

&&\\
\texttt{\textbackslash fphmaj} & 2 2 1 2 1 3 1 & Harmonic major scale\\
\texttt{\textbackslash fpdhmaj} & 1 3 1 2 1 3 1 & Double harmonic major scale\\
\texttt{\textbackslash fpnmaj} & 1 2 2 2 2 2 1 & Neapolitan major scale\\
\texttt{\textbackslash fpnmin} & 1 2 2 2 1 3 1 & Neapolitan minor scale\\
\texttt{\textbackslash fphunmaj} & 3 1 2 1 2 1 2 & Hungarian major scale\\
&&\\

\hline

&&\\
\texttt{\textbackslash fpbmaj} & 2 2 1 2 1 1 2 1 & Bebop major scale\\
\texttt{\textbackslash fpbmin} & 2 1 2 2 2 1 1 1 & Bebop minor scale\\
\texttt{\textbackslash fpbdom} & 2 2 1 2 2 1 1 1 & Bebop dominant scale\\
\texttt{\textbackslash fpldbeb} & 2 2 2 1 2 1 1 1 & Lydian dominant bebop scale\\
\texttt{\textbackslash fppdbeb} & 1 3 1 2 1 2 1 1 & Phrygian dominant bebop scale\\
&&\\

\hline

&&\\
\texttt{\textbackslash fpchr} & 1 1 1 1 1 1 1 1 1 1 1 1 & Chromatic scale\\
\texttt{\textbackslash fpwt} & 2 2 2 2 2 2 & Whole tone scale\\
\texttt{\textbackslash fptwowt} & 4 4 4 & Two whole tones scale\\
\texttt{\textbackslash fpthreewt} & 6 6 & Three whole tones scale\\
\texttt{\textbackslash fpmon} & 12 & Monotonic scale\\
&&\\

\hline

&&\\
\texttt{\textbackslash fpaug} & 3 1 3 1 3 1 & Augmented scale\\
\texttt{\textbackslash fptrit} & 1 3 2 1 3 2 & Tritone scale\\
\texttt{\textbackslash fpwhdim} & 2 1 2 1 2 1 2 1 & Whole half diminished scale\\
&&\\

\hline

&&\\
\texttt{\textbackslash fpmajsevenarp} & 4 3 4 1 & Major seventh arpeggio\\
\texttt{\textbackslash fpdomsevenarp} & 4 3 3 2 & Dominant seventh arpeggio\\
\texttt{\textbackslash fpminsevenarp} & 3 4 3 2 & Minor seventh arpeggio\\
\texttt{\textbackslash fphdimsevenarp} & 3 3 4 2 & Half diminished seventh arpeggio\\
\texttt{\textbackslash fpdimsevenarp} & 3 3 3 3 & Diminished seventh arpeggio\\
\texttt{\textbackslash fpminmajsevenarp} & 3 4 4 1 & Minor major seventh arpeggio\\
&&\\

\hline
\end{tabular}\caption{Macros for interval formulae of popular scale types}\end{table}
\normalsize

\newpage

\section{The fretplot file format}

A \textit{fretplot file}, \textit{fp file}, or \texttt{.fp} file describes the layout and appearance of a fretboard diagram.

\subsection{Syntax}

\begin{itemize}
\item Comment lines start with \texttt{\#}. Comment lines and empty lines are ignored.
\item Every other line of a fretplot file will have lines of form \texttt{firstword lots of data}, where \texttt{firstword} and \texttt{lots of data} must be separated by a single ordinary space character (ASCII 32), \texttt{lots of data} cannot be empty, and the first character of \texttt{lots of data} cannot be a whitespace character (space, tab, newline, or anything that matches \texttt{\%s} in Lua).
\item
  \begin{itemize}
  \item Note notation: \texttt{<STRINGINDEX,FRETINDEX>}\\Example: \texttt{<6,5>}

  \item Barre notation: \texttt{<STARTSTRINGINDEX-ENDSTRINGINDEX,FRETINDEX>}\\Example: \texttt{<1-6,5>}
  \end{itemize}
\item Barres never have labels. Frets, strings, and notes by default have no labels, but can be specified as follows:
  \begin{itemize}
    \item Frets: \texttt{flFRETINDEX LABEL}\\Example: \texttt{fl3 3}
    \item Strings: \texttt{slSTRINGINDEX LABEL}\\Example: \texttt{sl1 \{\textbackslash Large e\}}
    \item Notes: \texttt{nl<STRINGINDEX,FRETINDEX> LABEL}\\Example: \texttt{nl<6,5> \{\textbackslash Large A\}}
  \end{itemize}
\item To include another fretplot file at the current location of a fretplot file, use \texttt{include FILEPATH}.
\end{itemize}

\subsection{Parameters}

All available parameters that can be used in a fretplot file are listed in the table on the next page. Operations are case-sensitive and must be written exactly as shown.

\begin{table}[H]\tiny\hspace{-2.5cm}\begin{tabular}{|l|p{1.5cm}|l|p{2.5cm}|p{1pt}|l|p{2.5cm}|l|}
\hline

&&&&&&&\\
TYPE & POSSIBLE VALUES & OPERATIONS & OP DESCRIPTION & & PARAMETERS & PARAM DESC & DEFAULT PARAM VALUE\\
&&&&&&&\\

\hline

&&&&&&&\\
Boolean & \texttt{True}, \texttt{False} & \texttt{flip PARAMETER} & negate Boolean parameter named \texttt{PARAMETER} & & \texttt{onf0} & draw notes directly on top of fret 0 (nut of guitar) if \texttt{True} and not if \texttt{False}&\texttt{False}\\
&&&&&&&\\
\cline{6-8}
&&&&&&&\\
&&&&&\texttt{sovf}& draw strings over frets if \texttt{True} and frets over strings if \texttt{False}&\texttt{True}\\
&&&&&&&\\

\hline

&&&&&&&\\
&&\texttt{+PARAMETER VALUE} & add literal numerical value \texttt{VALUE} to numerical parameter named \texttt{PARAMETER}&&&&\\
&&&&&&&\\
\cline{3-4}
&&&&&&&\\
&&\texttt{-PARAMETER VALUE} & subtract literal numerical value \texttt{VALUE} from numerical parameter named \texttt{PARAMETER}&&&&\\
&&&&&\texttt{zoom}&Factor by which the diagram will be scaled&\texttt{1.0}\\
\cline{3-4}
&&&&&&&\\
\cline{6-8}
Numerical & Any numerical value & \texttt{*PARAMETER VALUE} & multiply numerical parameter named \texttt{PARAMETER} by literal numerical value \texttt{VALUE}&&&&\\
&&&&&\texttt{rotn}&Angle (in degrees) by which the diagram will be rotated &\texttt{0}\\
\cline{3-4}
&&&&&&&\\
\cline{6-8}
&&\texttt{/PARAMETER VALUE} & divide numerical parameter named \texttt{PARAMETER} by literal numerical value \texttt{VALUE}&&&&\\
&&&&&\texttt{numfrt}& Number of frets &\texttt{12}\\
\cline{3-4}
&&&&&&&\\
\cline{6-8}
&&\texttt{\%PARAMETER VALUE} & mod numerical parameter named \texttt{PARAMETER} by literal numerical value \texttt{VALUE}&&&&\\
&&&&&\texttt{numstr}& Number of strings &\texttt{6}\\
\cline{3-4}
&&&&&&&\\
&&\texttt{\textasciicircum PARAMETER VALUE} & raise numerical parameter named \texttt{PARAMETER} to the power of literal numerical value \texttt{VALUE}&&&&\\
&&&&&&&\\

\hline

&&&&&&&\\
&&&&&\texttt{frets}&List of fret indices&\texttt{0 1 2 3 4 5 6 7 8 9 10 11 12}\\
&&&&&&&\\
\cline{6-8}
&& \texttt{void PARAMETER} & empty the list parameter named \texttt{PARAMETER}&&&&\\
&&&&&&&\\
\cline{3-4}
&&&&&\texttt{strings}&List of string indices&\texttt{1 2 3 4 5 6}\\
&&&&&&&\\
\cline{6-8}
List& List of items delimited by single ordinary space characters (ASCII 32), or the \textit{empty list} &\texttt{>PARAMETER VALUE} & extend list parameter named \texttt{PARAMETER} by literal list value \texttt{VALUE}&&&&\\
\cline{3-4}
&&&&&\texttt{notes}&List of notes &empty list\\
&&&&&&&\\
\cline{6-8}
&&\texttt{<PARAMETER VALUE} & remove values in literal list value \texttt{VALUE} from list parameter named \texttt{PARAMETER}&&&&\\
&&&&&&&\\
&&&&&\texttt{barres}& List of barres &empty list\\
&&&&&&&\\

\hline

&&&&&&&\\
&&&&&\texttt{fx}&Fret style&\texttt{solid,line width=0.6,color=black}\\
&&&&&&&\\
\cline{6-8}
&&&&&&&\\
&&&&&\texttt{sx}&String style &\texttt{solid,line width=0.6,color=black}\\
&&&&&&&\\
\cline{6-8}
&&&&&&&\\
Style& List of PGF/Ti\textit{k}Z styles delimited by single \texttt{,} (comma) characters &\texttt{\&PARAMETER VALUE} & extend style parameter named \texttt{PARAMETER} by literal comma-delimited collection of styles \texttt{VALUE}&&&&\\
&&&&&&&\\
&&&&&\texttt{bx}&Barre style &\texttt{fill=black,draw=black}\\
&&&&&&&\\
\cline{6-8}
&&&&&&&\\
&&&&&\texttt{nx}& Note style &\texttt{shape=rectangle,draw=black,text=white,fill=black}\\
&&&&&&&\\

\hline
\end{tabular}\caption{Parameters for fretplot files}\end{table}
\normalsize

\subsection{Batch processing using operations on parameters}

The operations are particularly useful for batch manipulation of diagrams.\\

For example, say, you are writing a book containing 100 chord diagrams. Each of those diagrams is described using its own fretplot file. Now you want to scale/enlarge each of them to 1.5 times of their respective original sizes, and additionally you want to rotate all of them by 30 degrees.\\

To do this, in each of those 100 fretplot files you can include another common fretplot file, say, \texttt{common.fp} by writing \texttt{include common.fp} \textit{at the end} of all of those 100 fretplot files, and then in \texttt{common.fp} you can write the following two lines:\\

\begin{lstlisting}[language=fretplot]
+rotn 30
*zoom 1.5
\end{lstlisting}

This will rotate all those 100 diagrams by 30 degrees and zoom in by a factor of 1.5, without you having to edit each of those 100 files individually.\\

\textit{Please note} that lines in a fretplot file are interpreted sequentially, so the location where you write \texttt{include common.fp} in a fretplot file matters due to non-commutativity of certain operations. For instance, if the parameter \texttt{rotn} was \texttt{10} and you wanted to multiply it by \texttt{2} and subtract \texttt{5} from it, the order in which you performed those operations would matter.\\

The following is an example fretplot file that demonstrates the use of some parameters and some operations on them:\\

\lstinputlisting[language=fretplot]{include/operations-demo.fp}

\subsection{Example: barre chord diagram}

\fpdocexample{amaj}

\subsection{Example: fretless guitar diagram}

\fpdocexample{fretless}

\subsection{Example: custom instrument diagram}

\fpdocexample{custom-instrument}

\newpage

\section{The fretplot scale style file format}

A \textit{fretplot scale style file}, \textit{fps file}, or \texttt{.fps} file customizes the appearance and labels of notes in a scale, based on pitch class or degree.

\subsection{Syntax}

\begin{itemize}
\item A \textit{pitch class} is any element of the set

\begin{center}
\texttt{\{C, C\#, D, Eb, E, F, F\#, G, Ab, A, Bb, B\}}.
\end{center}
\item A \textit{degree} is any element of the set

\begin{center}
\texttt{\{1, b2, 2, b3, 3, 4, b5, 5, b6, 6, b7, 7\}}.
\end{center}

\item Each line assigns a style or label to a pitch class or degree:

\begin{itemize}
  \item Label based on pitch class: \texttt{lPITCHCLASS LABEL}.
  \item Label based on degree: \texttt{lDEGREE LABEL}.
  \item PGF/Ti\textit{k}Z style based on pitch class: \texttt{xPITCHCLASS STYLE}.
  \item PGF/Ti\textit{k}Z style based on degree: \texttt{xDEGREE STYLE}.
\end{itemize}
\end{itemize}

\subsection{An example}

\begin{lstlisting}[commentstyle=]
lC {\scriptsize C}
lC# {\tiny C$\sharp$}
lD {\scriptsize D}
lEb {\tiny E$\flat$}

xC shape=circle,draw=red,text=blue,fill=white,inner sep=1.0
xC# shape=circle,draw=red,text=blue,fill=white,inner sep=1.0

l1 {\scriptsize 1}
lb2 {\tiny $\flat$2}

x1 shape=circle,draw=red,text=white,fill=red,inner sep=1.0
xb2 shape=circle,draw=red,text=blue,fill=white,inner sep=1.0
\end{lstlisting}
\end{document}
