%%
%% This is file `xpiano.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xpiano.dtx  (with options: `package')
%% ---------------------------------------------------------------
%% The xpiano package --- Extension of piano.sty by \'Emile Daneault
%% Maintained by Enrico Gregorio
%% Email: enrico DOT gregorio AT univr DOT it
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ---------------------------------------------------------------
\RequirePackage{expl3,xparse}
\ProvidesExplPackage {xpiano} {2015/05/22} {1.0}
  {An extension of piano.sty by \'Emile Daneault}
\@ifpackagelater { expl3 } { 2015/03/01 }
  { }
  {
    \PackageError { xpiano } { Support~package~expl3~too~old }
      {
        You~need~to~update~your~installation~of~the~bundles~'l3kernel'~and~
        'l3packages'.\MessageBreak
        Loading~xpiano~will~abort!
      }
    \tex_endinput:D
  }
\RequirePackage{xcolor}
\definecolor{pianodefault}{RGB}{255,127,0}
\NewDocumentCommand{\keyboard}{ O{}m }
 {
  \xpiano_keyboard:nn { #1 } { #2 }
 }
\NewDocumentCommand{\keyboardsetup}{ m }
 {
  \keys_set:nn { piano } { #1 }
 }
\NewDocumentCommand{\Keyboard}{O{}O{}O{}O{}O{}}
 {
  \keyboard{#1,#2,#3,#4,#5}
 }
\keys_define:nn { piano }
 {
  font        .tl_set:N   = \l__xpiano_font_tl,
  single      .bool_set:N = \l__xpiano_single_bool,
  ext         .bool_set:N = \l__xpiano_ext_bool,
  size        .dim_set:N  = \l__xpiano_size_dim,
  height      .tl_set:N   = \l__xpiano_height_tl,
  numbers     .bool_set:N = \l__xpiano_numbers_bool,
  color       .tl_set:N   = \l__xpiano_color_tl,
  numbercolor .tl_set:N   = \l__xpiano_numbercolor_tl,
  10          .tl_set:N   = \l__xpiano_ten_tl,
  11          .tl_set:N   = \l__xpiano_eleven_tl,
  ratio       .fp_set:N   = \l__xpiano_ratio_fp,
  font        .initial:n  = \tiny,
  single      .initial:n  = false,
  single      .default:n  = true,
  ext         .initial:n  = false,
  ext         .default:n  = true,
  size        .initial:n  = 0.5cm,
  height      .initial:n  = 4,
  numbers     .initial:n  = false,
  numbers     .default:n  = true,
  color       .initial:n  = {pianodefault},
  numbercolor .initial:n  = black,
  10          .initial:n  = 10,
  11          .initial:n  = 11,
  ratio       .initial:n  = 0.75,
 }
\tl_new:N \l__xpiano_width_tl
\prop_new:N \g__xpiano_notes_prop
\prop_gput:Nnn \g__xpiano_notes_prop { Co }  { 0 }
\prop_gput:Nnn \g__xpiano_notes_prop { Cso } { 1 }
\prop_gput:Nnn \g__xpiano_notes_prop { Do }  { 2 }
\prop_gput:Nnn \g__xpiano_notes_prop { Dso } { 3 }
\prop_gput:Nnn \g__xpiano_notes_prop { Eo }  { 4 }
\prop_gput:Nnn \g__xpiano_notes_prop { Fo }  { 5 }
\prop_gput:Nnn \g__xpiano_notes_prop { Fso } { 6 }
\prop_gput:Nnn \g__xpiano_notes_prop { Go }  { 7 }
\prop_gput:Nnn \g__xpiano_notes_prop { Gso } { 8 }
\prop_gput:Nnn \g__xpiano_notes_prop { Ao }  { 9 }
\prop_gput:Nnn \g__xpiano_notes_prop { Aso } { 10 }
\prop_gput:Nnn \g__xpiano_notes_prop { Bo }  { 11 }
\prop_gput:Nnn \g__xpiano_notes_prop { Ct }  { 0' }
\prop_gput:Nnn \g__xpiano_notes_prop { Cst } { 1' }
\prop_gput:Nnn \g__xpiano_notes_prop { Dt }  { 2' }
\prop_gput:Nnn \g__xpiano_notes_prop { Dst } { 3' }
\prop_gput:Nnn \g__xpiano_notes_prop { Et }  { 4' }
\prop_gput:Nnn \g__xpiano_notes_prop { Ft }  { 5' }
\prop_gput:Nnn \g__xpiano_notes_prop { Fst } { 6' }
\prop_gput:Nnn \g__xpiano_notes_prop { Gt }  { 7' }
\prop_gput:Nnn \g__xpiano_notes_prop { Gst } { 8' }
\prop_gput:Nnn \g__xpiano_notes_prop { At }  { 9' }
\prop_gput:Nnn \g__xpiano_notes_prop { Ast } { 10' }
\prop_gput:Nnn \g__xpiano_notes_prop { Bt }  { 11' }
\prop_gput:Nnn \g__xpiano_notes_prop { C }     { 0 }
\prop_gput:Nnn \g__xpiano_notes_prop { Ciss }  { 1 }
\prop_gput:Nnn \g__xpiano_notes_prop { Dess }  { 1 }
\prop_gput:Nnn \g__xpiano_notes_prop { D }     { 2 }
\prop_gput:Nnn \g__xpiano_notes_prop { Diss }  { 3 }
\prop_gput:Nnn \g__xpiano_notes_prop { Ess }   { 3 }
\prop_gput:Nnn \g__xpiano_notes_prop { E }     { 4 }
\prop_gput:Nnn \g__xpiano_notes_prop { F }     { 5 }
\prop_gput:Nnn \g__xpiano_notes_prop { Fiss }  { 6 }
\prop_gput:Nnn \g__xpiano_notes_prop { Gess }  { 6 }
\prop_gput:Nnn \g__xpiano_notes_prop { G }     { 7 }
\prop_gput:Nnn \g__xpiano_notes_prop { Giss }  { 8 }
\prop_gput:Nnn \g__xpiano_notes_prop { Ass }   { 8 }
\prop_gput:Nnn \g__xpiano_notes_prop { A }     { 9 }
\prop_gput:Nnn \g__xpiano_notes_prop { Aiss }  { 10 }
\prop_gput:Nnn \g__xpiano_notes_prop { Bess }  { 10 }
\prop_gput:Nnn \g__xpiano_notes_prop { B }     { 11 }
\prop_gput:Nnn \g__xpiano_notes_prop { C' }    { 0' }
\prop_gput:Nnn \g__xpiano_notes_prop { Ciss' } { 1' }
\prop_gput:Nnn \g__xpiano_notes_prop { Dess' } { 1' }
\prop_gput:Nnn \g__xpiano_notes_prop { D' }    { 2' }
\prop_gput:Nnn \g__xpiano_notes_prop { Diss' } { 3' }
\prop_gput:Nnn \g__xpiano_notes_prop { Ess' }  { 3' }
\prop_gput:Nnn \g__xpiano_notes_prop { E' }    { 4' }
\prop_gput:Nnn \g__xpiano_notes_prop { F' }    { 5' }
\prop_gput:Nnn \g__xpiano_notes_prop { Fiss' } { 6' }
\prop_gput:Nnn \g__xpiano_notes_prop { Gess' } { 6' }
\prop_gput:Nnn \g__xpiano_notes_prop { G' }    { 7' }
\prop_gput:Nnn \g__xpiano_notes_prop { Giss' } { 8' }
\prop_gput:Nnn \g__xpiano_notes_prop { Ass' }  { 8' }
\prop_gput:Nnn \g__xpiano_notes_prop { A' }    { 9' }
\prop_gput:Nnn \g__xpiano_notes_prop { Aiss' } { 10' }
\prop_gput:Nnn \g__xpiano_notes_prop { Bess' } { 10' }
\prop_gput:Nnn \g__xpiano_notes_prop { B' }    { 11' }
\prop_gput:Nnn \g__xpiano_notes_prop { C }   { 0 }
\prop_gput:Nnn \g__xpiano_notes_prop { Cs }  { 1 }
\prop_gput:Nnn \g__xpiano_notes_prop { D }   { 2 }
\prop_gput:Nnn \g__xpiano_notes_prop { Ds }  { 3 }
\prop_gput:Nnn \g__xpiano_notes_prop { E }   { 4 }
\prop_gput:Nnn \g__xpiano_notes_prop { F }   { 5 }
\prop_gput:Nnn \g__xpiano_notes_prop { Fs }  { 6 }
\prop_gput:Nnn \g__xpiano_notes_prop { G }   { 7 }
\prop_gput:Nnn \g__xpiano_notes_prop { Gs }  { 8 }
\prop_gput:Nnn \g__xpiano_notes_prop { A }   { 9 }
\prop_gput:Nnn \g__xpiano_notes_prop { As }  { 10 }
\prop_gput:Nnn \g__xpiano_notes_prop { B }   { 11 }
\prop_gput:Nnn \g__xpiano_notes_prop { C' }  { 0' }
\prop_gput:Nnn \g__xpiano_notes_prop { Cs' } { 1' }
\prop_gput:Nnn \g__xpiano_notes_prop { D' }  { 2' }
\prop_gput:Nnn \g__xpiano_notes_prop { Ds' } { 3' }
\prop_gput:Nnn \g__xpiano_notes_prop { E' }  { 4' }
\prop_gput:Nnn \g__xpiano_notes_prop { F' }  { 5' }
\prop_gput:Nnn \g__xpiano_notes_prop { Fs' } { 6' }
\prop_gput:Nnn \g__xpiano_notes_prop { G' }  { 7' }
\prop_gput:Nnn \g__xpiano_notes_prop { Gs' } { 8' }
\prop_gput:Nnn \g__xpiano_notes_prop { A' }  { 9' }
\prop_gput:Nnn \g__xpiano_notes_prop { As' } { 10' }
\prop_gput:Nnn \g__xpiano_notes_prop { B' }  { 11' }
\prop_gput:Nnn \g__xpiano_notes_prop { 0 }   { 0 }
\prop_gput:Nnn \g__xpiano_notes_prop { 1 }   { 1 }
\prop_gput:Nnn \g__xpiano_notes_prop { 2 }   { 2 }
\prop_gput:Nnn \g__xpiano_notes_prop { 3 }   { 3 }
\prop_gput:Nnn \g__xpiano_notes_prop { 4 }   { 4 }
\prop_gput:Nnn \g__xpiano_notes_prop { 5 }   { 5 }
\prop_gput:Nnn \g__xpiano_notes_prop { 6 }   { 6 }
\prop_gput:Nnn \g__xpiano_notes_prop { 7 }   { 7 }
\prop_gput:Nnn \g__xpiano_notes_prop { 8 }   { 8 }
\prop_gput:Nnn \g__xpiano_notes_prop { 9 }   { 9 }
\prop_gput:Nnn \g__xpiano_notes_prop { 10 }  { 10 }
\prop_gput:Nnn \g__xpiano_notes_prop { 11 }  { 11 }
\prop_gput:Nnn \g__xpiano_notes_prop { 0' }  { 0' }
\prop_gput:Nnn \g__xpiano_notes_prop { 1' }  { 1' }
\prop_gput:Nnn \g__xpiano_notes_prop { 2' }  { 2' }
\prop_gput:Nnn \g__xpiano_notes_prop { 3' }  { 3' }
\prop_gput:Nnn \g__xpiano_notes_prop { 4' }  { 4' }
\prop_gput:Nnn \g__xpiano_notes_prop { 5' }  { 5' }
\prop_gput:Nnn \g__xpiano_notes_prop { 6' }  { 6' }
\prop_gput:Nnn \g__xpiano_notes_prop { 7' }  { 7' }
\prop_gput:Nnn \g__xpiano_notes_prop { 8' }  { 8' }
\prop_gput:Nnn \g__xpiano_notes_prop { 9' }  { 9' }
\prop_gput:Nnn \g__xpiano_notes_prop { 10' } { 10' }
\prop_gput:Nnn \g__xpiano_notes_prop { 11' } { 11' }
\cs_new_protected:Npn \xpiano_keyboard:nn #1 #2
 {
  \group_begin:
  \keys_set:nn { piano } { #1 }
  \bool_if:NTF \l__xpiano_ext_bool
   {
    \tl_set:Nx \l__xpiano_width_tl
     {
      \bool_if:NTF \l__xpiano_single_bool { 8 } { 15 }
     }
   }
   {
    \tl_set:Nx \l__xpiano_width_tl
     {
      \bool_if:NTF \l__xpiano_single_bool { 7 } { 14 }
     }
   }
  %% Draw the keyboard
  \setlength{\unitlength}{\l__xpiano_size_dim}
  \begin{picture}(\l__xpiano_width_tl,\l__xpiano_height_tl)
  % White keys
  \multiput(0,0)(1,0){\l__xpiano_width_tl}{\line(0,1){\l__xpiano_height_tl}}

  % Boundary
  \put(0,0){\line(0,1){\l__xpiano_height_tl}}
  \put(0,0){\line(1,0){\l__xpiano_width_tl}}
  \put(\l__xpiano_width_tl,0){\line(0,1){\l__xpiano_height_tl}}
  \put(0,\l__xpiano_height_tl){\line(1,0){\l__xpiano_width_tl}}

  % Black keys
  \linethickness{.6\l__xpiano_size_dim}
  \multiput(1,\l__xpiano_height_tl)(1,0){2}{\line(0,-1){\fp_eval:n {\l__xpiano_ratio_fp*\l__xpiano_height_tl}}}
  \multiput(4,\l__xpiano_height_tl)(1,0){3}{\line(0,-1){\fp_eval:n {\l__xpiano_ratio_fp*\l__xpiano_height_tl}}}
  \bool_if:NF \l__xpiano_single_bool
   {
    \multiput(8,\l__xpiano_height_tl)(1,0){2}{\line(0,-1){\fp_eval:n {\l__xpiano_ratio_fp*\l__xpiano_height_tl}}}
    \multiput(11,\l__xpiano_height_tl)(1,0){3}{\line(0,-1){\fp_eval:n {\l__xpiano_ratio_fp*\l__xpiano_height_tl}}}
   }
  % The notes
  \color{\l__xpiano_color_tl}
  \clist_map_inline:nn { #2 }
   {
    \__xpiano_do_key:n { ##1 }
   }
  \end{picture}
  \group_end:
 }
\cs_new_protected:Npn \__xpiano_add_note:nn #1 #2
 {
  \put(#2){\circle*{0.5}}
  \bool_if:NT \l__xpiano_numbers_bool
   {
    \put(#2){\makebox(0,0){\normalfont\color{\l__xpiano_numbercolor_tl}\l__xpiano_font_tl #1}}
   }
 }

\cs_new_protected:Npn \__xpiano_do_key:n #1
 {
  \str_case:fn { \prop_item:Nn \g__xpiano_notes_prop {#1} }
   {
    {0}{\__xpiano_add_note:nn {0}{0.5,0.5}}
    {2}{\__xpiano_add_note:nn {2}{1.5,0.5}}
    {4}{\__xpiano_add_note:nn {4}{2.5,0.5}}
    {5}{\__xpiano_add_note:nn {5}{3.5,0.5}}
    {7}{\__xpiano_add_note:nn {7}{4.5,0.5}}
    {9}{\__xpiano_add_note:nn {9}{5.5,0.5}}
    {11}{\__xpiano_add_note:nn {\l__xpiano_eleven_tl}{6.5,0.5}}
    {0'}{\__xpiano_add_note:nn {0}{7.5,0.5}}
    {2'}{\__xpiano_add_note:nn {2}{8.5,0.5}}
    {4'}{\__xpiano_add_note:nn {4}{9.5,0.5}}
    {5'}{\__xpiano_add_note:nn {5}{10.5,0.5}}
    {7'}{\__xpiano_add_note:nn {7}{11.5,0.5}}
    {9'}{\__xpiano_add_note:nn {9}{12.5,0.5}}
    {11'}{\__xpiano_add_note:nn {\l__xpiano_eleven_tl}{13.5,0.5}}
    {1}{\__xpiano_add_note:nn {1}{1,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {3}{\__xpiano_add_note:nn {3}{2,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {6}{\__xpiano_add_note:nn {6}{4,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {8}{\__xpiano_add_note:nn {8}{5,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {10}{\__xpiano_add_note:nn {\l__xpiano_ten_tl}{6,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {1'}{\__xpiano_add_note:nn {1}{8,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {3'}{\__xpiano_add_note:nn {3}{9,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {6'}{\__xpiano_add_note:nn {6}{11,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {8'}{\__xpiano_add_note:nn {8}{12,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
    {10'}{\__xpiano_add_note:nn {\l__xpiano_ten_tl}{13,\fp_eval:n {0.5+(1-\l__xpiano_ratio_fp)*\l__xpiano_height_tl}}}
   }
 }
\cs_generate_variant:Nn \str_case:nn {f}
%% Copyright (C) 2015 by
%%   Enrico Gregorio <enrico DOT gregorio AT univr DOT it>
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%%    http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%%   Enrico Gregorio.
%% 
%% This work consists of the file  xpiano.dtx
%%           and the derived files xpiano.pdf,
%%                                 xpiano.sty and
%%                                 xpiano.ins.
%%
%% End of file `xpiano.sty'.
