• トップページ
  • project
    • 全ての作品
    • 全てのタグ
  • blog
    • 全ての記事
    • 全てのタグ
  • tag
    • 全てのタグ
    • 全ての作品タグ
    • 全ての記事タグ
  • about
    • p進大好きサークル photo

      p進大好きサークル

      p進大好きサークルのHPです。

    • もっと読む
    • Twitter
    • pixiv
    • 巨大数Wiki

機能和声の実装 - 音階

2020/01/25

トップページ 前の記事 親記事 次の記事

twitter pixiv yukicoder お題箱 マシュマロ

数式での翻訳

英語のアルファベットを記号とする文字列の集合 \[ \textrm{OnKai} = \{\textrm{ChouOnKai},\textrm{WaSeiTekiTanOnKai},\textrm{ShiZenTanOnKai}\} \] に属する文字列を音階と呼びます。実際にはこの他にも\(\textrm{SenRitsuTekiTanOnKai}\)等の様々な音階がありますが、ここでは扱わないことにします。完全に公理的集合論で定義をしたい場合は、幹音の記事において導入した規則で英語のアルファベットを自然数にコードすることで、\(\mathbb{N}\)を記号の集合とする文字列の集合に翻訳して下さい。

また写像 \[ \begin{align} \textrm{PitchClassTable} \colon \textrm{OnKai} \times \textrm{KaiMei} & \to \textrm{PitchClass} \\
(s,n) & \mapsto \textrm{PitchClassTable}(s,n) \end{align} \] を以下のように定めます:

  1. \(s = \textrm{ChouOnKai}\)とする。
    1. \(n = \textrm{I}\)ならば、\(\textrm{PitchClassTable}(s,n) = 0\)である。
    2. \(n = \textrm{II}\)ならば、\(\textrm{PitchClassTable}(s,n) = 2\)である。
    3. \(n = \textrm{III}\)ならば、\(\textrm{PitchClassTable}(s,n) = 4\)である。
    4. \(n = \textrm{IV}\)ならば、\(\textrm{PitchClassTable}(s,n) = 5\)である。
    5. \(n = \textrm{V}\)ならば、\(\textrm{PitchClassTable}(s,n) = 7\)である。
    6. \(n = \textrm{VI}\)ならば、\(\textrm{PitchClassTable}(s,n) = 9\)である。
    7. \(n = \textrm{VII}\)ならば、\(\textrm{PitchClassTable}(s,n) = 11\)である。
  2. \(s = \textrm{WaSeiTekiTanOnKai}\)とする。
    1. \(n = \textrm{I}\)ならば、\(\textrm{PitchClassTable}(s,n) = 0\)である。
    2. \(n = \textrm{II}\)ならば、\(\textrm{PitchClassTable}(s,n) = 2\)である。
    3. \(n = \textrm{III}\)ならば、\(\textrm{PitchClassTable}(s,n) = 3\)である。
    4. \(n = \textrm{IV}\)ならば、\(\textrm{PitchClassTable}(s,n) = 5\)である。
    5. \(n = \textrm{V}\)ならば、\(\textrm{PitchClassTable}(s,n) = 7\)である。
    6. \(n = \textrm{VI}\)ならば、\(\textrm{PitchClassTable}(s,n) = 8\)である。
    7. \(n = \textrm{VII}\)ならば、\(\textrm{PitchClassTable}(s,n) = 11\)である。
  3. \(s = \textrm{ShiZenTekiTanOnKai}\)とする。
    1. \(n = \textrm{I}\)ならば、\(\textrm{PitchClassTable}(s,n) = 0\)である。
    2. \(n = \textrm{II}\)ならば、\(\textrm{PitchClassTable}(s,n) = 2\)である。
    3. \(n = \textrm{III}\)ならば、\(\textrm{PitchClassTable}(s,n) = 3\)である。
    4. \(n = \textrm{IV}\)ならば、\(\textrm{PitchClassTable}(s,n) = 5\)である。
    5. \(n = \textrm{V}\)ならば、\(\textrm{PitchClassTable}(s,n) = 7\)である。
    6. \(n = \textrm{VI}\)ならば、\(\textrm{PitchClassTable}(s,n) = 8\)である。
    7. \(n = \textrm{VII}\)ならば、\(\textrm{PitchClassTable}(s,n) = 10\)である。

この時、音階\(s\)を固定するごとに得られる写像 \[ \begin{align} \mathbb{Z} & \to \textrm{PitchClass} \\
n & \mapsto \textrm{PitchClassTable}(s,n + 7 \mathbb{Z}) \end{align} \] は\(12\)を法とする周期\(7\)の数列を定め、その階差数列は\(s = \textrm{ChouOnKai}\)ならば\(2,2,1,2,2,2,1\)の繰り返しとなり、一方で\(s = \textrm{WaseiTekiTanOnKai}\)ならば\(2,1,2,2,1,3,1\)の繰り返しとなります。

C++での宣言

音階のクラスおよび関係する関数たちを以下のように宣言します。


class OnKai
{

private:
  string m_scale;
  PitchClass m_I;
  PitchClass m_II;
  PitchClass m_III;
  PitchClass m_IV;
  PitchClass m_V;
  PitchClass m_VI;
  PitchClass m_VII;

public:
  inline OnKai( const string& scale , const int& I , const int& II , const int& III , const int& IV , const int& V , const int& VI , const int& VII ) noexcept;
  
  inline const string& Display() const noexcept;
  
  const PitchClass& PitchClassTable( const KaiMei& N ) const noexcept;

};

inline bool operator==( const OnKai& N1 , const OnKai& N2 ) noexcept;
inline bool operator!=( const OnKai& N1 , const OnKai& N2 ) noexcept;

const OnKai& ChouOnKai() noexcept;
const OnKai& WaSeiTekiTanOnKai() noexcept;
const OnKai& ShiZenTanOnKai() noexcept;

C++での定義

実際の実装例についてはこちらをご覧下さい。実装においては以下の仕様を要請します。

  • inline OnKai::OnKai( const string& scale , const int& I , const int& II , const int& III , const int& IV , const int& V , const int& VI , const int& VII ) noexceptはメンバ初期化子リストm_scale( scale ) , m_I( I ) , m_II( II ) , m_III( III ) , m_IV( IV ) , m_V( V ) , m_VI( VI ) , m_VII( VII )で定める。
  • inline string OnKai::Display() const noexceptはreturn m_scaleと定める。
  • const PitchClass& PitchClassTable( const KaiMei& N ) const noexceptは、OnKai::m_I~OnKai::m_VIIのうちN.Represent()+1番目のメンバ変数への参照返しと定める。
  • クラスOnKaiに対する等号演算子は自然なものである。
  • const OnKai& ChouOnKai() noexceptはコンストラクタOnKai::OnKai( "ChouOnKai" , 0 , 2 , 4 , 5 , 7 , 9 , 11 )で構築されるconst OnKai型静的局所変数への参照返しと定める。
  • const OnKai& WaSeiTekiTanOnKai() noexceptはコンストラクタOnKai::OnKai( "WaSeiTekiTanOnKai" , 0 , 2 , 3 , 5 , 7 , 8 , 11 )で構築されるconst OnKai型静的局所変数への参照返しと定める。
  • const OnKai& ShiZenTanOnKai() noexceptはコンストラクタOnKai::OnKai( "ShiZenTanOnKai" , 0 , 2 , 3 , 5 , 7 , 8 , 10 )で構築されるconst OnKai型静的局所変数への参照返しと定める。
トップページ 前の記事 親記事 次の記事

twitter pixiv yukicoder お題箱 マシュマロ