本文整理汇总了Python中mapper.Mapper.getMap方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.getMap方法的具体用法?Python Mapper.getMap怎么用?Python Mapper.getMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapper.Mapper
的用法示例。
在下文中一共展示了Mapper.getMap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MapperTests
# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import getMap [as 别名]
class MapperTests(unittest.TestCase):
def setUp(self):
self.mapper = Mapper();
self.utils = Utils();
utils_for_tests = UtilsForTests();
self.test_map_scale_to_white_keys = utils_for_tests.loadTestCorpus('test_corpus/test_to_white_keys_corpus');
self.test_get_map = utils_for_tests.loadTestCorpus('test_corpus/test_get_map_corpus');
def test_mapScaleToWhiteKeys(self):
for case in self.test_map_scale_to_white_keys:
mapped_scale = self.mapper.mapScaleToWhiteKeys(case[0]);
self.assertDictEqual(mapped_scale, case[1]);
def test_getMap(self):
for case in self.test_get_map:
map = self.mapper.getMap(case[0],case[1]);
self.assertDictEqual(map, case[2]);
@unittest.skip("Preformance test")
def test_TimeitGetMap(self):
setup = "from utils import Utils; from mapper import Mapper; mapper = Mapper(); utils = Utils();"
code_to_test = """
for scale in utils.getAvailableScales():
for note in utils.getNotes():
mapper.getMap(note, scale);
"""
result_first = timeit.repeat(code_to_test, setup = setup,repeat=100, number=100);
result_avg = reduce(lambda x, y: x + y, result_first) / len(result_first)
print("Result avg: " + str(result_avg));
示例2: __init__
# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import getMap [as 别名]
class ScaleCache:
cache = {};
def __init__(self, cacheAll = True):
self.mapper = Mapper();
self.utils = Utils();
if cacheAll:
self.cacheAllScales();
def cacheAllScales(self):
for scale in self.utils.getAllAvailableScales():
self.cacheHoleScale(scale);
def cacheHoleScale(self, scale):
for note in self.utils.getNotes():
self.cacheScale(note, scale);
def cacheScale(self, note, scale):
scale_to_map = self.mapper.getScaleToMap(note, scale);
mapped_scale = self.mapper.getMap(scale_to_map);
result = {'scale_to_map':scale_to_map, 'mapped_scale': mapped_scale}
self.cache[note + scale] = result;
def checkInCache(self, note, scale):
return (note + scale) in self.cache;
def clearCache(self):
self.cache.clear();
def getScaleFromCache(self, note, scale):
if self.checkInCache(note, scale):
return self.cache[note + scale];
else:
self.cacheScale(note, scale);
return self.cache[note + scale];
def __del__(self):
self.clearCache();
示例3: MainForm
# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import getMap [as 别名]
class MainForm(QtGui.QMainWindow):
NOTE_OFF = 0x80
NOTE_ON = 0x90
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.utils = Utils();
self.cache = ScaleCache();
self.mapper = Mapper();
self.scale_to_map = [];
self.mapped_scale = {};
self.transpose = 0;
self.autoScale = False;
self.ui = Ui_MainWindow();
self.ui.setupUi(self);
self.loadAvailableScales();
self.loadInitScale();
self.midi_in = None;
self.midi_out = None;
self.check_midi_ports();
self.ui.statusBar.showMessage("Ready for rock'N'roll!",1000 * 20);
def loadAvailableScales(self):
for scale in self.utils.getAllAvailableScales():
self.ui.listWidgetScales.addItem(scale);
def loadInitScale(self):
self.ui.listWidgetNotes.setCurrentRow(0);
self.ui.listWidgetScales.setCurrentRow(0);
result = self.cache.getScaleFromCache(str(self.ui.listWidgetNotes.item(0).text()),str(self.ui.listWidgetScales.item(0).text()));
self.setNewScale(result);
@QtCore.pyqtSlot(str)
def on_listWidgetScales_currentTextChanged(self, scale):
currNote = self.ui.listWidgetNotes.currentItem();
if currNote is not None:
result = self.cache.getScaleFromCache(str(currNote.text()), str(scale));
self.setNewScale(result);
self.ui.statusBar.showMessage("Mapped scale: %s-%s"%(str(currNote.text()),str(scale)), 1000 * 5);
@QtCore.pyqtSlot(str)
def on_listWidgetNotes_currentTextChanged(self, note):
currScale = self.ui.listWidgetScales.currentItem();
if currScale is not None:
result = self.cache.getScaleFromCache(str(note), str(currScale.text()));
self.setNewScale(result);
self.autoScale = False;
self.ui.pushButtonMagic.setChecked(False);
self.ui.statusBar.showMessage("Mapped scale: %s-%s"%(str(note),str(currScale.text())), 1000 * 5);
def setNewScale(self, scales):
self.scale_to_map = scales['scale_to_map'];
self.mapped_scale = scales['mapped_scale'];
self.showOnKeys();
def showOnKeys(self):
for key in self.utils.getNotes():
replacedKey = key.replace('#','S');
if key in self.scale_to_map:
new_state = True;
else:
new_state = False;
eval('self.ui.pushButton' + replacedKey + ".setChecked(" + str(new_state) + ")");
def setNewKeyState(self, key, state):
if state:
self.scale_to_map.append(key);
self.mapped_scale = self.mapper.getMap(self.scale_to_map);
else:
if key in self.scale_to_map:
self.scale_to_map.remove(key);
if len(self.scale_to_map) != 0:
self.mapped_scale = self.mapper.getMap(self.scale_to_map);
self.autoScale = False;
self.ui.pushButtonMagic.setChecked(False);
self.ui.statusBar.showMessage("Custom scale: " + str(self.scale_to_map), 1000 * 5);
@QtCore.pyqtSlot(bool)
def on_pushButtonC_clicked(self, status):
self.setNewKeyState('C', status);
@QtCore.pyqtSlot(bool)
def on_pushButtonCS_clicked(self, status):
self.setNewKeyState('C#', status);
@QtCore.pyqtSlot(bool)
def on_pushButtonD_clicked(self, status):
self.setNewKeyState('D', status);
#.........这里部分代码省略.........