File size: 1,245 Bytes
91394e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from .base import MelodyDatasetHandler


class Touhou(MelodyDatasetHandler):
    name = "touhou"

    def __init__(self, melody_type, *args, **kwargs):
        if melody_type != "note":
            raise ValueError(
                f"Touhou dataset only contains note annotations. {melody_type} is not supported."
            )

        import json

        with open("data/touhou/note_data.json", "r", encoding="utf-8") as f:
            song_db = json.load(f)
        song_db = {song["name"]: song for song in song_db}
        self.song_db = song_db

    def get_song_ids(self):
        return list(self.song_db.keys())

    def get_phrase_length(self, song_id):
        # touhou score does not have phrase segmentation
        return None

    def iter_song_phrases(self, song_id):
        song = self.song_db[song_id]
        song = {
            "tempo": song["tempo"],
            "note_start_times": [n[0] * (100 / song["tempo"]) for n in song["score"]],
            "note_end_times": [n[1] * (100 / song["tempo"]) for n in song["score"]],
            "note_lyrics": ["" for n in song["score"]],
            "note_midi": [n[2] for n in song["score"]],
        }
        # touhou score does not have phrase segmentation
        yield song