Last active
September 18, 2024 12:58
-
-
Save trueroad/04aeccd92122c6428a9442dd55dffc61 to your computer and use it in GitHub Desktop.
Show SMF's absolute tick and note event like LilyPond event-listener.ly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Show SMF's absolute tick and note event like LilyPond event-listener.ly. | |
https://gist.github.com/trueroad/04aeccd92122c6428a9442dd55dffc61 | |
Copyright (C) 2024 Masamichi Hosoda. | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions | |
are met: | |
* Redistributions of source code must retain the above copyright notice, | |
this list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, | |
this list of conditions and the following disclaimer in the documentation | |
and/or other materials provided with the distribution. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
ARE DISCLAIMED. | |
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
SUCH DAMAGE. | |
""" | |
import sys | |
# https://gist.github.com/trueroad/52b7c4c98eec5fdf0ff3f62d64ec17bd | |
import smf_parse | |
def main() -> None: | |
"""Do main.""" | |
if len(sys.argv) != 2: | |
print('Usage: ./show_abs_tick.py [INPUT.mid]') | |
sys.exit(1) | |
sn: smf_parse.smf_notes = smf_parse.smf_notes() | |
if not sn.load(sys.argv[1]): | |
print('Error') | |
sys.exit(1) | |
tpqn: int | |
_, tpqn, _ = sn.get_smf_specs() | |
i: int | |
note: smf_parse.note_container | |
for i, note in enumerate(sn.get_notes()): | |
# Show index and ABS tick etc. | |
print(f'{i}: ABS tick {note.note_on.abs_tick}, ' | |
f'MBT {note.note_on.mbt}, ' | |
f'{smf_parse.note_to_ipn(note.note_on.note_event.note)}') | |
# Show note event like LilyPond event-listener.ly | |
lilypond_time: float = note.note_on.abs_tick / (tpqn * 4) | |
print(f' {lilypond_time:.8f}\tnote\t{note.note_on.note_event.note}') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment