音程 (Interval)

Takuichi Hirano

音名を整数に変換する

[Input]
オクターブ
音名 (c,c#,d,d#,e,f,f#,g,g#,a,a#,b)

[Output]
整数値

\(\(CDEFGABToInteger[Octave_, ABCNote_] := 
        Module[{}, 
NumNote = 
            Which[
\((ABCNote == "C")\)\  || \ \((ABCNote == "c")\), 
              1, 
\((ABCNote == "C#")\)\  || \ \((ABCNote == "c#")\)\  || \ \((ABCNote == "D-")\)\  || \ \((ABCNote == "d-")\), 
              2, 
\((ABCNote == "D")\)\  || \ \((ABCNote == "d")\), 
              3, 
\((ABCNote == "D#")\)\  || \ \((ABCNote == "d#")\)\  || \ \((ABCNote == "E-")\)\  || \ \((ABCNote == "e-")\), 
              4, 
\((ABCNote == "E")\)\  || \ \((ABCNote == "e")\), 
              5, 
\((ABCNote == "F")\)\  || \ \((ABCNote == "f")\), 
              6, 
\((ABCNote == "F#")\)\  || \ \((ABCNote == "f#")\)\  || \ \((ABCNote == "G-")\)\  || \ \((ABCNote == "g-")\), 
              7, 
\((ABCNote == "G")\)\  || \ \((ABCNote == "g")\), 
              8, 
\((ABCNote == "G#")\)\  || \ \((ABCNote == "g#")\)\  || \ \((ABCNote == "A-")\)\  || \ \((ABCNote == "a-")\), 
              9, 
\((ABCNote == "A")\)\  || \ \((ABCNote == "a")\), 
              10, 
\((ABCNote == "A#")\)\  || \ \((ABCNote == "a#")\)\  || \ \((ABCNote == "B-")\)\  || \ \((ABCNote == "b-")\), 
              11, 
\((ABCNote == "B")\)\  || \ \((ABCNote == "b")\), 12]; 
\((Octave - 1)\)*12 + 
            NumNote
];\)\)

音程に変換する



[Input]
オクターブ
音名 (c,c#,d,d#,e,f,f#,g,g#,a,a#,b)

[Output]
整数値

NoteWholeHalfTone[1] = {0, 0};
NoteWholeHalfTone[2] = {0, 1};
NoteWholeHalfTone[3] = {1, 0};
NoteWholeHalfTone[4] = {1, 1};
NoteWholeHalfTone[5] = {2, 0};
NoteWholeHalfTone[6] = {2, 1};
NoteWholeHalfTone[7] = {2, 2};
NoteWholeHalfTone[8] = {3, 1};
NoteWholeHalfTone[9] = {3, 2};
NoteWholeHalfTone[10] = {4, 1};
NoteWholeHalfTone[11] = {4, 2};
NoteWholeHalfTone[12] = {5, 1};

    
NoteWholeHalfTone[n_] := 
        NoteWholeHalfTone[n - 12] + {5, 2}  /;  (13 ≤ 
              n);

    
InvertInterval[WHTone1_, WHTone2_] := 
        Module[{},
];

NoteInterval[IntNote1_, IntNote2_]:=Module[{n1, n2},
  
a = 
              Min[IntegerPart[(IntNote1 - 1)/12], 
                IntegerPart[(IntNote2 - 1)/12]]; 
n1 = 
              IntNote1 - 12*a; 
n2 = 
              IntNote2 - 12*a; 

If[
              n1 > 12, 
              n1 -= 12*(IntegerPart[n1/12] - 1)]; 
If[
              n2 > 12, 
              n2 -= 12*(IntegerPart[n2/12] - 
                      1)]; 

If[
              Abs[n1 - n2 + 1] ≥ 12, 
If[
                n1 > n2, n1 -= 12]; 
If[n1 < n2, 
                n2 -= 12];
]; 

{n1, n2}
];

CDEFGABToInteger[3, "D"]

{CDEFGABToInteger[3, "B"], CDEFGABToInteger[4, "A"]}

NoteInterval[CDEFGABToInteger[3, "B"], 
      CDEFGABToInteger[4, "A"]]

NoteWholeHalfTone[CDEFGABToInteger[1, "b-"]] - 
      NoteWholeHalfTone[CDEFGABToInteger[1, "c#"]]