hesym 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hesym-0.1.0/.gitignore ADDED
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
hesym-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GTLaimi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
hesym-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.5
2
+ Name: hesym
3
+ Version: 0.1.0
4
+ Summary: HesychiaMidS CLI tool - MIDI parsing and visualization in your terminal
5
+ Project-URL: Homepage, https://github.com/GTLaimi/hesym
6
+ Project-URL: Repository, https://github.com/GTLaimi/hesym
7
+ Project-URL: Issues, https://github.com/GTLaimi/hesym/issues
8
+ Author-email: GTLaimi <3935984932@qq.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Requires-Dist: mido>=1.3.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # hesym
hesym-0.1.0/README.md ADDED
@@ -0,0 +1 @@
1
+ # hesym
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "hesym"
7
+ version = "0.1.0"
8
+ description = "HesychiaMidS CLI tool - MIDI parsing and visualization in your terminal"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [
12
+ {name = "GTLaimi", email = "3935984932@qq.com"}
13
+ ]
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.8",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ ]
25
+ dependencies = [
26
+ "mido>=1.3.0"
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ dev = ["pytest>=7.0.0"]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/GTLaimi/hesym"
34
+ Repository = "https://github.com/GTLaimi/hesym"
35
+ Issues = "https://github.com/GTLaimi/hesym/issues"
36
+
37
+ [project.scripts]
38
+ hesym = "hesym.cli:main"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/hesym"]
@@ -0,0 +1,16 @@
1
+ """
2
+ hesym - HesychiaMidS CLI tool
3
+ MIDI parsing and visualization in your terminal
4
+ """
5
+
6
+ from .core.midi_parser import parse_midi
7
+ from .models.note import Note
8
+ from .cli import main
9
+
10
+ __all__ = [
11
+ "parse_midi",
12
+ "Note",
13
+ "main",
14
+ ]
15
+
16
+ __version__ = "0.1.0"
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env python3
2
+ """命令行入口 - MIDI 解析与可视化 CLI"""
3
+
4
+ import argparse
5
+ import json
6
+ import sys
7
+ import os
8
+
9
+ # 使用相对导入(包内导入)
10
+ from .core.midi_parser import parse_midi
11
+
12
+
13
+ def main():
14
+ parser = argparse.ArgumentParser(
15
+ description="hesym: MIDI file parser and visualizer - extract notes, stats, and more"
16
+ )
17
+ parser.add_argument("file", help="要解析的 MIDI 文件路径")
18
+ parser.add_argument("--json", action="store_true", help="以 JSON 格式输出原始数据")
19
+ parser.add_argument("--stats", action="store_true", help="显示统计信息(总音符数、时长等)")
20
+ parser.add_argument("--limit", type=int, default=20, help="显示前 N 个音符 (默认 20)")
21
+ parser.add_argument("--fix-vel", type=int, default=0, help="将力度为0的音符修正为指定值 (例如 100)")
22
+
23
+ args = parser.parse_args()
24
+
25
+ if not os.path.exists(args.file):
26
+ print(f"❌ 错误: 文件 '{args.file}' 不存在", file=sys.stderr)
27
+ sys.exit(1)
28
+
29
+ try:
30
+ notes, total_ticks, bpm, ticks_per_beat, time_sig = parse_midi(args.file)
31
+ except Exception as e:
32
+ print(f"❌ 解析 MIDI 失败: {e}", file=sys.stderr)
33
+ sys.exit(1)
34
+
35
+ # ---- 力度修复 ----
36
+ if args.fix_vel > 0:
37
+ for note in notes:
38
+ if note.velocity == 0:
39
+ note.velocity = args.fix_vel
40
+
41
+ # ---- 输出逻辑 ----
42
+ if args.json:
43
+ data = {
44
+ "format": "hesym_core",
45
+ "ticks_per_beat": ticks_per_beat,
46
+ "bpm": bpm,
47
+ "time_signature": time_sig,
48
+ "total_ticks": total_ticks,
49
+ "note_count": len(notes),
50
+ "notes": [
51
+ {
52
+ "pitch": n.pitch,
53
+ "name": n.pitch_name,
54
+ "start_tick": n.start_tick,
55
+ "duration_ticks": n.duration,
56
+ "velocity": n.velocity
57
+ } for n in notes
58
+ ]
59
+ }
60
+ print(json.dumps(data, indent=2))
61
+ elif args.stats:
62
+ total_sec = total_ticks / ((bpm / 60.0) * ticks_per_beat)
63
+ pitches = [n.pitch for n in notes]
64
+ print(f"📊 MIDI 统计报告")
65
+ print(f" 🎵 音符总数: {len(notes)}")
66
+ print(f" ⏱️ 总时长: {total_ticks} ticks ≈ {total_sec:.2f} 秒")
67
+ print(f" 🎚️ BPM: {bpm:.1f}")
68
+ print(f" 📏 PPQ (每拍Tick数): {ticks_per_beat}")
69
+ print(f" 🎼 拍号: {time_sig}")
70
+ if pitches:
71
+ print(f" 🎹 音域: {min(pitches)} -> {max(pitches)}")
72
+ if args.fix_vel > 0:
73
+ print(f" 🔧 已将所有力度 0 修正为 {args.fix_vel}")
74
+ else:
75
+ # 默认表格显示
76
+ print(f"\n🎵 解析成功!共读取 {len(notes)} 个音符 (显示前 {min(args.limit, len(notes))} 个):\n")
77
+ print(f"{'Note':<6} {'Pitch':<5} {'Start':<10} {'Dur':<8} {'Vel'}")
78
+ print("-" * 40)
79
+ for n in notes[:args.limit]:
80
+ print(f"{n.pitch_name:<6} {n.pitch:<5} {n.start_tick:<10} {n.duration:<8} {n.velocity}")
81
+ if len(notes) > args.limit:
82
+ print(f"... (以及其余 {len(notes) - args.limit} 个音符)")
83
+
84
+ if __name__ == "__main__":
85
+ main()
@@ -0,0 +1,3 @@
1
+ from .midi_parser import parse_midi
2
+
3
+ __all__ = ["parse_midi"]
@@ -0,0 +1,57 @@
1
+ # core/midi_parser.py
2
+ """MIDI 文件解析核心模块
3
+
4
+ 依赖: mido (pip install mido)
5
+ """
6
+
7
+ import mido
8
+ from ..models.note import Note # 改用相对导入
9
+
10
+
11
+ def parse_midi(file_path: str):
12
+ """
13
+ 解析 MIDI 文件,返回音符列表和元数据
14
+
15
+ Args:
16
+ file_path: MIDI 文件路径
17
+
18
+ Returns:
19
+ tuple: (notes, total_ticks, bpm, ticks_per_beat, time_sig)
20
+ - notes: Note 对象列表
21
+ - total_ticks: 总 tick 数
22
+ - bpm: 速度 (Beats Per Minute)
23
+ - ticks_per_beat: 每拍 tick 数 (PPQ)
24
+ - time_sig: 拍号字符串,如 "4/4"
25
+
26
+ Raises:
27
+ FileNotFoundError: 文件不存在时
28
+ ValueError: 解析失败时
29
+ """
30
+ mid = mido.MidiFile(file_path)
31
+ notes = []
32
+ active_notes = {}
33
+ cur_tick = 0
34
+ bpm = 120.0
35
+ ticks_per_beat = mid.ticks_per_beat
36
+ time_sig = "4/4"
37
+
38
+ for track in mid.tracks:
39
+ for msg in track:
40
+ cur_tick += msg.time
41
+ if msg.type == 'note_on' and msg.velocity > 0:
42
+ active_notes[msg.note] = cur_tick
43
+ elif msg.type == 'note_off' or (msg.type == 'note_on' and msg.velocity == 0):
44
+ if msg.note in active_notes:
45
+ notes.append(Note(
46
+ pitch=msg.note,
47
+ start_tick=active_notes[msg.note],
48
+ duration=cur_tick - active_notes[msg.note],
49
+ velocity=msg.velocity
50
+ ))
51
+ del active_notes[msg.note]
52
+ elif msg.type == 'set_tempo':
53
+ bpm = mido.tempo2bpm(msg.tempo)
54
+ elif msg.type == 'time_signature':
55
+ time_sig = f"{msg.numerator}/{msg.denominator}"
56
+
57
+ return notes, cur_tick, bpm, ticks_per_beat, time_sig
@@ -0,0 +1 @@
1
+ from .note import Note
@@ -0,0 +1,29 @@
1
+ # models/note.py
2
+ """MIDI 音符数据模型"""
3
+
4
+
5
+ class Note:
6
+ """MIDI 音符对象
7
+
8
+ Attributes:
9
+ pitch: 音高 (0-127)
10
+ start_tick: 起始 tick
11
+ duration: 持续时间 (tick 数)
12
+ velocity: 力度 (0-127)
13
+ pitch_name: 音名,如 "C4" (自动计算)
14
+ """
15
+
16
+ def __init__(self, pitch: int, start_tick: int, duration: int, velocity: int):
17
+ self.pitch = pitch
18
+ self.start_tick = start_tick
19
+ self.duration = duration
20
+ self.velocity = velocity
21
+ self.pitch_name = self._midi_to_name(pitch)
22
+
23
+ def _midi_to_name(self, midi_note: int) -> str:
24
+ """将 MIDI 音高编号转换为音名,如 60 -> C4"""
25
+ notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
26
+ return f"{notes[midi_note % 12]}{(midi_note // 12) - 1}"
27
+
28
+ def __repr__(self) -> str:
29
+ return f"Note(pitch={self.pitch}, name={self.pitch_name}, start={self.start_tick}, dur={self.duration}, vel={self.velocity})"
hesym-0.1.0/test.mid ADDED
Binary file