Musixtex 中的钢琴 MIDI 鼓映射

Musixtex 中的钢琴 MIDI 鼓映射

需要在Musixtex中实现钢琴MIDI鼓映射,基本代码如下:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{musixtex} 
\usepackage{piano}
\usetikzlibrary{arrows.meta}
\tikzset{
blackkey/.style={
white, scale=0.8,
append after command={\pgfextra{\tikzset{every label/.append style={white, scale=0.8}}}}
}}
\begin{document}
\begin{tikzpicture}[
inner sep=1pt, 
every node/.style={circle, minimum width=14pt, font=\bf},
every label/.style={rectangle, label position=below, label distance=1pt, inner sep=0pt, font=\small}
]
\node[rectangle, anchor=south west, inner sep=0pt, outer sep=0pt, rotate=90,transform shape, shift={(0.03,0.3)}, font=\normalsize, scale=2] {\keyboard};
%\node[draw, label={Fun}] at (1,1) {C};
%\node[fill=orange, label={[white, scale=0.8]Fun}] at (1.5,2) {};
%\node[fill=red] at (2.5,2) {};
%\node[fill=orange, label={Fun}] at (2,1) {D};
%\node[draw=teal, very thick, fill=orange, label={Fun}] at (3,1) {E};
\node[label={R}] at (6,1) {A};
\node[label={M2}] at (7,1) {B};
\node[label={m3}] at (8,1) {C};
\node[label={P4}] at (9,1) {D};
\node[label={P5}] at (10,1) {E};
\node[label={m6}] at (11,1) {F};
\node[label={R(0)}] at (13,1) {A};
\node[blackkey, label={(M7)}] at (12.5,2.5) {G\#};
\draw[-Stealth]
(6,-0.2)    edge +(0,0.4) -- 
(7,-0.2)    edge +(0,0.4) --
(8,-0.2)    edge +(0,0.4) -- 
(9,-0.2)    edge +(0,0.4) -- 
(10,-0.2)   edge +(0,0.4) -- 
(11,-0.2)   edge +(0,0.4) -- 
(12.4,-0.2) edge +(0,1.4) --
(13,-0.2)   --   +(0,0.4);
\tikzset{every node/.style={font=\normalfont}}
\node at (6.5,-0.5)  {T};
\node at (7.5,-0.5)  {S};
\node at (8.5,-0.5)  {T};
\node at (9.5,-0.5)  {T};
\node at (10.5,-0.5) {S};
\node at (11.8,-0.5) {1.5T};
\node at (12.7,-0.5) {S};
\end{tikzpicture}
\end{document}

当前输出如下: 当前的

期望的输出如下: 期望

答案1

首先我要说的是,我对音乐一无所知musictex(而且对音乐了解不多)。所以,我在这里想做的只是用简单的 Ti 重现你的绘画Z。

我的想法是创建两个pics,一个用于黑键,另一个用于白键。这些pics 绘制键并放置标签(编号和鼓名称?)。然后我将其全部包装在一个\foreach宏中,但我需要对位置进行一些计算,以及一个记住它们的全局变量。

像这样:

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

% white key dimensons
\pgfmathsetmacro\x{3.5}  % width
\pgfmathsetmacro\y{0.95} % height
\pgfmathsetmacro\r{0.1}  % corner radius
\tikzset
{% pics
   pics/blackkey/.style 2 args={code=% #1 = number, #2 = label
   {% black key
     \filldraw[thick]   (0,\y/3) rectangle (-0.6*\x,-\y/3);
     \filldraw[gray!30] (0.1,\y/3) -| (\x,-\y/3) -- (0.1,-\y/3);
     \node[white] at    (-0.5*\x,0) {\bfseries\footnotesize #1};
     \node[right] at    (0,0)       {\strut\footnotesize #2};
   }},
   pics/whitekey/.style 2 args={code=% #1 = number, #2 = label
   {% white key
     \begin{scope}[on background layer]
       \draw[thick]   (0,\y) |- (\r-\x,0) arc (270:180:\r) -- (-\x,\y-\r) arc (180:90:\r) -- cycle;
       \draw[gray!30] (0.1,\y) -| (\x,0) -- (0.1,0);
     \end{scope}
     \node at  (-0.5*\x,0.5*\y) {\bfseries\footnotesize #1};
     \node[right] at (0,0.5*\y) {\strut\footnotesize #2};
   }},
}

\begin{document}
\lipsum[1][1-2]

\begin{figure}[ht]\centering\sffamily
\begin{tikzpicture}[line cap=round,line join=round]
% table header
\begin{scope}[shift={(0,0.5*\y)},x=\x cm,y=\y cm,]
  \draw[thick] (0,1) -- (0,0) -- (-1,1) -| (1,0) -| (-1,1);
  \node at (-0.75,0.35) {\bfseries KEY \#};
  \node[text width=\x cm,align=center] at (0.5,.5) {\bfseries General MIDI Drum Map};
\end{scope}
% table
\pgfmathsetmacro\LastKeyPosition{0}
\foreach[count=\ii from 35]\i in
{% Drums
   Acoustic Bass Drum,
   Bass Drum 1,
   Side Stick,
   Acoustic Snare,
   Hand Clap,
   Electric Snare,
   Low Floor Tom,
   Closed Hi-Hat,
   High Floor Tom,
   Pedal Hi-Hat,
   Low Tom,
   Open Hi-Hat 2,
   Low-Mid Tom,
   High-Mid Tom
%  ...
}
{% this stuff computes if a key is black (\k=0) or white (\k=1)
   \pgfmathtruncatemacro\j{mod(\ii-1,12)<4?mod(\ii-1,12)+2:mod(\ii-1,12)+1}
   \pgfmathtruncatemacro\k{\j<11?mod(\j,2):1}
   \ifnum\k=0% black key
     \pic at (0,-\LastKeyPosition) {blackkey={\ii}{\i}};
   \else% white key
     \pgfmathsetmacro\posy{\LastKeyPosition+\y}
     \pic at (0,-\posy) {whitekey={\ii}{\i}};
     \global\let\LastKeyPosition=\posy
   \fi
}
% First and last black keys
\pic at (0,0) {blackkey={}{}};
\pic at (0,-\LastKeyPosition) {blackkey={}{}};
\end{tikzpicture}
\end{figure}

\lipsum[2]
\end{document}

在此处输入图片描述

相关内容