\font\chFont=cmbx10 scaled \magstep0
\font\chFontRm=cmbx8 scaled \magstep0
\font\chFontIdx=cmbx7 scaled \magstep0


\def\ch.#1.{\csname  ch:#1\endcsname}
\def\defch.#1.{\expandafter \def \csname ch:#1\endcsname}

\def\chFlat{$\scriptstyle\flat$}
\def\chSharp{$\scriptstyle\sharp$}
%\def\chDim{$\circ$}
\def\chDim{dim}
\def\chMaj{$\scriptstyle\bigtriangleup$}
%\def\chMaj{maj}

%
% Base chords
%
\def\chVerticalAlign{13}% basic vertical align \internotes
\def\chBase#1{\zchar{\chVerticalAlign}{\chFont #1}}

%
% Macros for chords without sharp or flat
% it means C, D, E, F, G, A, B
%
\def\chX#1{\chBase{#1}}
\def\chXOneParam#1#2{\chBase{#1{\chFontRm #2}}}
\def\chXm#1{\chXOneParam{#1}{m}}
\def\chXPlus#1{\chXOneParam{#1}{+}}
\def\chXSus#1{\chXOneParam{#1}{sus}}
\def\chXDim#1{\chXOneParam{#1}{\chDim}}
\def\chXMaj#1{\chXOneParam{#1}{\chMaj}}

\def\chXOneParamUpper#1#2{\chBase{#1\lower-1ex\hbox{\chFontIdx #2}}}
%\def\chXDim#1{\chXOneParamUpper{#1}{\chDim}}
\def\chXSix#1{\chXOneParamUpper{#1}{6}}
\def\chXSeven#1{\chXOneParamUpper{#1}{7}}
\def\chXNine#1{\chXOneParamUpper{#1}{9}}
\def\chXNineFlat#1{\chXOneParamUpper{#1}{\chFontIdx 9\chFlat}}

\def\chXTwoParams#1#2#3{\chBase{#1{\chFontRm #2}\lower-1ex\hbox{\chFontIdx #3}}}
\def\chXmSeven#1{\chXTwoParams{#1}{m}{7}}
\def\chXmSix#1{\chXTwoParams{#1}{m}{6}}
\def\chXmFiveFlat#1{\chXTwoParams{#1}{m}{5\chFlat}}
\def\chXSusSeven#1{\chXTwoParams{#1}{sus}{7}}

\def\chXmSevenFiveFlat#1{\chBase{#1{\chFontRm m}\lower0.5ex\vbox{\baselineskip=1ex\hbox{\chFontIdx 7}\hbox{\chFontIdx 5\chFlat}}}}
%\def\chXmSevenFiveFlat#1{\chBase{#1{\chFontRm m}\lower0.5ex\vbox{\baselineskip=1ex\hbox{\chFontIdx 7}\hbox{\chFontIdx 5\chFlat}}}}


%
% Macros for chords with flat
% it means Ef, Af, Bf
%
\def\chXFlat#1{\chXOneParamUpper{#1}{\chFlat}}

\def\chXFlatOneParam#1#2{\chBase{#1\lower-1.1ex\hbox{\chFlat}\kern-0.3em\hbox{\chFontRm #2}}}
\def\chXFlatm#1{\chXFlatOneParam{#1}{m}}
\def\chXFlatPlus#1{\chXFlatOneParam{#1}{+}}
\def\chXFlatSus#1{\chXFlatOneParam{#1}{sus}}
\def\chXFlatDim#1{\chXFlatOneParam{#1}{\chDim}}
\def\chXFlatMaj#1{\chXFlatOneParam{#1}{\chMaj}}


\def\chXFlatOneParamUpper#1#2{\chXOneParamUpper{#1}{\chFlat\kern 0.2ex\chFontIdx #2}}
\def\chXFlatSix#1{\chXFlatOneParamUpper{#1}{6}}
\def\chXFlatSeven#1{\chXFlatOneParamUpper{#1}{7}}
\def\chXFlatNine#1{\chXFlatOneParamUpper{#1}{9}}
\def\chXFlatNineFlat#1{\chXFlatOneParamUpper{#1}{9\chFlat}}

\def\chXFlatTwoParams#1#2#3{\chBase{#1\lower-1.1ex\hbox{\chFlat}\kern-0.3em\hbox{\chFontRm #2}\lower-1ex\hbox{\chFontIdx #3}}}
\def\chXFlatmSeven#1{\chXFlatTwoParams{#1}{m}{7}}
\def\chXFlatmSix#1{\chXFlatTwoParams{#1}{m}{6}}
\def\chXFlatmFiveFlat#1{\chXFlatTwoParams{#1}{m}{5\chFlat}}
\def\chXFlatSusSeven#1{\chXFlatTwoParams{#1}{sus}{7}}

\def\chXFlatmSevenFiveFlat#1{\chBase{#1\lower-1.1ex\hbox{\chFlat}\kern-0.3em{\chFontRm m\lower0.5ex\vbox{\baselineskip=1ex\hbox{\chFontIdx 7}\hbox{\chFontIdx 5\chFlat}}}}}

%
% Macros for chords with sharp
% it means Cs, Fs
%
\def\chXSharp#1{\chXOneParamUpper{#1}{\chSharp}}

\def\chXSharpOneParam#1#2{\chBase{#1\lower-1.4ex\hbox{\chSharp}\kern-0.3em\hbox{\chFontRm #2}}}
\def\chXSharpm#1{\chXSharpOneParam{#1}{m}}
\def\chXSharpPlus#1{\chXSharpOneParam{#1}{+}}
\def\chXSharpSus#1{\chXSharpOneParam{#1}{sus}}
\def\chXSharpDim#1{\chXSharpOneParam{#1}{\chDim}}
\def\chXSharpMaj#1{\chXSharpOneParam{#1}{\chMaj}}


\def\chXSharpOneParamUpper#1#2{\chXOneParamUpper{#1}{\chFontIdx\chSharp\kern 0.2ex#2}}
\def\chXSharpSix#1{\chXSharpOneParamUpper{#1}{6}}
\def\chXSharpSeven#1{\chXSharpOneParamUpper{#1}{7}}
\def\chXSharpNine#1{\chXSharpOneParamUpper{#1}{9}}
\def\chXSharpNineFlat#1{\chXSharpOneParamUpper{#1}{9\chFlat}}

\def\chXSharpTwoParams#1#2#3{\chBase{#1\lower-1.4ex\hbox{\chSharp}\kern-0.3em\hbox{\chFontRm #2}\lower-1ex\hbox{\chFontIdx #3}}}
\def\chXSharpmSeven#1{\chXSharpTwoParams{#1}{m}{7}}
\def\chXSharpmSix#1{\chXSharpTwoParams{#1}{m}{6}}
\def\chXSharpmFiveFlat#1{\chXSharpTwoParams{#1}{m}{5\chFlat}}
\def\chXSharpSusSeven#1{\chXSharpTwoParams{#1}{sus}{7}}

\def\chXSharpmSevenFiveFlat#1{\chBase{#1\lower-1.4ex\hbox{\chSharp}\kern-0.3em{\chFontRm m\lower0.5ex\vbox{\baselineskip=1ex\hbox{\chFontIdx 7}\hbox{\chFontIdx 5\chFlat}}}}}

%
% C
%
\defch.C.{\chX{C}}
\defch.Cm.{\chXm{C}}
\defch.C+.{\chXPlus{C}}
\defch.C4.{\chXSus{C}}
\defch.Cdim.{\chXDim{C}}
\defch.Cmaj.{\chXMaj{C}}
\defch.C6.{\chXSix{C}}
\defch.C7.{\chXSeven{C}}
\defch.C9.{\chXNine{C}}
\defch.C9f.{\chXNineFlat{C}}
\defch.Cm7.{\chXmSeven{C}}
\defch.Cm6.{\chXmSix{C}}
\defch.Cm5f.{\chXmFiveFlat{C}}
\defch.C47.{\chXSusSeven{C}}
\defch.Cm75f.{\chXmSevenFiveFlat{C}}

%
% D
%
\defch.D.{\chX{D}}
\defch.Dm.{\chXm{D}}
\defch.D+.{\chXPlus{D}}
\defch.D4.{\chXSus{D}}
\defch.Ddim.{\chXDim{D}}
\defch.Dmaj.{\chXMaj{D}}
\defch.D6.{\chXSix{D}}
\defch.D7.{\chXSeven{D}}
\defch.D9.{\chXNine{D}}
\defch.D9f.{\chXNineFlat{D}}
\defch.Dm7.{\chXmSeven{D}}
\defch.Dm6.{\chXmSix{D}}
\defch.Dm5f.{\chXmFiveFlat{D}}
\defch.D47.{\chXSusSeven{D}}
\defch.Dm75f.{\chXmSevenFiveFlat{D}}

%
% E
%
\defch.E.{\chX{E}}
\defch.Em.{\chXm{E}}
\defch.E+.{\chXPlus{E}}
\defch.E4.{\chXSus{E}}
\defch.Edim.{\chXDim{E}}
\defch.Emaj.{\chXMaj{E}}
\defch.E6.{\chXSix{E}}
\defch.E7.{\chXSeven{E}}
\defch.E9.{\chXNine{E}}
\defch.E9f.{\chXNineFlat{E}}
\defch.Em7.{\chXmSeven{E}}
\defch.Em6.{\chXmSix{E}}
\defch.Em5f.{\chXmFiveFlat{E}}
\defch.E47.{\chXSusSeven{E}}
\defch.Em75f.{\chXmSevenFiveFlat{E}}

%
% F
%
\defch.F.{\chX{F}}
\defch.Fm.{\chXm{F}}
\defch.F+.{\chXPlus{F}}
\defch.F4.{\chXSus{F}}
\defch.Fdim.{\chXDim{F}}
\defch.Fmaj.{\chXMaj{F}}
\defch.F6.{\chXSix{F}}
\defch.F7.{\chXSeven{F}}
\defch.F9.{\chXNine{F}}
\defch.F9f.{\chXNineFlat{F}}
\defch.Fm7.{\chXmSeven{F}}
\defch.Fm6.{\chXmSix{F}}
\defch.Fm5f.{\chXmFiveFlat{F}}
\defch.F47.{\chXSusSeven{F}}
\defch.Fm75f.{\chXmSevenFiveFlat{F}}

%
% G
%
\defch.G.{\chX{G}}
\defch.Gm.{\chXm{G}}
\defch.G+.{\chXPlus{G}}
\defch.G4.{\chXSus{G}}
\defch.Gdim.{\chXDim{G}}
\defch.Gmaj.{\chXMaj{G}}
\defch.G6.{\chXSix{G}}
\defch.G7.{\chXSeven{G}}
\defch.G9.{\chXNine{G}}
\defch.G9f.{\chXNineFlat{G}}
\defch.Gm7.{\chXmSeven{G}}
\defch.Gm6.{\chXmSix{G}}
\defch.Gm5f.{\chXmFiveFlat{G}}
\defch.G47.{\chXSusSeven{G}}
\defch.Gm75f.{\chXmSevenFiveFlat{G}}

%
% A
%
\defch.A.{\chX{A}}
\defch.Am.{\chXm{A}}
\defch.A+.{\chXPlus{A}}
\defch.A4.{\chXSus{A}}
\defch.Adim.{\chXDim{A}}
\defch.Amaj.{\chXMaj{A}}
\defch.A6.{\chXSix{A}}
\defch.A7.{\chXSeven{A}}
\defch.A9.{\chXNine{A}}
\defch.A9f.{\chXNineFlat{A}}
\defch.Am7.{\chXmSeven{A}}
\defch.Am6.{\chXmSix{A}}
\defch.Am5f.{\chXmFiveFlat{A}}
\defch.A47.{\chXSusSeven{A}}
\defch.Am75f.{\chXmSevenFiveFlat{A}}

%
% Cs
%
\defch.Cs.{\chXSharp{C}}
\defch.Csm.{\chXSharpm{C}}
\defch.Cs+.{\chXSharpPlus{C}}
\defch.Cs4.{\chXSharpSus{C}}
\defch.Csdim.{\chXSharpDim{C}}
\defch.Csmaj.{\chXSharpMaj{C}}
\defch.Cs6.{\chXSharpSix{C}}
\defch.Cs7.{\chXSharpSeven{C}}
\defch.Cs9.{\chXSharpNine{C}}
\defch.Cs9f.{\chXSharpNineFlat{C}}
\defch.Csm7.{\chXSharpmSeven{C}}
\defch.Csm6.{\chXSharpmSix{C}}
\defch.Csm5f.{\chXSharpmFiveFlat{C}}
\defch.Cs47.{\chXSharpSusSeven{C}}
\defch.Csm75f.{\chXSharpmSevenFiveFlat{C}}

%
% Fs
%
\defch.Fs.{\chXSharp{F}}
\defch.Fsm.{\chXSharpm{F}}
\defch.Fs+.{\chXSharpPlus{F}}
\defch.Fs4.{\chXSharpSus{F}}
\defch.Fsdim.{\chXSharpDim{F}}
\defch.Fsmaj.{\chXSharpMaj{F}}
\defch.Fs6.{\chXSharpSix{F}}
\defch.Fs7.{\chXSharpSeven{F}}
\defch.Fs9.{\chXSharpNine{F}}
\defch.Fs9f.{\chXSharpNineFlat{F}}
\defch.Fsm7.{\chXSharpmSeven{F}}
\defch.Fsm6.{\chXSharpmSix{F}}
\defch.Fsm5f.{\chXSharpmFiveFlat{F}}
\defch.Fs47.{\chXSharpSusSeven{F}}
\defch.Fsm75f.{\chXSharpmSevenFiveFlat{F}}

%
% Ef
%
\defch.Ef.{\chXFlat{E}}
\defch.Efm.{\chXFlatm{E}}
\defch.Ef+.{\chXFlatPlus{E}}
\defch.Ef4.{\chXFlatSus{E}}
\defch.Efdim.{\chXFlatDim{E}}
\defch.Efmaj.{\chXFlatMaj{E}}
\defch.Ef6.{\chXFlatSix{E}}
\defch.Ef7.{\chXFlatSeven{E}}
\defch.Ef9.{\chXFlatNine{E}}
\defch.Ef9f.{\chXFlatNineFlat{E}}
\defch.Efm7.{\chXFlatmSeven{E}}
\defch.Efm6.{\chXFlatmSix{E}}
\defch.Efm5f.{\chXFlatmFiveFlat{E}}
\defch.Ef47.{\chXFlatSusSeven{E}}
\defch.Efm75f.{\chXFlatmSevenFiveFlat{E}}

%
% Af
%
\defch.Af.{\chXFlat{A}}
\defch.Afm.{\chXFlatm{A}}
\defch.Af+.{\chXFlatPlus{A}}
\defch.Af4.{\chXFlatSus{A}}
\defch.Afdim.{\chXFlatDim{A}}
\defch.Afmaj.{\chXFlatMaj{A}}
\defch.Af6.{\chXFlatSix{A}}
\defch.Af7.{\chXFlatSeven{A}}
\defch.Af9.{\chXFlatNine{A}}
\defch.Af9f.{\chXFlatNineFlat{A}}
\defch.Afm7.{\chXFlatmSeven{A}}
\defch.Afm6.{\chXFlatmSix{A}}
\defch.Afm5f.{\chXFlatmFiveFlat{A}}
\defch.Af47.{\chXFlatSusSeven{A}}
\defch.Afm75f.{\chXFlatmSevenFiveFlat{A}}

%
% B
%
\defch.B.{\chX{H}}
\defch.Bm.{\chXm{H}}
\defch.B+.{\chXPlus{H}}
\defch.B4.{\chXSus{H}}
\defch.Bdim.{\chXDim{H}}
\defch.Bmaj.{\chXMaj{H}}
\defch.B6.{\chXSix{H}}
\defch.B7.{\chXSeven{H}}
\defch.B9.{\chXNine{H}}
\defch.B9f.{\chXNineFlat{H}}
\defch.Bm7.{\chXmSeven{H}}
\defch.Bm6.{\chXmSix{H}}
\defch.Bm5f.{\chXmFiveFlat{H}}
\defch.B47.{\chXSusSeven{H}}
\defch.Bm75f.{\chXmSevenFiveFlat{H}}

%
% Bf
%
\defch.Bf.{\chX{B}}
\defch.Bfm.{\chXm{B}}
\defch.Bf+.{\chXPlus{B}}
\defch.Bf4.{\chXSus{B}}
\defch.Bfdim.{\chXDim{B}}
\defch.Bfmaj.{\chXMaj{B}}
\defch.Bf6.{\chXSix{B}}
\defch.Bf7.{\chXSeven{B}}
\defch.Bf9.{\chXNine{B}}
\defch.Bf9f.{\chXNineFlat{B}}
\defch.Bfm7.{\chXmSeven{B}}
\defch.Bfm6.{\chXmSix{B}}
\defch.Bfm5f.{\chXmFiveFlat{B}}
\defch.Bf47.{\chXSusSeven{B}}
\defch.Bfm75f.{\chXmSevenFiveFlat{B}}
