groovebin 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.
Files changed (37) hide show
  1. groovebin-0.1.0/CHANGELOG.md +25 -0
  2. groovebin-0.1.0/LICENSE +202 -0
  3. groovebin-0.1.0/MANIFEST.in +4 -0
  4. groovebin-0.1.0/NOTICE +10 -0
  5. groovebin-0.1.0/PKG-INFO +66 -0
  6. groovebin-0.1.0/README.md +38 -0
  7. groovebin-0.1.0/pyproject.toml +60 -0
  8. groovebin-0.1.0/setup.cfg +4 -0
  9. groovebin-0.1.0/src/groovebin/__init__.py +10 -0
  10. groovebin-0.1.0/src/groovebin/_parsers.py +97 -0
  11. groovebin-0.1.0/src/groovebin/_views.py +46 -0
  12. groovebin-0.1.0/src/groovebin/_views_library.py +40 -0
  13. groovebin-0.1.0/src/groovebin/cli.py +185 -0
  14. groovebin-0.1.0/src/groovebin/data/maps/addictive-drums-2.json +87 -0
  15. groovebin-0.1.0/src/groovebin/data/maps/drum-kit-designer.json +37 -0
  16. groovebin-0.1.0/src/groovebin/data/maps/gm.json +54 -0
  17. groovebin-0.1.0/src/groovebin/events.py +146 -0
  18. groovebin-0.1.0/src/groovebin/library/__init__.py +1 -0
  19. groovebin-0.1.0/src/groovebin/library/compose.py +127 -0
  20. groovebin-0.1.0/src/groovebin/library/generate.py +215 -0
  21. groovebin-0.1.0/src/groovebin/library/index.py +246 -0
  22. groovebin-0.1.0/src/groovebin/library/names.py +60 -0
  23. groovebin-0.1.0/src/groovebin/library/pattern.py +115 -0
  24. groovebin-0.1.0/src/groovebin/library/search.py +160 -0
  25. groovebin-0.1.0/src/groovebin/library/show.py +83 -0
  26. groovebin-0.1.0/src/groovebin/maps.py +146 -0
  27. groovebin-0.1.0/src/groovebin/midi.py +157 -0
  28. groovebin-0.1.0/src/groovebin/py.typed +0 -0
  29. groovebin-0.1.0/src/groovebin/song.py +164 -0
  30. groovebin-0.1.0/src/groovebin/timing.py +135 -0
  31. groovebin-0.1.0/src/groovebin/transforms.py +106 -0
  32. groovebin-0.1.0/src/groovebin.egg-info/PKG-INFO +66 -0
  33. groovebin-0.1.0/src/groovebin.egg-info/SOURCES.txt +35 -0
  34. groovebin-0.1.0/src/groovebin.egg-info/dependency_links.txt +1 -0
  35. groovebin-0.1.0/src/groovebin.egg-info/entry_points.txt +2 -0
  36. groovebin-0.1.0/src/groovebin.egg-info/requires.txt +6 -0
  37. groovebin-0.1.0/src/groovebin.egg-info/top_level.txt +1 -0
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versioning: [SemVer](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] — 2026-09-14
9
+
10
+ First release.
11
+
12
+ ### Added
13
+ - `groovebin remap`: translate a MIDI file's drum notes and polyphonic aftertouch keys from one note map to
14
+ another, scoped by `--track` and `--channel`; notes with no counterpart are kept or dropped (`--unmapped`).
15
+ - `groovebin notes`: a file's tracks and notes with bar positions and stroke names.
16
+ - `groovebin index`: a sqlite pattern library from a folder of `.mid` files, labelled from their paths, or
17
+ from a `MidiDb.csv`.
18
+ - `groovebin search` and `groovebin show`: filter patterns by label, role, meter, tempo, swing and intensity;
19
+ draw one as drum lanes or a piano roll.
20
+ - `groovebin generate`: a drum phrase picked bar by bar from library bars, with fills and a repeatable seed.
21
+ - Note maps `gm` (General MIDI Level 1 percussion), `addictive-drums-2` and `drum-kit-designer` (GM Standard
22
+ input mapping).
23
+ - Library: Standard MIDI File read and write (format 0 and 1) through paired notes and every other event,
24
+ tempo and meter maps, note transforms (transpose, velocity, shift, delete, quantize, merge), map
25
+ translation, and section planning (`library.compose`).
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ include LICENSE NOTICE README.md CHANGELOG.md
2
+ # The suite reads docs/ and the repo's own markdown, so it runs from a repository checkout.
3
+ prune tests
4
+ global-exclude __pycache__ *.py[cod]
groovebin-0.1.0/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ groovebin
2
+ Copyright 2026 Mike Farr
3
+
4
+ Built on pf-core (https://github.com/phierceweb/pf-core), Copyright 2026 Mike Farr,
5
+ licensed under the MIT License, and mido (https://github.com/mido/mido), licensed under
6
+ the MIT License.
7
+
8
+ Addictive Drums 2 is a trademark of XLN Audio; Logic Pro and Drum Kit Designer are
9
+ trademarks of Apple Inc. groovebin is not affiliated with either and ships no sounds,
10
+ patterns or MIDI content from them — only note-number tables.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: groovebin
3
+ Version: 0.1.0
4
+ Summary: MIDI files, note maps and a pattern library in Python: translate drum maps, transform notes, index and search grooves — no DAW or plug-in needed
5
+ Author: Mike Farr
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/phierceweb/groovebin
8
+ Project-URL: Changelog, https://github.com/phierceweb/groovebin/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/phierceweb/groovebin/issues
10
+ Keywords: midi,drums,drum-map,general-midi,groove,smf
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: End Users/Desktop
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: NOTICE
22
+ Requires-Dist: pf-core~=0.22.0
23
+ Requires-Dist: mido~=1.3
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0; extra == "dev"
26
+ Requires-Dist: ruff>=0.6; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # groovebin
30
+
31
+ MIDI files, note maps and a pattern library in Python. It reads and writes Standard MIDI Files,
32
+ translates notes between instrument maps — General MIDI drums, Addictive Drums 2, Logic's Drum Kit
33
+ Designer — and indexes a folder of MIDI patterns so they can be searched, shown and recombined.
34
+ Nothing needs a DAW or a plug-in installed or running.
35
+
36
+ Status: alpha. Commands, the library API and the index format may change before 1.0.
37
+
38
+ ## Install
39
+
40
+ pip install groovebin
41
+ groovebin --version
42
+
43
+ Needs Python 3.12 or newer.
44
+
45
+ ## Commands
46
+
47
+ groovebin remap IN.mid --from drum-kit-designer --to addictive-drums-2 -o OUT.mid
48
+ groovebin notes IN.mid --map gm
49
+ groovebin index ~/Grooves --map addictive-drums-2
50
+ groovebin search --role verse --meter 4/4 --tempo 90-110
51
+ groovebin generate --meter 4/4 --bars 16 --fills --role verse -o verse.mid
52
+
53
+ Usage: [docs/usage.md](https://github.com/phierceweb/groovebin/blob/main/docs/usage.md).
54
+ Changes: [CHANGELOG.md](https://github.com/phierceweb/groovebin/blob/main/CHANGELOG.md).
55
+
56
+ ## Develop
57
+
58
+ From a checkout:
59
+
60
+ bin/run setup
61
+ bin/run pytest
62
+ bin/run lint # ruff + the pf-core structural gate (300 soft / 500 hard lines)
63
+
64
+ See [CONTRIBUTING.md](https://github.com/phierceweb/groovebin/blob/main/CONTRIBUTING.md).
65
+
66
+ groovebin ships note-number tables only: no sounds, patterns or MIDI content from any vendor.
@@ -0,0 +1,38 @@
1
+ # groovebin
2
+
3
+ MIDI files, note maps and a pattern library in Python. It reads and writes Standard MIDI Files,
4
+ translates notes between instrument maps — General MIDI drums, Addictive Drums 2, Logic's Drum Kit
5
+ Designer — and indexes a folder of MIDI patterns so they can be searched, shown and recombined.
6
+ Nothing needs a DAW or a plug-in installed or running.
7
+
8
+ Status: alpha. Commands, the library API and the index format may change before 1.0.
9
+
10
+ ## Install
11
+
12
+ pip install groovebin
13
+ groovebin --version
14
+
15
+ Needs Python 3.12 or newer.
16
+
17
+ ## Commands
18
+
19
+ groovebin remap IN.mid --from drum-kit-designer --to addictive-drums-2 -o OUT.mid
20
+ groovebin notes IN.mid --map gm
21
+ groovebin index ~/Grooves --map addictive-drums-2
22
+ groovebin search --role verse --meter 4/4 --tempo 90-110
23
+ groovebin generate --meter 4/4 --bars 16 --fills --role verse -o verse.mid
24
+
25
+ Usage: [docs/usage.md](https://github.com/phierceweb/groovebin/blob/main/docs/usage.md).
26
+ Changes: [CHANGELOG.md](https://github.com/phierceweb/groovebin/blob/main/CHANGELOG.md).
27
+
28
+ ## Develop
29
+
30
+ From a checkout:
31
+
32
+ bin/run setup
33
+ bin/run pytest
34
+ bin/run lint # ruff + the pf-core structural gate (300 soft / 500 hard lines)
35
+
36
+ See [CONTRIBUTING.md](https://github.com/phierceweb/groovebin/blob/main/CONTRIBUTING.md).
37
+
38
+ groovebin ships note-number tables only: no sounds, patterns or MIDI content from any vendor.
@@ -0,0 +1,60 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "groovebin"
7
+ version = "0.1.0"
8
+ description = "MIDI files, note maps and a pattern library in Python: translate drum maps, transform notes, index and search grooves — no DAW or plug-in needed"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ authors = [{ name = "Mike Farr" }]
14
+ keywords = ["midi", "drums", "drum-map", "general-midi", "groove", "smf"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: End Users/Desktop",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Multimedia :: Sound/Audio :: MIDI",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = [
25
+ "pf-core~=0.22.0",
26
+ "mido~=1.3",
27
+ ]
28
+
29
+ [project.urls]
30
+ Repository = "https://github.com/phierceweb/groovebin"
31
+ Changelog = "https://github.com/phierceweb/groovebin/blob/main/CHANGELOG.md"
32
+ Issues = "https://github.com/phierceweb/groovebin/issues"
33
+
34
+ [project.scripts]
35
+ groovebin = "groovebin.cli:main"
36
+
37
+ [project.optional-dependencies]
38
+ dev = ["pytest>=8.0", "ruff>=0.6"]
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+
43
+ [tool.setuptools.package-data]
44
+ groovebin = ["py.typed", "data/maps/*.json"]
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
48
+ # every skip is listed: a skip that fires on a fresh clone proves nothing
49
+ addopts = "-rs"
50
+
51
+ [tool.ruff]
52
+ line-length = 100
53
+ target-version = "py312"
54
+
55
+ [tool.ruff.lint]
56
+ select = ["E", "W", "F", "B", "UP035"]
57
+ ignore = ["E501", "B008", "B904"]
58
+
59
+ [tool.ruff.lint.per-file-ignores]
60
+ "tests/**/*.py" = ["B011"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ """MIDI files, note maps and a pattern library, with no DAW or plug-in involved."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ try:
6
+ __version__ = version("groovebin")
7
+ except PackageNotFoundError: # a source tree without an install
8
+ __version__ = "0.0.0.dev0"
9
+
10
+ __all__ = ["__version__"]
@@ -0,0 +1,97 @@
1
+ """argparse construction for the `groovebin` command line."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ from pathlib import Path
7
+
8
+ from pf_core.utils.env import resolve_str
9
+
10
+ from . import __version__
11
+ from .maps import NAMES
12
+
13
+
14
+ def default_db() -> Path:
15
+ """The pattern library index when --db is not given: under the user's cache folder."""
16
+ return Path(resolve_str(None, "XDG_CACHE_HOME", default="~/.cache")).expanduser() / "groovebin" / "library.sqlite"
17
+
18
+
19
+ def build_parser() -> argparse.ArgumentParser:
20
+ ap = argparse.ArgumentParser(prog="groovebin",
21
+ description="MIDI files, note maps and a pattern library, with no DAW or plug-in involved.")
22
+ ap.add_argument("--version", action="version", version=f"groovebin {__version__}")
23
+ sub = ap.add_subparsers(dest="command")
24
+
25
+ remap = sub.add_parser("remap", help="translate a MIDI file's notes from one note map to another")
26
+ remap.add_argument("input", help="the .mid file to read")
27
+ remap.add_argument("--from", dest="src", required=True, choices=NAMES, help="the map the notes follow now")
28
+ remap.add_argument("--to", dest="dst", required=True, choices=NAMES, help="the map to translate them to")
29
+ remap.add_argument("-o", "--out", required=True, help="the .mid file to write")
30
+ remap.add_argument("--channel", type=int, action="append",
31
+ help="remap only notes on this channel, 1-16 (repeatable)")
32
+ remap.add_argument("--track", type=int, action="append", help="remap only this track, from 1 (repeatable)")
33
+ remap.add_argument("--unmapped", choices=("keep", "drop"), default="keep",
34
+ help="a note with no counterpart keeps its pitch (default) or is dropped")
35
+ remap.add_argument("--force", action="store_true", help="overwrite an existing --out file")
36
+
37
+ notes = sub.add_parser("notes", help="list a MIDI file's tracks and notes")
38
+ notes.add_argument("input", help="the .mid file to read")
39
+ notes.add_argument("--map", choices=NAMES, help="name each note's stroke from this map")
40
+ notes.add_argument("--track", type=int, action="append", help="list only this track, from 1 (repeatable)")
41
+
42
+ _library(sub)
43
+ return ap
44
+
45
+
46
+ def _db(parser: argparse.ArgumentParser) -> None:
47
+ parser.add_argument("--db", type=Path, help=f"the library index file (default {default_db()})")
48
+
49
+
50
+ def _library(sub) -> None:
51
+ ix = sub.add_parser("index", help="build the pattern library index from a folder of .mid files or a MidiDb.csv")
52
+ ix.add_argument("folder", nargs="?", type=Path, help="a folder of .mid files, labelled from their paths")
53
+ ix.add_argument("--csv", type=Path, help="a MidiDb.csv instead of a folder: its columns label each pattern")
54
+ ix.add_argument("--map", choices=NAMES, help="the drum map the patterns follow (leave out for a library that is not drums)")
55
+ _db(ix)
56
+
57
+ se = sub.add_parser("search", help="patterns matching every filter given")
58
+ se.add_argument("--category", help="whole value, any case")
59
+ se.add_argument("--role", help="intro, verse, pre-chorus, chorus, bridge or outro")
60
+ se.add_argument("--meter", metavar="N/D", help="e.g. 4/4")
61
+ se.add_argument("--tempo", metavar="RANGE",
62
+ help="100-130, <90, >=140 or 98, each bound to the digits written (98 is 97.5 up to 98.5)")
63
+ kind = se.add_mutually_exclusive_group()
64
+ kind.add_argument("--fill", action="store_true", help="fills only")
65
+ kind.add_argument("--beat", action="store_true", help="beats only")
66
+ se.add_argument("--swing", metavar="RANGE", help="0-1, as --tempo")
67
+ se.add_argument("--intensity", metavar="RANGE", help="0-1, as --tempo")
68
+ se.add_argument("--group", metavar="TEXT", help="a substring of the group")
69
+ se.add_argument("--variant", metavar="TEXT", help="a substring of the variant")
70
+ se.add_argument("--library", metavar="NAME", help="whole value, any case")
71
+ se.add_argument("--limit", type=int, default=50, metavar="N", help="at most N rows (default 50; 0 for all)")
72
+ se.add_argument("--json", action="store_true", help="the rows as JSON")
73
+ _db(se)
74
+
75
+ ge = sub.add_parser("generate", help="a drum phrase picked bar by bar from real library bars, as a MIDI file",
76
+ description="Every bar is a real bar of a matching pattern: the first starts a pattern; each "
77
+ "next has the kick and snare onsets nearest those of the bar that followed the last "
78
+ "pick in its own pattern. Timing moves up to 5 ticks and velocity up to 6.")
79
+ ge.add_argument("--meter", required=True, metavar="N/D", help="e.g. 4/4; patterns with any bar in another meter are left out")
80
+ ge.add_argument("--bars", required=True, type=int, metavar="N", help="the phrase's length in bars")
81
+ ge.add_argument("-o", "--out", required=True, help="the .mid file to write")
82
+ ge.add_argument("--category", help="whole value, any case")
83
+ ge.add_argument("--role", help="intro, verse, pre-chorus, chorus, bridge or outro")
84
+ ge.add_argument("--tempo", metavar="RANGE", help="as `groovebin search` takes it")
85
+ ge.add_argument("--intensity", metavar="RANGE", help="as `groovebin search` takes it")
86
+ ge.add_argument("--fills", action="store_true", help="every fourth bar from a fill pattern")
87
+ ge.add_argument("--seed", type=int, metavar="N", help="0 or more; the same seed and index give the same phrase (default: a new one, printed)")
88
+ ge.add_argument("--map", choices=NAMES, help="write the notes in this drum map (default: the patterns' own)")
89
+ ge.add_argument("--unmapped", choices=("keep", "drop"), default="keep",
90
+ help="with --map, a note with no counterpart keeps its pitch (default) or is dropped")
91
+ ge.add_argument("--force", action="store_true", help="overwrite an existing --out file")
92
+ _db(ge)
93
+
94
+ sh = sub.add_parser("show", help="one pattern as text: drum lanes, or a piano roll when it has no drum map")
95
+ sh.add_argument("id", help="the id search prints, or a unique prefix of it")
96
+ sh.add_argument("--map", choices=NAMES, help="name each lane's stroke from this map instead of the pattern's own")
97
+ _db(sh)
@@ -0,0 +1,46 @@
1
+ """Terminal output for the `groovebin` commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections import Counter
6
+
7
+ from .maps import stroke
8
+ from .song import Song, meter_map, tempo_map
9
+
10
+
11
+ def joined(items: list[object]) -> str:
12
+ words = [str(i) for i in items]
13
+ return words[0] if len(words) == 1 else f"{', '.join(words[:-1])} and {words[-1]}"
14
+
15
+
16
+ def remap_report(*, notes: int, unmapped: Counter, src: str, dst: str, nested: int, orphans: int,
17
+ rule: str = "keep") -> list[str]:
18
+ line = f"{notes - sum(unmapped.values())} of {notes} note(s) remapped {src} -> {dst}"
19
+ if unmapped:
20
+ kept = ", ".join(f"{pitch} x{count}" for pitch, count in sorted(unmapped.items()))
21
+ line += f"; no {dst} counterpart, {'pitch kept' if rule == 'keep' else 'dropped'}: {kept}"
22
+ lines = [line]
23
+ if nested:
24
+ lines.append(f"{nested} same-pitch note(s) now start inside a longer one and end before it: "
25
+ "a reader pairs note-offs first in, first out, so those lengths read back swapped")
26
+ if orphans:
27
+ lines.append(f"{orphans} note-off(s) with no note before them were dropped")
28
+ return lines
29
+
30
+
31
+ def listing(name: str, song: Song, tracks: list[int], map_name: str | None) -> list[str]:
32
+ meters = meter_map(song)
33
+ num, den = meters.meter_at(0)
34
+ lines = [f"{name}: format {song.format}, PPQ {song.ppq}, {len(song.tracks)} track(s), "
35
+ f"{tempo_map(song).bpm(0):g} bpm, {num}/{den}"]
36
+ for i in tracks:
37
+ part = song.tracks[i]
38
+ label = f" {part.name!r}" if part.name else ""
39
+ lines.append(f"track {i + 1}{label}: {len(part.notes)} note(s), {len(part.events)} other event(s)")
40
+ for n in part.notes:
41
+ line = (f" bar {meters.bar(n.tick):8.3f} ch {n.channel:2d} note {n.pitch:3d} "
42
+ f"vel {n.velocity:3d} len {n.length:6d}")
43
+ if map_name:
44
+ line += f" {stroke(map_name, n.pitch) or '-'}"
45
+ lines.append(line)
46
+ return lines
@@ -0,0 +1,40 @@
1
+ """Terminal output for the pattern library commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ def _cell(value: object, width: int) -> str:
7
+ text = "" if value is None else f"{value:g}" if isinstance(value, float) else str(value)
8
+ return text[:width].ljust(width)
9
+
10
+
11
+ def indexed(counts: dict) -> str:
12
+ return (f" {counts['parsed']} pattern(s) indexed, {counts['failed']} not parsed, "
13
+ f"{counts['duplicates']} duplicate(s) skipped")
14
+
15
+
16
+ def found(rows: list[dict], limit: int | None) -> list[str]:
17
+ lines = [f"{len(rows)} pattern(s){' (limit reached)' if limit and len(rows) == limit else ''}"]
18
+ for r in rows:
19
+ kind = "fill" if r["is_fill"] else "beat" if r["is_beat"] else ""
20
+ tempo = f"{r['tempo']:6.1f}" if r["tempo"] is not None else " -"
21
+ lines.append(f" {r['id']} {_cell(r['meter'], 5)} {tempo} {kind:4s} {_cell(r['bars'], 3)} "
22
+ f"{_cell(r['role'], 10)} {_cell(r['category'], 16)} {_cell(r['group_name'], 24)} "
23
+ f"{_cell(r['variant'] or r['file'], 28)}")
24
+ return lines
25
+
26
+
27
+ def picked(pool, ph) -> list[str]:
28
+ fills = f", {len(pool.fills)} fill bar(s)" if pool.fills else ""
29
+ left = f"; {pool.left_out} pattern(s) with a bar in another meter left out" if pool.left_out else ""
30
+ lines = [f"pool: {len(pool.bars)} beat bar(s) from {len(pool.patterns)} pattern(s){fills}{left}",
31
+ f"seed {ph.seed}: {len(ph.picks)} bar(s) of {ph.sig[0]}/{ph.sig[1]}, {len(ph.notes)} note(s) in {ph.map}"]
32
+ for k, p in enumerate(ph.picks, 1):
33
+ line = f" bar {k:<3d} {'fill' if p.fill else 'beat'} {p.bar.id} bar {p.bar.index + 1} of {p.bar.count}"
34
+ if p.fill:
35
+ line += f", replaces {p.replaces.id} bar {p.replaces.index + 1}, {p.distance} onset step(s) from it"
36
+ lines.append(line)
37
+ if ph.unmapped:
38
+ kept = ", ".join(f"{pitch} x{n}" for pitch, n in ph.unmapped.items())
39
+ lines.append(f" no {ph.map} counterpart, {'pitch kept' if ph.unmapped_rule == 'keep' else 'dropped'}: {kept}")
40
+ return lines