本文整理匯總了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