Last active
December 12, 2021 12:44
-
-
Save taroushirani/0c047d868c5c6ad494c92f78a194b0ed to your computer and use it in GitHub Desktop.
Convert from UST file to MusicXML file.
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/python | |
import argparse | |
import sys | |
from tqdm import tqdm | |
from os.path import expanduser | |
import utaupy as up | |
import music21 as m21 | |
def convert_lyric(lyric, table): | |
ret = None | |
for key, value in table.items(): | |
if lyric == "".join(value): | |
ret = key | |
if ret == None: # Not found | |
ret = lyric | |
# print(ret) | |
return ret | |
def get_parser(): | |
parser = argparse.ArgumentParser( | |
description="Convert ust file to musicxml", | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | |
) | |
parser.add_argument("input_filename", type=str, help="Input UST filename") | |
parser.add_argument("output_filename", type=str, help="Output MusicXML filename") | |
parser.add_argument("table_path", type=str, help="Table file path") | |
parser.add_argument("--title", type=str, help="Title") | |
parser.add_argument("--composer", type=str, help="Composer") | |
parser.add_argument("--lyricist", type=str, help="Lyricist") | |
parser.add_argument("--convert", action="store_true", help="Convert lyrics according to table file") | |
parser.add_argument("--cv", action="store_true", help="Convert VCV to CV") | |
return parser | |
args = get_parser().parse_args(sys.argv[1:]) | |
input_filename = expanduser(args.input_filename) | |
output_filename = expanduser(args.output_filename) | |
table_path = expanduser(args.table_path) | |
is_convert = args.convert | |
is_cv = args.cv | |
title = args.title | |
composer = args.composer | |
lyricist = args.lyricist | |
ust = up.ust.load(input_filename) | |
d_table = up.table.load(table_path, encoding="utf_8") | |
current_tempo = None | |
m21_s = m21.stream.Score() | |
m21_s.insert(0, m21.metadata.Metadata()) | |
m21_s.metadata.title = title | |
m21_s.metadata.composer = composer | |
m21_s.metadata.lyricist = lyricist | |
for ust_note in tqdm(ust.notes): | |
if current_tempo != ust_note.tempo: | |
mm = m21.tempo.MetronomeMark(number=ust_note.tempo) | |
m21_s.append(mm) | |
current_tempo = ust_note.tempo | |
m21_note = None | |
lyric = ust_note.lyric | |
if is_cv and len(lyric) > 2: | |
lyric = lyric.split(" ")[1] | |
# print(lyric) | |
if lyric != "R": | |
m21_note = m21.note.Note() | |
m21_note.pitch = m21.pitch.Pitch(ust_note.notename) | |
if is_convert: | |
m21_note.lyric = convert_lyric(lyric, d_table) | |
else: | |
m21_note.lyric=lyric | |
else: | |
m21_note = m21.note.Rest() | |
m21_note.duration = m21.duration.Duration(ust_note.length * 0.001 * 125 / 60.0) | |
m21_s.append(m21_note) | |
#m21_s.show("t") | |
m21_s.write("musicxml", fp=output_filename) |
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
くぁ k w a | |
くぃ k w i | |
くぅ k w u | |
くぇ k w e | |
くぉ k w o | |
くゎ k w a | |
ぐぁ g w a | |
ぐぃ g w i | |
ぐぅ g w u | |
ぐぇ g w e | |
ぐぉ g w o | |
ぐゎ g w a | |
ゔょ by o | |
ゔゅ by u | |
ゔゃ by a | |
ゔぉ v o | |
ゔぇ v e | |
ゔぃ v i | |
ゔぁ v a | |
ん N | |
わ w a | |
ろ r o | |
れ r e | |
る r u | |
りょ ry o | |
りゅ ry u | |
りゃ ry a | |
りぇ ry e | |
り r i | |
ら r a | |
よ y o | |
ゆ y u | |
や y a | |
も m o | |
め m e | |
む m u | |
みょ my o | |
みゅ my u | |
みゃ my a | |
みぇ my e | |
み m i | |
ま m a | |
ぽ p o | |
ぼ b o | |
ほ h o | |
ぺ p e | |
べ b e | |
へ h e | |
ぷ p u | |
ぶ b u | |
ふぉ f o | |
ふぇ f e | |
ふぃ f i | |
ふぁ f a | |
ふ f u | |
ぴょ py o | |
ぴゅ py u | |
ぴゃ py a | |
ぴぇ py e | |
ぴ p i | |
びょ by o | |
びゅ by u | |
びゃ by a | |
びぇ by e | |
び b i | |
ひょ hy o | |
ひゅ hy u | |
ひゃ hy a | |
ひぇ hy e | |
ひ h i | |
ぱ p a | |
ば b a | |
は h a | |
の n o | |
ね n e | |
ぬ n u | |
にょ ny o | |
にゅ ny u | |
にゃ ny a | |
にぇ ny e | |
に n i | |
な n a | |
どぅ d u | |
ど d o | |
とぅ t u | |
と t o | |
でょ dy o | |
でゅ dy u | |
でゃ dy a | |
でぇ dy e | |
でぃ d i | |
で d e | |
てょ ty o | |
てゅ ty u | |
てゃ ty a | |
てぃ t i | |
て t e | |
づ z u | |
つぉ ts o | |
つぇ ts e | |
つぃ ts i | |
つぁ ts a | |
つ ts u | |
っ cl | |
ぢ j i | |
ちょ ch o | |
ちゅ ch u | |
ちゃ ch a | |
ちぇ ch e | |
ち ch i | |
だ d a | |
た t a | |
ぞ z o | |
そ s o | |
ぜ z e | |
せ s e | |
ずぃ z i | |
ず z u | |
すぃ s i | |
す s u | |
じょ j o | |
じゅ j u | |
じゃ j a | |
じぇ j e | |
じ j i | |
しょ sh o | |
しゅ sh u | |
しゃ sh a | |
しぇ sh e | |
しぃ s i | |
し sh i | |
ざ z a | |
さ s a | |
ご g o | |
こ k o | |
げ g e | |
け k e | |
ぐ g u | |
く k u | |
ぎょ gy o | |
ぎゅ gy u | |
ぎゃ gy a | |
ぎぇ gy e | |
ぎ g i | |
きょ ky o | |
きゅ ky u | |
きゃ ky a | |
きぇ ky e | |
き k i | |
が g a | |
か k a | |
お o | |
え e | |
うぉ w o | |
うぇ w e | |
うぃ w i | |
う u | |
いぇ y e | |
い i | |
あ a | |
ん n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment