mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-20 13:07:52 +09:00
added some classes
This commit is contained in:
1 parent
fc50222590
commit
03979db405
8 files changed
+100
-86
No files matched your search
@@ -2,6 +2,7 @@
|
||||
Date: 2024.07.07
|
||||
- Changes:
|
||||
- Reduce Memory usage by clearing cache in whisper
|
||||
- Added lyrics to midi file
|
||||
- Some bug fixes and improved error handling and logs
|
||||
|
||||
# Version: 0.0.11
|
||||
|
||||
+11
-11
@@ -851,7 +851,7 @@ def create_midi_file(
|
||||
convert_ultrastar_to_midi_instrument(ultrastar_class)
|
||||
]
|
||||
midi_output = os.path.join(song_output, f"{basename_without_ext}.mid")
|
||||
instruments_to_midi(voice_instrument, real_bpm, midi_output)
|
||||
instruments_to_midi(voice_instrument, real_bpm, midi_output, ultrastar_class.UltrastarNoteLines)
|
||||
|
||||
|
||||
def pitch_audio(
|
||||
@@ -884,22 +884,22 @@ def pitch_audio(
|
||||
json = file.read()
|
||||
pitched_data = PitchedData.from_json(json)
|
||||
|
||||
start_times = []
|
||||
end_times = []
|
||||
words = []
|
||||
if not settings.ignore_audio:
|
||||
start_times = []
|
||||
end_times = []
|
||||
words = []
|
||||
|
||||
for i, midi_segment in enumerate(transcribed_data):
|
||||
start_times.append(midi_segment.start)
|
||||
end_times.append(midi_segment.end)
|
||||
words.append(midi_segment.word)
|
||||
midi_segments = create_midi_notes_from_pitched_data(
|
||||
start_times, end_times, words, pitched_data
|
||||
)
|
||||
|
||||
else:
|
||||
midi_segments = create_midi_notes_from_pitched_data(
|
||||
ultrastar_class.startTimes, ultrastar_class.endTimes, ultrastar_class.words, pitched_data
|
||||
)
|
||||
for i, note_lines in enumerate(ultrastar_class.UltrastarNoteLines):
|
||||
start_times.append(note_lines.startTime)
|
||||
end_times.append(note_lines.endTime)
|
||||
words.append(note_lines.word)
|
||||
|
||||
midi_segments = create_midi_notes_from_pitched_data(start_times, end_times, words, pitched_data)
|
||||
|
||||
# fixme: should be in UltraStar
|
||||
ultrastar_note_numbers = convert_midi_notes_to_ultrastar_notes(midi_segments)
|
||||
|
||||
@@ -10,16 +10,13 @@ from dataclasses import dataclass
|
||||
|
||||
from modules.Pitcher.pitcher import get_frequencies_with_high_confidence
|
||||
from modules.Ultrastar.ultrastar_converter import (
|
||||
get_end_time_from_ultrastar,
|
||||
get_start_time_from_ultrastar,
|
||||
ultrastar_note_to_midi_note,
|
||||
midi_note_to_ultrastar_note
|
||||
midi_note_to_ultrastar_note,
|
||||
ultrastar_note_to_midi_note
|
||||
)
|
||||
from modules.console_colors import (
|
||||
ULTRASINGER_HEAD,
|
||||
red_highlighted,
|
||||
)
|
||||
from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue
|
||||
from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarNoteLine
|
||||
from modules.Pitcher.pitched_data import PitchedData
|
||||
|
||||
|
||||
@@ -28,27 +25,24 @@ def convert_ultrastar_to_midi_instrument(ultrastar_class: UltrastarTxtValue) ->
|
||||
|
||||
print(f"{ULTRASINGER_HEAD} Creating midi instrument from Ultrastar txt")
|
||||
|
||||
instrument = pretty_midi.Instrument(program=0)
|
||||
instrument = pretty_midi.Instrument(program=0, name="Vocals")
|
||||
velocity = 100
|
||||
|
||||
for i in enumerate(ultrastar_class.words):
|
||||
pos = i[0]
|
||||
start_time = get_start_time_from_ultrastar(ultrastar_class, pos)
|
||||
end_time = get_end_time_from_ultrastar(ultrastar_class, pos)
|
||||
pitch = ultrastar_note_to_midi_note(int(ultrastar_class.pitches[pos]))
|
||||
|
||||
note = pretty_midi.Note(velocity, pitch, start_time, end_time)
|
||||
for i, note_line in enumerate(ultrastar_class.UltrastarNoteLines):
|
||||
note = pretty_midi.Note(velocity, ultrastar_note_to_midi_note(note_line.pitch), note_line.startTime, note_line.endTime)
|
||||
instrument.notes.append(note)
|
||||
|
||||
return instrument
|
||||
|
||||
|
||||
def instruments_to_midi(instruments: list[object], bpm: float, midi_output: str) -> None:
|
||||
def instruments_to_midi(instruments: list[object], bpm: float, midi_output: str, ultrastar_note_line: UltrastarNoteLine) -> None:
|
||||
"""Write instruments to midi file"""
|
||||
|
||||
print(f"{ULTRASINGER_HEAD} Creating midi file -> {midi_output}")
|
||||
|
||||
midi_data = pretty_midi.PrettyMIDI(initial_tempo=bpm)
|
||||
for i, note_line in enumerate(ultrastar_note_line):
|
||||
midi_data.lyrics.append(pretty_midi.Lyric(text=note_line.word, time=note_line.startTime))
|
||||
for instrument in instruments:
|
||||
midi_data.instruments.append(instrument)
|
||||
midi_data.write(midi_output)
|
||||
|
||||
@@ -48,27 +48,37 @@ def ultrastar_note_to_midi_note(ultrastar_note: int) -> int:
|
||||
return midi_note
|
||||
|
||||
|
||||
def get_start_time_from_ultrastar(
|
||||
ultrastar_class: UltrastarTxtValue, pos: int
|
||||
) -> float:
|
||||
def get_start_time_from_ultrastar(ultrastar_class: UltrastarTxtValue, pos: int) -> float:
|
||||
"""Calculates the start time from the Ultrastar txt"""
|
||||
|
||||
gap = int(float(ultrastar_class.gap.replace(",", ".")) / 1000)
|
||||
real_bpm = ultrastar_bpm_to_real_bpm(float(ultrastar_class.bpm.replace(",", ".")))
|
||||
start_time = beat_to_second(int(ultrastar_class.startBeat[pos]), real_bpm) + gap
|
||||
start_time = get_start_time(ultrastar_class.gap, ultrastar_class.bpm, ultrastar_class.UltrastarNoteLines[pos].startBeat)
|
||||
return start_time
|
||||
|
||||
def get_start_time(gap: str, ultrastar_bpm: str, startBeat: float) -> float:
|
||||
"""Calculates the start time from the Ultrastar txt"""
|
||||
|
||||
gap = int(float(gap.replace(",", ".")) / 1000)
|
||||
real_bpm = ultrastar_bpm_to_real_bpm(float(ultrastar_bpm.replace(",", ".")))
|
||||
start_time = beat_to_second(int(startBeat), real_bpm) + gap
|
||||
return start_time
|
||||
|
||||
def get_end_time_from_ultrastar(ultrastar_class: UltrastarTxtValue, pos: int) -> float:
|
||||
"""Calculates the end time from the Ultrastar txt"""
|
||||
|
||||
gap = int(float(ultrastar_class.gap.replace(",", ".")) / 1000)
|
||||
real_bpm = ultrastar_bpm_to_real_bpm(float(ultrastar_class.bpm.replace(",", ".")))
|
||||
end_time = get_end_time(ultrastar_class.gap, ultrastar_class.bpm, ultrastar_class.UltrastarNoteLines[pos].startBeat, ultrastar_class.UltrastarNoteLines[pos].duration)
|
||||
return end_time
|
||||
|
||||
|
||||
def get_end_time(gap: str, ultrastar_bpm: str, startBeat: float, duration: float) -> float:
|
||||
"""Calculates the end time from the Ultrastar txt"""
|
||||
|
||||
gap = int(float(gap.replace(",", ".")) / 1000)
|
||||
real_bpm = ultrastar_bpm_to_real_bpm(float(ultrastar_bpm.replace(",", ".")))
|
||||
end_time = (
|
||||
beat_to_second(
|
||||
int(ultrastar_class.startBeat[pos]) + int(ultrastar_class.durations[pos]),
|
||||
int(startBeat) + int(duration),
|
||||
real_bpm,
|
||||
)
|
||||
+ gap
|
||||
)
|
||||
return end_time
|
||||
return end_time
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
from modules.console_colors import ULTRASINGER_HEAD
|
||||
from modules.Ultrastar.ultrastar_converter import (
|
||||
get_end_time_from_ultrastar,
|
||||
get_start_time_from_ultrastar,
|
||||
get_end_time,
|
||||
get_start_time,
|
||||
)
|
||||
from modules.Ultrastar.ultrastar_txt import (
|
||||
UltrastarTxtValue,
|
||||
UltrastarTxtTag,
|
||||
UltrastarTxtNoteTypeTag,
|
||||
FILE_ENCODING,
|
||||
UltrastarNoteLine,
|
||||
get_note_type_from_string
|
||||
)
|
||||
|
||||
|
||||
@@ -65,20 +67,16 @@ def parse_ultrastar_txt(input_file: str) -> UltrastarTxtValue:
|
||||
# [3] pitch
|
||||
# [4] word
|
||||
|
||||
ultrastar_class.noteType.append(parts[0])
|
||||
ultrastar_class.startBeat.append(parts[1])
|
||||
ultrastar_class.durations.append(parts[2])
|
||||
ultrastar_class.pitches.append(parts[3])
|
||||
ultrastar_class.words.append(parts[4] if len(parts) > 4 else "")
|
||||
ultrastar_note_line = UltrastarNoteLine(noteType=get_note_type_from_string(parts[0]),
|
||||
startBeat=float(parts[1]),
|
||||
duration=float(parts[2]),
|
||||
pitch=int(parts[3]),
|
||||
word=parts[4] if len(parts) > 4 else "",
|
||||
startTime=get_start_time(ultrastar_class.gap, ultrastar_class.bpm, float(parts[1])),
|
||||
endTime=get_end_time(ultrastar_class.gap, ultrastar_class.bpm, float(parts[1]), float(parts[2])))
|
||||
|
||||
ultrastar_class.UltrastarNoteLines.append(ultrastar_note_line)
|
||||
|
||||
# do always as last
|
||||
pos = len(ultrastar_class.startBeat) - 1
|
||||
ultrastar_class.startTimes.append(
|
||||
get_start_time_from_ultrastar(ultrastar_class, pos)
|
||||
)
|
||||
ultrastar_class.endTimes.append(
|
||||
get_end_time_from_ultrastar(ultrastar_class, pos)
|
||||
)
|
||||
# todo: Progress?
|
||||
|
||||
return ultrastar_class
|
||||
@@ -19,7 +19,7 @@ from modules.Ultrastar.ultrastar_converter import (
|
||||
get_start_time_from_ultrastar,
|
||||
ultrastar_note_to_midi_note,
|
||||
)
|
||||
from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue
|
||||
from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtNoteTypeTag
|
||||
from modules.Pitcher.pitched_data import PitchedData
|
||||
|
||||
MAX_SONG_SCORE = 10000
|
||||
@@ -40,13 +40,13 @@ class Points:
|
||||
def add_point(note_type: str, points: Points) -> Points:
|
||||
"""Add calculated points to the points object."""
|
||||
|
||||
if note_type == ":":
|
||||
if note_type == UltrastarTxtNoteTypeTag.NORMAL:
|
||||
points.notes += 1
|
||||
elif note_type == "*":
|
||||
elif note_type == UltrastarTxtNoteTypeTag.GOLDEN:
|
||||
points.golden_notes += 2
|
||||
elif note_type == "R":
|
||||
elif note_type == UltrastarTxtNoteTypeTag.RAP:
|
||||
points.rap += 1
|
||||
elif note_type == "G":
|
||||
elif note_type == UltrastarTxtNoteTypeTag.RAP_GOLDEN:
|
||||
points.golden_rap += 2
|
||||
return points
|
||||
|
||||
@@ -97,15 +97,13 @@ def calculate_score(pitched_data: PitchedData, ultrastar_class: UltrastarTxtValu
|
||||
simple_points = Points()
|
||||
accurate_points = Points()
|
||||
|
||||
reachable_line_bonus_per_word = MAX_SONG_LINE_BONUS / len(
|
||||
ultrastar_class.words
|
||||
)
|
||||
reachable_line_bonus_per_word = MAX_SONG_LINE_BONUS / len(ultrastar_class.UltrastarNoteLines)
|
||||
|
||||
for i, word in enumerate(ultrastar_class.words):
|
||||
if ultrastar_class.words == "":
|
||||
for i, note_line in enumerate(ultrastar_class.UltrastarNoteLines):
|
||||
if note_line.word == "":
|
||||
continue
|
||||
|
||||
if ultrastar_class.noteType[i] == "F":
|
||||
if note_line.noteType == UltrastarTxtNoteTypeTag.FREESTYLE:
|
||||
continue
|
||||
|
||||
start_time = get_start_time_from_ultrastar(ultrastar_class, i)
|
||||
@@ -118,9 +116,7 @@ def calculate_score(pitched_data: PitchedData, ultrastar_class: UltrastarTxtValu
|
||||
accurate_part_line_bonus_points = 0
|
||||
simple_part_line_bonus_points = 0
|
||||
|
||||
ultrastar_midi_note = ultrastar_note_to_midi_note(
|
||||
int(ultrastar_class.pitches[i])
|
||||
)
|
||||
ultrastar_midi_note = ultrastar_note_to_midi_note(int(note_line.pitch))
|
||||
ultrastar_note = librosa.midi_to_note(ultrastar_midi_note)
|
||||
|
||||
for part in range(parts):
|
||||
@@ -130,22 +126,16 @@ def calculate_score(pitched_data: PitchedData, ultrastar_class: UltrastarTxtValu
|
||||
if end_time < end or part == parts - 1:
|
||||
end = end_time
|
||||
|
||||
midi_segment = create_midi_note_from_pitched_data(
|
||||
start, end, pitched_data, word
|
||||
)
|
||||
midi_segment = create_midi_note_from_pitched_data(start, end, pitched_data, note_line.word)
|
||||
|
||||
if midi_segment.note[:-1] == ultrastar_note[:-1]:
|
||||
# Ignore octave high
|
||||
simple_points = add_point(
|
||||
ultrastar_class.noteType[i], simple_points
|
||||
)
|
||||
simple_points = add_point(note_line.noteType, simple_points)
|
||||
simple_part_line_bonus_points += 1
|
||||
|
||||
if midi_segment.note == ultrastar_note:
|
||||
# Octave high must be the same
|
||||
accurate_points = add_point(
|
||||
ultrastar_class.noteType[i], accurate_points
|
||||
)
|
||||
accurate_points = add_point(note_line.noteType, accurate_points)
|
||||
accurate_part_line_bonus_points += 1
|
||||
|
||||
accurate_points.parts += 1
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""Ultrastar TXT"""
|
||||
|
||||
from enum import Enum
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
FILE_ENCODING = "utf-8"
|
||||
|
||||
@@ -73,6 +75,33 @@ class UltrastarTxtNoteTypeTag(str, Enum):
|
||||
GOLDEN = '*'
|
||||
|
||||
|
||||
def get_note_type_from_string(note_type_str: str) -> UltrastarTxtNoteTypeTag:
|
||||
if note_type_str == UltrastarTxtNoteTypeTag.NORMAL.value:
|
||||
return UltrastarTxtNoteTypeTag.NORMAL
|
||||
elif note_type_str == UltrastarTxtNoteTypeTag.RAP.value:
|
||||
return UltrastarTxtNoteTypeTag.RAP
|
||||
elif note_type_str == UltrastarTxtNoteTypeTag.RAP_GOLDEN.value:
|
||||
return UltrastarTxtNoteTypeTag.RAP_GOLDEN
|
||||
elif note_type_str == UltrastarTxtNoteTypeTag.FREESTYLE.value:
|
||||
return UltrastarTxtNoteTypeTag.FREESTYLE
|
||||
elif note_type_str == UltrastarTxtNoteTypeTag.GOLDEN.value:
|
||||
return UltrastarTxtNoteTypeTag.GOLDEN
|
||||
else:
|
||||
raise ValueError(f"Unknown NoteType: {note_type_str}")
|
||||
|
||||
|
||||
@dataclass
|
||||
class UltrastarNoteLine:
|
||||
startBeat: float
|
||||
startTime: float
|
||||
endTime: float
|
||||
duration: float
|
||||
pitch: int
|
||||
word: str
|
||||
noteType: UltrastarTxtNoteTypeTag # F, R, G, *, :
|
||||
|
||||
|
||||
@dataclass
|
||||
class UltrastarTxtValue:
|
||||
"""Vaules for Ultrastar TXT files."""
|
||||
|
||||
@@ -95,10 +124,4 @@ class UltrastarTxtValue:
|
||||
tags = None
|
||||
creator = "UltraSinger [GitHub]"
|
||||
comment = "UltraSinger [GitHub]"
|
||||
startBeat = []
|
||||
startTimes = []
|
||||
endTimes = []
|
||||
durations = []
|
||||
pitches = []
|
||||
words = []
|
||||
noteType = [] # F, R, G, *, :
|
||||
UltrastarNoteLines: List[UltrastarNoteLine] = field(default_factory=list)
|
||||
@@ -4,11 +4,10 @@ import re
|
||||
import langcodes
|
||||
from packaging import version
|
||||
|
||||
from modules.console_colors import ULTRASINGER_HEAD
|
||||
from modules.console_colors import ULTRASINGER_HEAD, blue_highlighted
|
||||
from modules.Ultrastar.ultrastar_converter import (
|
||||
real_bpm_to_ultrastar_bpm,
|
||||
second_to_beat,
|
||||
beat_to_second,
|
||||
)
|
||||
from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, \
|
||||
FILE_ENCODING
|
||||
@@ -75,9 +74,8 @@ def create_ultrastar_txt_from_automation(
|
||||
) -> None:
|
||||
"""Creates an Ultrastar txt file from the automation data"""
|
||||
|
||||
print(
|
||||
f"{ULTRASINGER_HEAD} Creating {ultrastar_file_output} from transcription."
|
||||
)
|
||||
print(f"{ULTRASINGER_HEAD} Creating UltraStar file {ultrastar_file_output}")
|
||||
print(f"{ULTRASINGER_HEAD} Using UltraStar {blue_highlighted(f'Format Version {ultrastar_class.version}')}")
|
||||
|
||||
ultrastar_bpm = real_bpm_to_ultrastar_bpm(real_bpm)
|
||||
multiplication = get_multiplier(ultrastar_bpm)
|
||||
|
||||
Reference in new issue
Block a user