JSON to Midi classes
This commit is contained in:
parent
3f7b409302
commit
413cefb933
BIN
py/assets/entities/__pycache__/header.cpython-313.pyc
Normal file
BIN
py/assets/entities/__pycache__/header.cpython-313.pyc
Normal file
Binary file not shown.
BIN
py/assets/entities/__pycache__/instrument.cpython-313.pyc
Normal file
BIN
py/assets/entities/__pycache__/instrument.cpython-313.pyc
Normal file
Binary file not shown.
BIN
py/assets/entities/__pycache__/note.cpython-313.pyc
Normal file
BIN
py/assets/entities/__pycache__/note.cpython-313.pyc
Normal file
Binary file not shown.
BIN
py/assets/entities/__pycache__/song.cpython-313.pyc
Normal file
BIN
py/assets/entities/__pycache__/song.cpython-313.pyc
Normal file
Binary file not shown.
BIN
py/assets/entities/__pycache__/track.cpython-313.pyc
Normal file
BIN
py/assets/entities/__pycache__/track.cpython-313.pyc
Normal file
Binary file not shown.
6
py/assets/entities/header.py
Normal file
6
py/assets/entities/header.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
class Header(BaseModel):
|
||||||
|
model_config = ConfigDict(extra='ignore')
|
||||||
|
|
||||||
|
name: str
|
||||||
7
py/assets/entities/instrument.py
Normal file
7
py/assets/entities/instrument.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
class Instrument(BaseModel):
|
||||||
|
model_config = ConfigDict(extra='ignore')
|
||||||
|
|
||||||
|
family: str
|
||||||
|
number: int
|
||||||
9
py/assets/entities/note.py
Normal file
9
py/assets/entities/note.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
class Note(BaseModel):
|
||||||
|
model_config = ConfigDict(extra='ignore')
|
||||||
|
|
||||||
|
duration_ticks: int = Field(alias='durationTicks')
|
||||||
|
midi: int
|
||||||
|
name: str
|
||||||
|
ticks: int
|
||||||
9
py/assets/entities/song.py
Normal file
9
py/assets/entities/song.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from header import Header
|
||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
from track import Track
|
||||||
|
|
||||||
|
class Song(BaseModel):
|
||||||
|
model_config = ConfigDict(extra='ignore')
|
||||||
|
|
||||||
|
header: Header
|
||||||
|
tracks: list[Track]
|
||||||
16
py/assets/entities/song_manager.py
Normal file
16
py/assets/entities/song_manager.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from song import Song
|
||||||
|
|
||||||
|
def load_song(song_file: str) -> Song:
|
||||||
|
print("load song:", song_file)
|
||||||
|
cd = os.getcwd()
|
||||||
|
print("current directory", cd)
|
||||||
|
with open(song_file, 'r') as f:
|
||||||
|
return Song(**json.load(f))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
song = load_song('assets/music/json/tetris.json')
|
||||||
|
print(song)
|
||||||
|
raise SystemExit(0)
|
||||||
10
py/assets/entities/track.py
Normal file
10
py/assets/entities/track.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from instrument import Instrument
|
||||||
|
from note import Note
|
||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
class Track(BaseModel):
|
||||||
|
model_config = ConfigDict(extra='ignore')
|
||||||
|
|
||||||
|
instrument: Instrument
|
||||||
|
name: str
|
||||||
|
notes: list[Note]
|
||||||
22823
py/assets/music/json/tetris.json
Normal file
22823
py/assets/music/json/tetris.json
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,3 @@
|
|||||||
raylib
|
raylib
|
||||||
Box2D
|
Box2D
|
||||||
|
pydantic
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user