audioworkstation.keyboard.keyboard のソースコード
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""MIDI sequencer function for USB MIDI Keyboard"""
from pathlib import Path
from json import load
from kivy.logger import Logger # noqa: F401
from kivy.uix.screenmanager import Screen
from kivy.clock import Clock
from kivy.event import EventDispatcher
from kivy.uix.togglebutton import ToggleButton
from kivy.properties import (
ObjectProperty,
NumericProperty,
DictProperty,
)
from kivy.lang import Builder
from . import mididriver as MD
Builder.load_file(str(Path(__file__).with_name("keyboard.kv")))
[ドキュメント]class KeyboardView(Screen):
"""KeyboardView places GM Sound Set and GM Sound Set Group layout widget."""
#: ObjectProperty: Layout for GM Sound Set Group
gmssg = ObjectProperty()
#: ObjectProperty: Layout for GM Sound Set
gmss = ObjectProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
Logger.debug("keyboard: initializing...")
self.msm = MD.MidiSoundModule()
self.msm.programchange(0)
Clock.schedule_once(lambda dt: self.msm.sounding())
with open(file="config/gmsoundsetgroping.json", mode="r") as fp:
gmssg_json = load(fp)
for name, presets in gmssg_json.items():
self.add_gmssg_button(name, presets)
self.add_gmss_buttons()
[ドキュメント] def unregister(self) -> None:
"""Processing when terminating a View."""
pass
[ドキュメント] def select_gmss(self, gmss_button: GMSoundSetButton) -> None:
"""Select program(preset) number assigned to the button.
:param GMSoundSetButton gmss_button: selected button
"""
Logger.debug(f"keyboard: program change {gmss_button.preset_num}")
self.msm.programchange(gmss_button.preset_num)
Clock.schedule_once(lambda dt: self.msm.sounding())
[ドキュメント] def select_gmssg(self, gmssg_button: GMSoundSetGroupButton) -> None:
"""Select GM Sound Set Group assigned to the button.
:param GMSoundSetGroupButton gmssg_button: selected button
"""
presets_num: list = list(
reversed(
range(gmssg_button.presets["Start"], gmssg_button.presets["End"] + 1)
)
)
for i in range(8):
self.gmss.children[i].text = self.msm.preset_name(presets_num[i])
self.gmss.children[i].preset_num = presets_num[i]
@property
def volume(self) -> int:
"""int: volume"""
return self.msm.volume
@volume.setter
def volume(self, value: int) -> None:
self.msm.volume = value
if __name__ == "__main__":
print(__file__)