def midi_to_event(time: int, msg: Any, voice: Voice): if msg.type == 'control_change': return ControlChangeEvent(time, voice, msg.control, msg.value) elif msg.type == 'program_change': pass # return ProgramChangeEvent( time, voice, msg.program ) elif msg.type == 'note_on': note = Note().with_pitch(msg.note) return NoteOnEvent(timestamp=time, pitch_class=note.pitch_class, octave=note.octave, accidental=note.accidental, velocity=msg.velocity, voice=voice) elif msg.type == 'note_off': note = Note().with_pitch(msg.note) return NoteOffEvent(timestamp=time, pitch_class=note.pitch_class, octave=note.octave, accidental=note.accidental, voice=voice) return None
def on_message ( self, virtual_keyboard : KeyboardLibrary, msg : mido.Message ): if msg.type == 'note_on': note = Note().with_pitch( msg.note ) virtual_keyboard.on_press( PianoKey( note ) ) elif msg.type == 'note_off': note = Note().with_pitch( msg.note ) virtual_keyboard.on_release( PianoKey( note ) ) virtual_keyboard.on_press( MidiEvent( msg ) )
def note_to_ast(self, context: Context, voice: Voice, event: NoteEvent) -> ast.NoteNode: return ast.NoteNode( Note(pitch_class=event.pitch_class, octave=event.octave - voice.octave, accidental=event.accidental, value=voice.get_relative_value(event.value)))
def note(self, tree): position = self._get_position(tree) accidental, (pitch_class, octave) = tree.children[0] value = Fraction(1) if len(tree.children) == 2: value = tree.children[1] note = Note(pitch_class=pitch_class, octave=octave, value=value, accidental=accidental) return NoteNode(note, position)
def chord_shortcut(self, tree): position = self._get_position(tree) value = Fraction(1) if len(tree.children) == 3: value = tree.children[2] accidental, (pitch_class, octave) = tree.children[0] chord = tree.children[1] note = Note(pitch_class=pitch_class, octave=octave, value=value, accidental=accidental) return ChordNode(Chord.from_abbreviature(note, chord, value), position=position)
def chord_manual(self, tree): position = self._get_position(tree) value = Fraction(1) x = len(tree.children) if tree.children and isnumber(tree.children[-1]): value = tree.children[-1] x = -1 notes: List[Note] = [] for accidental, (pitch_class, octave) in tree.children[:x]: notes.append( Note(pitch_class=pitch_class, octave=octave, value=value, accidental=accidental)) return ChordNode(Chord(notes, None, value), position=position)
def deserialize(data: str, parameters: Dict[str, Any]) -> 'PianoKey': return PianoKey(Note.from_pitch(int(data)))
def NODE_PITCH_RAW(self, token): return Note.parse_pitch_octave(str(token))