Skip to content

Commit

Permalink
Add metavars and change --identify to --info
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberrumor committed May 5, 2024
1 parent b8c715d commit 045c744
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ Features:
# Usage

```
usage: midilint [-h] [--velocity VELOCITY] [--snap SNAP] [--transpose TRANSPOSE] [--align] [--precision PRECISION] [--identify] SOURCE [DEST]
usage: midilint [-h] [--velocity INT] [--snap KEY] [--transpose KEY] [--align INT] [--info] SOURCE [DEST]
The midi linter.
positional arguments:
SOURCE the midi file to lint
DEST the name of the output file
SOURCE the midi file to lint
DEST the name of the output file
options:
-h, --help show this help message and exit
--velocity VELOCITY the velocity to set all notes to
--snap SNAP the key to snap notes to. E.g. c_major or e_phrygian.
--transpose TRANSPOSE
the key to transpose to. E.g. c_major or e_phrygian.
--align align the start and end of notes to intervals
--precision PRECISION
determines the size of the interval to align to. 1 is quarter note, 2 is eighth, 4 is sixteenth, etc
--identify read information about a file
-h, --help show this help message and exit
--velocity INT the velocity to set all notes to
--snap KEY the key to snap notes to. E.g. c_major or e_phrygian.
--transpose KEY the key to transpose to. E.g. c_major or e_phrygian.
--align INT align the start and end of notes to intervals. 1 is quarter note, 2 is eighth, 4 is sixteenth, etc
--info read information about a file
```

# Installation
Expand Down
23 changes: 9 additions & 14 deletions bin/midilint
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def main(source: Path, args) -> None:


# Identify then exit
if args.identify:
for k, v in midilint.identify(mid).items():
if args.info:
for k, v in midilint.info(mid).items():
print(f"{k:<20} {v}")
return

Expand All @@ -42,7 +42,7 @@ def main(source: Path, args) -> None:

# note alignment
if args.align:
mid = midilint.align(mid, args.precision)
mid = midilint.align(mid, args.align)

# Save to dest if it was provided, otherwise
# overwrite input file.
Expand All @@ -67,31 +67,26 @@ if __name__ == "__main__":
nargs="?",
)

parser.add_argument("--velocity", type=int, help="the velocity to set all notes to")
parser.add_argument("--velocity", type=int, help="the velocity to set all notes to", metavar="INT")

parser.add_argument(
"--snap", type=str, help="the key to snap notes to. E.g. c_major or e_phrygian."
"--snap", type=str, help="the key to snap notes to. E.g. c_major or e_phrygian.", metavar="KEY"
)

parser.add_argument(
"--transpose", type=str, help="the key to transpose to. E.g. c_major or e_phrygian."
"--transpose", type=str, help="the key to transpose to. E.g. c_major or e_phrygian.", metavar="KEY"
)

parser.add_argument(
"--align",
action="store_true",
help="align the start and end of notes to intervals",
)

parser.add_argument(
"--precision",
type=int,
default=1,
help="determines the size of the interval to align to. 1 is quarter note, 2 is eighth, 4 is sixteenth, etc",
metavar="INT",
help="align the start and end of notes to intervals. 1 is quarter note, 2 is eighth, 4 is sixteenth, etc",
)

parser.add_argument(
"--identify",
"--info",
action="store_true",
help="read information about a file"
)
Expand Down
4 changes: 2 additions & 2 deletions midilint/midilint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import midi_abstraction as mab


def identify(source: mido.MidiFile) -> mido.MidiFile:
def info(source: mido.MidiFile) -> mido.MidiFile:
"""
Get information about a file.
"""
Expand Down Expand Up @@ -199,7 +199,7 @@ def transpose(
"""
Transpose based on scale degrees. Requires an identifiable key.
"""
original_key = identify(source)["key"]
original_key = info(source)["key"]
if "?" in original_key:
raise ValueError("original key is unidentifiable, unable to transpose.")

Expand Down
4 changes: 2 additions & 2 deletions test/test_identify.py → test/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
),
],
)
def test_identify(file, expected):
def test_info(file, expected):
mid = mido.MidiFile(file, clip=True)
result = midilint.identify(mid)
result = midilint.info(mid)
assert result == expected

0 comments on commit 045c744

Please sign in to comment.