Skip to main content

Chord Romanizer

PyPI version

コード進行をローマ数字と機能ラベルへ変換するPythonライブラリです。 調を指定した通常解析、表示・MIDIマーカー用ラベル、複数の機能解釈、調・転調推定を利用できます。 解析本体はRustで実装されています。

インストール

python -m pip install chord-romanizer

Python 3.8以上に対応しています。新しく解析を始める場合は、修正版の規則を使う Romanizer.strict()を利用してください。

3分で使う

1. 調を指定してローマ数字へ変換する

from chord_romanizer import Romanizer

romanizer = Romanizer.strict(default_tonic="C")
results = romanizer.romanize_progression(["Dm7", "G7", "Cmaj7"])

print([result.roman for result in results])
# ['IIm7', 'V7', 'IM7']

1コードだけならromanize()を使います。

result = Romanizer.strict("G").romanize("B7/D#")

print(result.roman)
print(result.normalized_symbol)   # 表示向けスペリング
print(result.theoretical_symbol)  # 理論スペリング

2. 画面やMIDIマーカー向けのラベルを作る

display_progression()は、進行全体で選ばれたTop-1解釈を表示用にまとめます。 combined_labelはそのまま画面、ログ、MIDIテキストマーカーへ渡せます。

romanizer = Romanizer.strict("E")
display = romanizer.display_progression(
    ["Bm7", "Eaug/A#", "AM7", "G#aug/D", "C#m7"]
)

for item in display:
    print(item.combined_label)
Bm7 [ii7/IV|PD]
Eaug/Bb [bV7(9,#11)|subV/IV]
AM7 [IVM7|I/IV]
G#aug/D [bVII7(9,#11)|subV/vi]
C#m7 [vi7|i/vi]

入力位置と対応させる場合はevent_indexを使います。

markers = {
    item.event_index: item.combined_label
    for item in romanizer.display_progression(progression)
}

AnalysisDisplayの主なフィールドは次のとおりです。

フィールド 用途 例
combined_label 完成済み表示 Eaug/Bb [bV7(9,#11)|subV/IV]
symbol 表示向けコード名 Eaug/Bb
theoretical_symbol 理論上のスペリング Eaug/Bb
global_label 全体調から見た度数 bV7(9,#11)
local_label 一時的な調での度数 ii7/IV, I/IV
function_label 機能 subV/IV, SDm, D
role_label 大分類 T, PD, D, S, NF
analysis_label 角括弧内だけの表示 bV7(9,#11)|subV/IV
event_index 元の進行での位置 1

3. 必要なAPIを選ぶ

やりたいこと API
1コードを解析する romanize()
コード列をローマ数字へ変換する romanize_progression()
詳細な解析結果を得る annotate_progression()
表示・MIDI用ラベルを得る display_progression()
N.C.や境界を含めて入力位置を保つ annotate_events()
機能的に異なる候補を比較する analyze_top_k_interpretations()
調・転調・機能をまとめて推定する analyze_keys_and_functions()

コード表記を表示用と保存用に分ける

annotate_progression()の結果では、コード表記を次のように使い分けます。

  • normalized_symbol: 画面やMIDI表示向け
  • theoretical_symbol: 理論表記の保存向け
  • symbol_fixed: normalized_symbolと同じ値を返す互換フィールド
  • chord.original_symbol: 入力された表記

simplify_accidentals=Trueでは、複重変化記号を表示しやすい異名同音へ置き換えます。 理論表記は失われません。

romanizer = Romanizer.strict("Db", simplify_accidentals=True)
item = romanizer.display_progression(["A"])[0]

print(item.symbol)              # A
print(item.theoretical_symbol)  # Bbb
print(item.global_label)        # bVI

理論表記を保存して画面だけ簡略化する場合は、同じ結果の theoretical_symbolとsymbolをそれぞれ保存・表示へ割り当てます。

ルートとslash bassは一組として綴りを決定します。たとえばG調のF#/G#は、 rootだけを異名同音にしてGb/G#とはせず、Gb/Ab [bII9sus4|S]と表示します。

詳細な解析結果を使う

annotate_progression()は、表示文字列へまとめる前の結果を返します。

results = Romanizer.strict("C").annotate_progression(
    ["Em7-5", "Eb7", "Dm7"]
)

for result in results:
    print(result.normalized_symbol, result.roman)
    for classification in result.harmonic_classifications:
        print(
            classification.role,
            classification.dominant_relation,
            classification.perspective,
        )

代表的なフィールド:

  • roman: 基本のローマ数字
  • alter: 文脈から得た拡張度数表記
  • normalized_symbol, theoretical_symbol: コードスペリング
  • harmonic_classifications: 役割、dominant関係、借用元、局所調
  • functional_interpretations: Blackadderを含むコード機能候補

複数の解釈を比較する

単一の表示結果ではなく、曖昧性を残して確認したい場合に使います。

romanizer = Romanizer.strict("B")
paths = romanizer.analyze_top_k_interpretations(
    ["Daug/C", "B"],
    k=3,
)

for path in paths:
    print("score:", path.total_score)
    for selection in path.selections:
        print(selection.event_index, selection.label, selection.blackadder)

paths[0]が最上位です。display_progression()も同じTop-1経路を使うため、 画面の機能ラベルと解析で選ばれた候補が食い違いません。

通常はanalyze_top_k_interpretations()を使用してください。 表記だけ異なる候補も含む低水準の経路が必要な場合に限りanalyze_top_k()を使います。

調や転調も推定する

調が既知ならglobal_keyを指定します。

paths = Romanizer.strict().analyze_keys_and_functions(
    ["C", "Am7", "D7", "G", "C", "D7", "G"],
    global_key="C",
    global_mode="major",
    k=5,
)

best = paths[0]
for selection in best.selections:
    print(selection.event_index, selection.active_key, selection.scope)

for span in best.modulations:
    print(span.from_key, "->", span.to_key, span.mechanism)

調も不明な場合はglobal_keyを省略します。

paths = Romanizer.strict().analyze_keys_and_functions(
    ["Dm7", "G7", "Cmaj7"],
    k=3,
)
print(paths[0].global_key)

詳しい転調判定はdocs/MODULATION.md、 長い範囲にまたがるdominant解決は docs/HARMONIC_MEMORY.mdを参照してください。

コードごとに調を指定する

(コード, 調)のタプルを渡します。

results = Romanizer.strict("C").romanize_progression(
    [
        ("C", "C"),
        ("F", "C"),
        ("Dm7", "F"),
        ("G7", "F"),
    ]
)

調の指定が変わる位置は、StrictV1では既定で文脈の境界になります。

N.C.とセクション境界を扱う

from chord_romanizer import Boundary, Romanizer

progression = ["Dm7", "N.C.", Boundary("chorus"), "G7"]
romanizer = Romanizer.strict("C")

# コードだけを返す。N.C.と境界は省略する。
chords = romanizer.annotate_progression(progression)

# 入力と同じ長さで返す。N.C.と境界も確認できる。
events = romanizer.annotate_events(progression)

N.C.は短い休符として扱い、前後の和声文脈を接続します。 長い空白、セクション変更などで文脈を切る場合はBoundaryを置きます。 display_progression()はN.C.と境界を省略しますが、各結果のevent_indexは 元の入力位置を保持します。

機能ラベルの読み方

表記 意味
T tonic
PD predominant
D dominant
S subdominant
NF non-functional
CT 共通音を保持するchromatic neighbor
VL chromaticな声部連結を主とする和音
passdim 半音進行をつなぐpassing diminished
CS 同型コードを反復するconstant structure
V/ii iiを一時主音とするdominant
V+/IV IVへ向かうaugmented dominant
subV/IV IVへ向かうtritone substitute
I/IV, i/vi 一時的な調でのtonic
SDm subdominant minor由来

Bm7 [ii7/IV|PD]のように|がある場合、左側が具体的な度数、 右側が機能または役割です。

Tはtonic-familyという役割であり、常にIの和音という意味ではありません。 E major上のAm7 → Bm7 → CM7 → Dを一時的なG majorのii–iiiとして読む候補では、 Bm7のlocal degreeを保ち、Bm7 [v7|iii7/bIII]と表示します。

C#m7-5 → CM7ではE、G、Bの3音を保持し、C#だけがCへ半音下行します。 この場合はpredominantではなく共通音装飾としてC#m7-5 [#im7-5|CT]と表示します。 この判定はtargetがglobal tonicでなくても成立し、G majorの C#:m7-5/G → C#:m7-5 → C:M7では最初の2和音を|CTと表示します。

major keyの#ivm7-5は、配置だけを根拠にPDとはしません。直後がglobal Vなら G#m7-5 → A7 → Dのように#ivm7-5|PDを維持します。一方、D majorの G#m7-5 → D/AはDとF#を保持するため#ivm7-5|CT、E majorの A#m7-5 → Am7は半音進行による声部連結として#ivm7-5|VLと表示します。

Bm7 → Bb:dim7 → Am7ではroot lineのB–Bb–Aを半音下行でつなぐため、 Bb:dim7 [biiidim7|passdim]と表示します。

Eb/F → Gb/Ab → A/B → C/D → Eb/F → Gでは、最初の5和音が 同じ9sus4構造を保ち、functional bassを短3度周期で移動します。3和音以上 続いた場合は個別のS/Dよりconstant structureを優先し、|CSと表示します。 F#/G#やGb/G#からGb/Abへ正規化されたmemberも同じpitch classとして 系列を維持します。単独のC/D → Gは従来どおりC/D [V9sus4|D]です。

C → Caug/F# → FM7では、CaugをV+/IV、F# bassをFへ半音下行する 独立したapproach bassとして扱います。したがってsubVではなく、 Caug/F# [Iaug/#IV|V+/IV]を1-bestとして表示します。

StrictV1と旧バージョン互換

新規コードでは次を使います。

romanizer = Romanizer.strict(default_tonic="C")

Romanizer(default_tonic="C")は、Python 0.1.9の出力を再現する python019プロファイルです。既存結果との互換性が必要な場合だけ利用してください。

開発用インストール

python -m pip install "maturin>=1.9.4,<2" pytest
python -m maturin develop --release
python -m pytest -q

Rust側だけを検証する場合:

cargo test --manifest-path chord-romanizer-rs/Cargo.toml
cargo test --manifest-path chord-romanizer-py/Cargo.toml

Rust APIの使用例は chord-romanizer-rs/README.mdを参照してください。 解析器の設計や詳細な判定規則はdocs/にあります。

動作環境

  • CPython 3.8以上
  • Rust 1.85以上(ソースからビルドする場合のみ)
  • Python wheel: PyO3 / abi3-py38

ライセンス

MIT License

Metadata

Release files for chord-romanizer 0.1.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chord-romanizer 0.1.17
File Size Uploaded Provenance Actions
chord_romanizer-0.1.17.tar.gz 152.9 kB With provenance Details for chord_romanizer-0.1.17.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for chord-romanizer 0.1.17
File Actions
chord_romanizer-0.1.17-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for chord_romanizer-0.1.17-cp38-abi3-win_amd64.whl
chord_romanizer-0.1.17-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details for chord_romanizer-0.1.17-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
chord_romanizer-0.1.17-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for chord_romanizer-0.1.17-cp38-abi3-macosx_11_0_arm64.whl
chord_romanizer-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details for chord_romanizer-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl

Total release size: 2.4 MB

Release files / chord_romanizer-0.1.17.tar.gz

Download URL chord_romanizer-0.1.17.tar.gz
Size 152.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d7b911492810a081b7bacd2261e4046f6a28435e6cfd01f4c6aa29452a766622
BLAKE2b-256 checksum
How to use checksums
42b9090b1b62d349da0ca3abd4d8db7d0a0b114d465f64cfe929b7c7d0dd2657
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / chord_romanizer-0.1.17-cp38-abi3-win_amd64.whl

Download URL chord_romanizer-0.1.17-cp38-abi3-win_amd64.whl
Size 487.2 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
94ce852c8e2479c541eb7d1182c8946ca414400cd251bf094e5eec82661b9288
BLAKE2b-256 checksum
How to use checksums
8dd90f14613a59d6f73526197cb5565ad6baf036f6b1ff96abd591d3586be6fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / chord_romanizer-0.1.17-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL chord_romanizer-0.1.17-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 633.1 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
bbdf46c8d4946c6657974b400011ec1b3a493f6f13aeaab78cd58ecf6b82502a
BLAKE2b-256 checksum
How to use checksums
b367f3293e533b757e1c3eab9af3e0256970ab6e093e023db7d06042279ac6db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / chord_romanizer-0.1.17-cp38-abi3-macosx_11_0_arm64.whl

Download URL chord_romanizer-0.1.17-cp38-abi3-macosx_11_0_arm64.whl
Size 567.4 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
127570457ed56c34f44d5c9fc6a6b4c180f6642db29fa70a8d3d1826bb9f5876
BLAKE2b-256 checksum
How to use checksums
90768bf03c4a717656b1fa722f95d255bcc3af6b6caf91f5bb4b89add8660257
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / chord_romanizer-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl

Download URL chord_romanizer-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl
Size 580.9 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
88543fe63b00fd43e1f5cab2bc18638bf3a675aabc055edac0ca55e3165e133f
BLAKE2b-256 checksum
How to use checksums
13545ed3d55641ef492bb943d49b37c11514c4caccdea7f957538a943c381386
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for chord-romanizer 0.1.17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for chord_romanizer-0.1.17.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page