当前位置: 首页>>代码示例>>Python>>正文


Python Mapper.getScaleToMap方法代码示例

本文整理汇总了Python中mapper.Mapper.getScaleToMap方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.getScaleToMap方法的具体用法?Python Mapper.getScaleToMap怎么用?Python Mapper.getScaleToMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mapper.Mapper的用法示例。


在下文中一共展示了Mapper.getScaleToMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import getScaleToMap [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();
开发者ID:doino-gretchenliev,项目名称:Mid-Magic,代码行数:42,代码来源:cache.py

示例2: Gui

# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import getScaleToMap [as 别名]

#.........这里部分代码省略.........
                    else:
                        scale = self.utils.getAvailableScales()[self._ListboxScale.curselection()[0]];
                        self.mapped_scale = self.cache.getScaleFromCache(note_scale[0],scale);
                        self.showMessage("Magic mode scale:%s-%s"%(note_scale[0],scale));
                        self.midi_out.send_message(message);
                else:
                    self.send_modif_massage(message);
            else:
                self.send_modif_massage(message);
        else:
            self.midi_out.send_message(message);
            
    def send_modif_massage(self, message):
        note_octave = self.utils.getNoteAndOctave(message[1]);
        message[1] = self.utils.getMidiNumber(self.mapped_scale[note_octave[0]], note_octave[1]);
        message[1] += self.transpose;
        self.midi_out.send_message(message);
        
    
    def showCurrentNote(self, message):
        note_octave = self.utils.getNoteAndOctave(message[1]);
        note_name = note_octave[0];
        octave = note_octave[1];
        if (message[0] & 0xF0) in self.event_types:
            self.showMessage("Note: %s, Octave: %s, Vel: %s"%(note_name,octave,message[2]));
            
    def _on__ButtonScanMidi_command(self,Event=None):
        self.check_midi_ports();

    def process_note_change(self, note):
        if len(note) != 0 and len(self.current_scale) != 0:
            note_name = notes.int_to_note(note[0]);
            scale_name = self.utils.getAvailableScales()[self.current_scale[0]];
            self.scale_to_map = self.mapper.getScaleToMap(note_name, scale_name);
            self.mapped_scale = self.cache.getScaleFromCache(note_name, scale_name);
            self.show_scale_to_buttons();
            self.auto_mode = False;
            self.showMessage(note_name + " - " + scale_name);
     
    def process_scale_change(self, scale):
        if len(scale) != 0 and len(self.current_note) != 0:
            note_name = notes.int_to_note(self.current_note[0]);
            scale_name = self.utils.getAvailableScales()[scale[0]];
            self.scale_to_map = self.mapper.getScaleToMap(note_name, scale_name);
            self.mapped_scale = self.cache.getScaleFromCache(note_name, scale_name);
            self.show_scale_to_buttons();
            self.auto_mode = False;
            self.showMessage(note_name + " - " + scale_name);
            
    def show_scale_to_buttons(self):
        for note in self.utils.getNotes():
            button_name = note.replace('#','Sharp');
            button_name = "self._Button" + button_name;
            
            if note in self.scale_to_map:
                self.button_state_map[note] = True 
                if '#' in note:
                    button_color = self.button_color_state_map_black[True];
                else:
                    button_color = self.button_color_state_map_white[True];
            else:
                self.button_state_map[note] = False
                if '#' in note:
                    button_color = self.button_color_state_map_black[False];
                else:
                    button_color = self.button_color_state_map_white[False];
开发者ID:doino-gretchenliev,项目名称:Mid-Magic,代码行数:70,代码来源:ui.py


注:本文中的mapper.Mapper.getScaleToMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。