import convert_to import load_asset from Fingering import fingering scales = load_asset.load('scales') mod = False #scales[0] = ailias,scales[1] = scales #adds scale with name def add(ns,name): new = scale(ns).transpose('c').notes scales[1].append(new) scales[0][name] = len(scales[1])-1 load_asset.save(scales,'scales') #adds alternative name to scale def alias(exist,con): scale[0][con] = scale[0][exist] load_asset.save(scales,'scales') #creates scale with specified starting note, type, and notation def create(n,scale_type,notation = 'flats'): return scale( scales[1][ scales[0][scale_type.lower()] ] ).transpose(n,notation) class scale: #converts scale notes to above c0, in effect giving raw intervals from the start note def normalize(self): #ensures that the start note is the same as the end note. This affects the data returned by the .notes method if convert_to.above_c(self.notes[0])%12 != convert_to.above_c(self.notes[-1])%12: self.notes.append(self.notes[0]) #subtracts starting note from each note start = convert_to.above_c(self.notes[0]) note_list = list( map( lambda n: convert_to.above_c(n)-start, self.notes ) ) #ensures scales are ascending for i in range(len(note_list)-1): while note_list[i] > note_list[i+1]: note_list[i+1] += 12 return note_list #returns fingering with specified device def fingers(self,d,tuning_a = 440): return list( map( lambda n: '{} ({})'.format(n,fingering(n,d,tuning_a)), self.notes ) ) #transposes scale to specified note def transpose(self,n,notation = 'flats'): n = convert_to.above_c(n) return scale( list( map( lambda m: convert_to.notename(m+n,notation), self.intv ) ) ) def __init__(self,notes): self.notes = notes self.intv = self.normalize()