-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicEvent.py
More file actions
49 lines (37 loc) · 1.08 KB
/
Copy pathMusicEvent.py
File metadata and controls
49 lines (37 loc) · 1.08 KB
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
39
40
41
42
43
44
45
46
47
48
49
from typing import Literal
from .MIDIEvent import MIDIEvent
class MusicEvent:
type: str
value: int
def __init__(self, value: int):
self.type = ""
self.value = value
def __str__(self):
return f"{self.__class__.__name__}({self.type} with value {self.value})"
def toMIDIEvent(
self,
midi_channel: int,
status: Literal["on", "off"],
notesOffset: int,
) -> MIDIEvent: ...
class Note(MusicEvent):
type: Literal["note"] = "note"
value: int = 0
def __init__(self, value: int):
self.value = value
def toMIDIEvent(
self,
midi_channel: int,
status: Literal["on", "off"],
notesOffset: int,
) -> MIDIEvent:
note = self.value + notesOffset
if status == "on":
return MIDIEvent(midi_channel, MIDIEvent.NOTE_ON, note, 127)
else:
return MIDIEvent(midi_channel, MIDIEvent.NOTE_OFF, note, 0)
class NullEvent(MusicEvent):
type: Literal["null"] = "null"
value: int = 0
def __init__(self):
self.value = 0