本文整理汇总了Python中device.Device.updateMapping方法的典型用法代码示例。如果您正苦于以下问题:Python Device.updateMapping方法的具体用法?Python Device.updateMapping怎么用?Python Device.updateMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类device.Device
的用法示例。
在下文中一共展示了Device.updateMapping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LearnDialog
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import updateMapping [as 别名]
#.........这里部分代码省略.........
self.knownCtrl.add(ctrl_key)
self.knownBtn.add(btn_key)
elif self.send_midi_to == self.START_STOP:
self.current_line_pitch.append(btn_id)
cell = LearnCell(self)
cell.label.setText("Ch %s\n%s"
% (channel + 1,
self.displayNote(pitch)))
cell.setStyleSheet(self.NEW_CELL_STYLE)
self.gridLayout.addWidget(cell,
self.current_line,
self.current_row)
self.current_row += 1
self.firstLine.setEnabled(True)
self.knownCtrl.add(ctrl_key)
self.knownBtn.add(btn_key)
def accept(self):
try:
self.parseInitCommand()
super(LearnDialog, self).accept()
except Exception as ex:
QMessageBox.critical(self,
"Invalid init commands",
str(ex))
def reject(self):
self.gui.is_learn_device_mode = False
self.gui.redraw()
super(LearnDialog, self).reject()
def onSave(self):
self.device.name = str(self.name.text())
self.device.black_vel = int(self.black_vel.value())
self.device.green_vel = int(self.green_vel.value())
self.device.blink_green_vel = int(self.blink_green_vel.value())
self.device.red_vel = int(self.red_vel.value())
self.device.blink_red_vel = int(self.blink_red_vel.value())
self.device.amber_vel = int(self.amber_vel.value())
self.device.blink_amber_vel = int(self.blink_amber_vel.value())
self.device.mapping['init_command'] = self.parseInitCommand()
self.original_device.updateMapping(self.device.mapping)
self.gui.is_learn_device_mode = False
self.callback(self.original_device)
self.gui.redraw()
def displayNote(self, note_dec):
octave, note = divmod(note_dec, 12)
octave += 1
note_str = self.NOTE_NAME[note]
return note_str[:1] + str(octave) + note_str[1:]
def displayCtrl(self, ctrl_key):
(msg_type, channel, pitch) = ctrl_key
if msg_type == self.NOTEON:
type = "Note On"
note = self.displayNote(pitch)
elif msg_type == self.NOTEOFF:
type = "Note Off"
note = self.displayNote(pitch)
elif msg_type == self.MIDICTRL:
type = "Controller"
note = str(pitch)
else:
type = "Type=%s" % msg_type
return "Channel %s %s %s" % (channel + 1,
type,
note)
def displayBtn(self, btn_id):
(msg_type, channel, pitch, velocity) = btn_id
ctrl_key = (msg_type, channel, pitch)
return self.displayCtrl(ctrl_key)
def parseInitCommand(self):
raw_str = str(self.init_command.toPlainText())
init_commands = []
line = 1
for raw_line in raw_str.split("\n"):
matches = _init_cmd_regexp.match(raw_line)
if matches:
byte1 = int(matches.group(1))
byte2 = int(matches.group(2))
byte3 = int(matches.group(3))
if not 0 <= byte1 < 256:
raise Exception("First number out of range on line %s"
% line)
if not 0 <= byte2 < 256:
raise Exception("Second number out of range on line %s"
% line)
if not 0 <= byte3 < 256:
raise Exception("Third number out of range on line %s"
% line)
init_commands.append((byte1, byte2, byte3))
elif len(raw_line):
raise Exception("Invalid format for Line %s :\n%s"
% (line, raw_line))
line = line + 1
return init_commands