1

The expected output should be: enter image description here

The current code is as follow:

\documentclass[tikz,border=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{polyglossia}
\setmainlanguage{spanish}

\usepackage{tikz} \usetikzlibrary{arrows.meta, calc} \tikzstyle{every picture}+=[remember picture]

\usepackage{musicography} \usepackage{musixtex} \input{musixlyr} \input {musixcho} \input {musixdat}%fecha \input {musixfll} \input {musixgre}%gregoriano \input {musixper}%percusión \input {musixppff} \input {musixstr} \input {musixvbm} % experimental vectorized beams \input {musixdbr} % lineas de barras punteadas, discontinuas y arbitrariamente discontinuas \input {musixbm} % compatibilidad garrapateas con ganchos o con barras \input {musixbbm} % compatibilidad semi garrapateas con ganchos o con barras

%Rutinas para dibujar el piano \newlength{\CtoBwd}%% Width of 7 adjacent white (natural) keys \newlength{\Whitewd}%% Width of a natural key \newlength{\Blackwd}%% Width of a black key \newlength{\Whitefrontht}%% Distance from front of white key to black key \newlength{\Backwdi}%% <<-- See below \newlength{\Backwdii}%% <<-- See below \newlength{\Backwdiii}%% <<-- See below \newlength{\FronttoBack}%% Total length of a natural key \newlength{\Blackht}%% Length of a black key

%% http://datagenetics.com/blog/may32016/index.html

\NewDocumentCommand{\drawaccidental}{mmmm}{% Lower left, sharp name, flat name, coordinate name for upper right of accidental \draw[fill=black] (#1) rectangle node[white,text width=\Backwdii,align=center] {\bfseries\huge#2${}^\sharp$\[1ex]#3${}^\flat$} ++ (\Blackwd,\Blackht)coordinate (#4); }

\NewDocumentCommand{\drawname}{m}{% Coordinate name of lower left of key and name of key \node at ($(#1) + (\Whitewd/2,\Whitefrontht/2)$) {\bfseries\Huge#1}; }

%% f b = \Backwdi %% cs ds fs gs as = \Backwdii %% d g a = \Backwdii %% c e = \Backwdiii

\NewDocumentCommand{\drawkeyboard}{}{% \draw (0,0)coordinate(C) -- ++(0,\FronttoBack) -- ++(\Backwdiii,0) -- ++(0,-\Blackht)coordinate(CS) -| (\Whitewd,0)coordinate(D) -- cycle; \drawaccidental{CS}{C}{D}{CS0} \drawname{C}

\draw (D) -- ++(0,\Whitefrontht) -| (CS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(DS)
    -| (2\Whitewd,0)coordinate(E) -- cycle;
\drawaccidental{DS}{D}{E}{DS0}
\drawname{D}

\draw (E) -- ++(0,\Whitefrontht) -| (DS0) -- ++(\Backwdiii,0) -- ++(0,-\FronttoBack)coordinate(F)
    -- cycle;
\drawname {E}

\draw (F) -- ++(0,\FronttoBack) -- ++(\Backwdi,0) -- ++(0,-\Blackht)coordinate(FS)
    -| (4\Whitewd,0)coordinate(G) -- cycle;
\drawaccidental{FS}{F}{G}{FS0}
\drawname{F}

\draw (G) -- ++(0,\Whitefrontht) -| (FS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(GS)
    -| (5\Whitewd,0)coordinate(A) -- cycle;
\drawaccidental{GS}{G}{A}{GS0}
\drawname{G}

\draw (A) -- ++(0,\Whitefrontht) -| (GS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(AS)
-| (6\Whitewd,0)coordinate(B) -- cycle;
\drawaccidental{AS}{A}{B}{AS0}
\drawname{A}

\draw (B) -- ++(0,\Whitefrontht) -| (AS0) -- ++(\Backwdi,0) -- ++(0,-\FronttoBack) -- cycle;
\drawname{B}

}

\begin{document}

%Dibujo del piano \setlength{\CtoBwd}{6.5in} %% This varies between 160mm to 167mm depending upon manufacturer \pgfmathsetlengthmacro{\tmpwd}{\CtoBwd/5880}\typeout{\tmpwd!!!!} \setlength{\Whitewd}{\dimexpr \tmpwd840\relax} \setlength{\Blackwd}{\dimexpr \tmpwd490\relax} \setlength{\Blackht}{3.75in} \setlength{\Whitefrontht}{2in} \setlength{\FronttoBack}{\dimexpr \Whitefrontht + \Blackht\relax} \setlength{\Backwdi}{\dimexpr\tmpwd455\relax} \setlength{\Backwdii}{\dimexpr\tmpwd490\relax} \setlength{\Backwdiii}{\dimexpr\tmpwd*525\relax}

\begin{tikzpicture}[scale=0.7,rounded corners=4pt] %\foreach \oct in {0,...,3}{% for 4 octaves; vary at will \foreach \oct in {0}{% for 4 octaves; vary at will \begin{scope}[xshift=\oct*\CtoBwd] \drawkeyboard \end{scope} } %Poniendo etiquetas \node[text width=1cm,align=center] (tonoCD) at (2.35,-1.0) {\textbf{1 tono}}; \node[text width=1cm,align=center] (tonoDE) at (4.7,-1.0) {\textbf{1 tono}}; \node[text width=1cm,align=center] (semiTonoEF) at (7.1,-1.0) {\textbf{$1/2$ tono}}; \node[text width=1cm,align=center] (tonoFG) at (9.4,-1.0) {\textbf{1 tono}}; \node[text width=1cm,align=center] (tonoGA) at (11.8,-1.0) {\textbf{1 tono}}; \node[text width=1cm,align=center] (tonoAB) at (14.2,-1.0) {\textbf{1 tono}}; \node[text width=1cm,align=center] (semiTonoBC) at (16.5,-1.0) {\textbf{$1/2$ tono}};

\end{tikzpicture}

\end{document}

I need to improve the code for the following issues:

  1. Add border and background collor for labels: tones and semitones.
  2. Change the notes for spanish: Do for C, Re for D, Mi for E, and so on.
  3. Reduce the high size of the piano.

The current code output is:

current code output

Thanks and Regards

ABV
  • 611