當前位置: 首頁>>代碼示例>>Python>>正文


Python Keyboard.note_on方法代碼示例

本文整理匯總了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
開發者ID:souca,項目名稱:sixthdev,代碼行數:34,代碼來源:readmidi.py


注:本文中的keyboard.Keyboard.note_on方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。