本文整理汇总了Python中keyboard.Keyboard.note_on方法的典型用法代码示例。如果您正苦于以下问题:Python Keyboard.note_on方法的具体用法?Python Keyboard.note_on怎么用?Python Keyboard.note_on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyboard.Keyboard
的用法示例。
在下文中一共展示了Keyboard.note_on方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ScoreBuilder
# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import note_on [as 别名]
class ScoreBuilder(MidiOutStream):
def __init__(self):
MidiOutStream.__init__(self)
self._last_time = 0
self.keyboard = Keyboard()
self._last_status = None
self.score = []
def note_on(self, channel=0, note=0x40, velocity=0x40):
# print ("note_on: %s" % note)
self.keyboard.note_on(note)
def note_off(self, channel=0, note=0x40, velocity=0x40):
# print ("note_off: %s" % note)
self.keyboard.note_off(note)
def update_time(self, new_time=0, relative=1):
# print ("new_time: %s" % new_time)
MidiOutStream.update_time(self, new_time, relative)
if self._absolute_time != self._last_time:
diff = self._absolute_time - self._last_time
# print keyboard.format(self.keyboard.snapshot())
self.score.append(self.keyboard.snapshot())
self._last_status = [continued(x) for x in self.keyboard.snapshot()]
for tick in range((diff / eighth_note) - 1):
# print keyboard.format(self._last_status)
self.score.append(self._last_status)
self._last_time = self._absolute_time