本文整理汇总了Python中utils.Utils.getNotes方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.getNotes方法的具体用法?Python Utils.getNotes怎么用?Python Utils.getNotes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Utils
的用法示例。
在下文中一共展示了Utils.getNotes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CacheTests
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getNotes [as 别名]
class CacheTests(unittest.TestCase):
def setUp(self):
self.utils = Utils();
def test_cacheScale(self):
cache = ScaleCache(False);
cache.cacheScale('E', 'diatonic');
self.assertIn('diatonicE', cache.cache);
self.assertNotIn('diatonicA', cache.cache);
def test_cacheHoleScale(self):
cache = ScaleCache(False);
cache.cacheHoleScale('diatonic');
for note in self.utils.getNotes():
self.assertIn('diatonic' + note, cache.cache);
self.assertNotIn('lydian' + 'C', cache.cache);
def test_checkInCache(self):
cache = ScaleCache(False);
cache.cacheHoleScale('diatonic');
self.assertTrue(cache.checkInCache('C', 'diatonic'));
self.assertFalse(cache.checkInCache('C', 'lydian'));
def test_cacheAllScales(self):
cache = ScaleCache(False);
cache.cacheAllScales();
for scale in self.utils.getAvailableScales():
for note in self.utils.getNotes():
self.assertIn(scale + note, cache.cache);
示例2: __init__
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getNotes [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: Gui
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getNotes [as 别名]
#.........这里部分代码省略.........
,bigincrement=1,borderwidth='0',command=self._on__ScaleTrans_command
,foreground='#2b3633',from_=-12,highlightbackground='#3b3c3c'
,highlightcolor='#3b3c3c',highlightthickness='0'
,label='Transpose(cents)',orient='horizontal',resolution=1
,sliderlength='50',tickinterval=0,to=12)
self._ScaleTrans.pack(expand='yes',fill='x',side='left')
self._Frame9 = Frame(self._Frame18,background='#016678')
self._Frame9.pack(expand='yes',fill='both',side='left')
self._ButtonAutoMode = Button(self._Frame9,activebackground='#ffffff'
,activeforeground='#2b3633',background='#FFFFCD',text='Magic mode'
,width='7')
self._ButtonAutoMode.pack(expand='yes',side='bottom')
self._Frame34 = Frame(self._Frame18,background='#016678')
self._Frame34.pack(expand='yes',fill='both',side='left')
self._ButtonQuit = Button(self._Frame34,activebackground='#BB1167'
,background='#CD0045',command=self._on__ButtonQuit_command
,text='Quit')
self._ButtonQuit.pack(expand='yes',side='left')
############### GUI ###############
self._MenuInput.menu = Menu(self._MenuInput, tearoff = 0 );
self._MenuInput["menu"] = self._MenuInput.menu;
self._MenuOutput.menu = Menu(self._MenuOutput, tearoff = 0 );
self._MenuOutput["menu"] = self._MenuOutput.menu;
self.midi_in = None;
self.midi_out = None;
self.check_midi_ports();
self._ButtonAutoMode.config(command=self.process_auto_mode_change);
self.showMessage("Loading...");
for note in self.utils.getNotes():
self._ListboxNote.insert(END, note);
for scale in self.utils.getAvailableScales():
self._ListboxScale.insert(END, scale);
self.current_scale = [10];
self.current_note = [0];
self.process_note_change(self.current_note);
self.showMessage("Ready to work, sir!");
self.current_note = ();
self.current_scale = ();
self.poll_lists(); # start polling the list
def process_auto_mode_change(self):
if self.auto_mode:
self.auto_mode = False;
else:
self.auto_mode = True;
self.showMessage("Magic Mode!");
def check_midi_ports(self):
if self.midi_in is not None:
self.midi_in.close_port();
if self.midi_out is not None:
self.midi_out.close_port();
self.midi_in = rtmidi.MidiIn();
self.midi_out = rtmidi.MidiOut();
ports_in = self.midi_in.ports;
示例4: __init__
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getNotes [as 别名]
class Mapper:
def __init__(self):
self.utils = Utils();
self.all_keys = self.utils.getNotes();
self.white_keys = self.utils.getWhiteKeys();
def mapScaleToWhiteKeys(self, scale):
result_map = {};
for note in scale:
result_map[note] = note;
not_mapped_keys = self.getNotMapped(result_map.keys(), self.all_keys);
mapped_keys = result_map.keys();
for note in not_mapped_keys:
result_map[note] = self.searchEmpty(note, mapped_keys);
return result_map;
def searchEmpty(self, note, result_map):
dim_candidate = note;
aug_candidate = note;
while(True):
dim_candidate = self.utils.normalizeNote(notes.diminish(dim_candidate));
aug_candidate = self.utils.normalizeNote(notes.augment(aug_candidate));
if dim_candidate in result_map:
return dim_candidate;
if aug_candidate in result_map:
return aug_candidate;
def getNotMapped(self, a, b):
return [bb for bb in b if bb not in a]
def getMap(self, scale_to_map):
return self.mapScaleToWhiteKeys(scale_to_map);
def getScaleToMap(self, rootNote, scale):
if self.utils.checkIsCustom(scale):
scale_to_map = self.calcScale(rootNote, self.utils.getIntervalsForScale(scale));
else:
method = getattr(scales, scale);
scale_to_map = method(rootNote);
return self.utils.normalizeScale(scale_to_map);
def calcScale(self, note, intervals):
result_scale = [];
result_scale.append(note);
last_aug_note = note;
for interval in intervals:
last_aug_note = self.augmentNote(last_aug_note, interval);
result_scale.append(last_aug_note);
return result_scale;
def augmentNote(self, note, augSteps = 1):
result_note = note;
for step in range(0, augSteps):
result_note = self.utils.normalizeNote(notes.augment(result_note));
return result_note;
示例5: MainForm
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getNotes [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);
#.........这里部分代码省略.........