def generate_blues_scale(key="C"): """Returns an ordered list of the notes of the blues scale in this key. \ For example: if the key is set to 'C', this function will return \ `['C', 'D#', 'F', 'F#', 'G', 'A#']`. \ This function will raise an !NoteFormatError if the key isn't recognised""" if not (notes.is_valid_note(key)): raise NoteFormatError, "Unrecognised format for key '%s'" % key result = [] fifth_index = notes.fifths.index(key[0]) result.append(intervals.unison(key)) result.append(notes.diminish(intervals.third(key, key))) result.append(intervals.third(key, key)) result.append(intervals.fourth(key, key)) result.append(notes.diminish(intervals.fifth(key, key))) result.append(intervals.fifth(key, key)) result.append(notes.diminish(intervals.seventh(key, key))) # Remove redundant #'s and b's from the result result = map(notes.remove_redundant_accidentals, result) tonic = result.index(notes.remove_redundant_accidentals(key)) result = result[tonic:] + result[:tonic] return result
def test_diminish(self): known = { "C" : "Cb", "C#" : "C", "C##" : "C#", "Cb" : "Cbb"} map(lambda x: self.assertEqual(known[x], notes.diminish(x),\ "The diminished note of %s is not %s, expecting %s" % (x, notes.diminish(x), known[x])), known.keys())
def test_diminish(self): known = {'C': 'Cb', 'C#': 'C', 'C##': 'C#', 'Cb': 'Cbb'} map( lambda x: self.assertEqual( known[x], notes.diminish( x), 'The diminished note of %s is not %s, expecting %s' % (x, notes.diminish(x), known[x])), known.keys())
def test_diminish(self): known = {"C": "Cb", "C#": "C", "C##": "C#", "Cb": "Cbb"} for x in known: self.assertEqual( known[x], notes.diminish(x), "The diminished note of %s is not %s, expecting %s" % (x, notes.diminish(x), known[x]), )
def test_diminish(self): known = { 'C': 'Cb', 'C#': 'C', 'C##': 'C#', 'Cb': 'Cbb', } map(lambda x: self.assertEqual(known[x], notes.diminish(x), 'The diminished note of %s is not %s, expecting %s' % (x, notes.diminish(x), known[x])), known.keys())
def from_shorthand(note, interval, up=True): """Return the note on interval up or down. Examples: >>> from_shorthand('A', 'b3') 'C' >>> from_shorthand('D', '2') 'E' >>> from_shorthand('E', '2', False) 'D' """ # warning should be a valid note. if not notes.is_valid_note(note): return False # [shorthand, interval function up, interval function down] shorthand_lookup = [ ['1', major_unison, major_unison], ['2', major_second, minor_seventh], ['3', major_third, minor_sixth], ['4', major_fourth, major_fifth], ['5', major_fifth, major_fourth], ['6', major_sixth, minor_third], ['7', major_seventh, minor_second], ] # Looking up last character in interval in shorthand_lookup and calling that # function. val = False for shorthand in shorthand_lookup: if shorthand[0] == interval[-1]: if up: val = shorthand[1](note) else: val = shorthand[2](note) # warning Last character in interval should be 1-7 if val == False: return False # Collect accidentals for x in interval: if x == '#': if up: val = notes.augment(val) else: val = notes.diminish(val) elif x == 'b': if up: val = notes.diminish(val) else: val = notes.augment(val) else: return val
def generate_note(self, state): wild = state['wild'] if self.last_note == '': n = choice(state["chord"]) else: if self.up: n = notes.augment(self.last_note) else: n = notes.diminish(self.last_note) self.last_note = n if random() < 0.20: self.up = not(self.up) if random() < 0.3 * wild: self.params["let_ring"] = False return [Note(n)] elif random() < 0.15 * wild and state["tick"] % 2 == 0: self.params["let_ring"] = True return [Note(self.last_note)] elif random() < 0.1 * wild: self.params["let_ring"] = True c = choice(state["chord"]) self.last_note = c return [Note(c)] else: if random() > 0.05: self.params['let_ring'] = True else: self.params['let_ring'] = False return None
def get_interval(note, interval, key='C'): """Return the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases. """ intervals = list( map(lambda x: (notes.note_to_int(key) + x) % 12, [ 0, 2, 4, 5, 7, 9, 11, ])) key_notes = keys.get_notes(key) for x in key_notes: if x[0] == note[0]: result = (intervals[key_notes.index(x)] + interval) % 12 if result in intervals: return key_notes[intervals.index(result)] + note[1:] else: return notes.diminish(key_notes[intervals.index((result + 1) % 12)] + note[1:])
def generate_note(self, state): wild = 1.0 if "wild" in state: wild = state["wild"] if state["tick"] % (state["resolution"] / 4.0) == 0 and random() < 1.0 * wild: n = Note(choice(state["chord"])) while n > Note("E", 3): if n.octave >= 3: n.octave_down() else: break return [n] elif ( state["resolution"] > 4 and state["tick"] % (state["resolution"] / 4.0) == state["resolution"] / 8 and random() < 0.2 * wild ): n = Note(choice(state["chord"])) while n > Note("E", 3): if n.octave >= 3: n.octave_down() else: break n.name = notes.diminish(n.name) return [n]
def to_chords(progression, key="C"): """Convert a list of chord functions or a string to a list of chords. Examples: >>> to_chords(['I', 'V7']) [['C', 'E', 'G'], ['G', 'B', 'D', 'F']] >>> to_chords('I7') [['C', 'E', 'G', 'B']] Any number of accidentals can be used as prefix to augment or diminish; for example: bIV or #I. All the chord abbreviations in the chord module can be used as suffixes; for example: Im7, IVdim7, etc. You can combine prefixes and suffixes to manage complex progressions: #vii7, #iidim7, iii7, etc. Using 7 as suffix is ambiguous, since it is classicly used to denote the seventh chord when talking about progressions instead of just the dominant seventh chord. We have taken the classic route; I7 will get you a major seventh chord. If you specifically want a dominanth seventh, use Idom7. """ if isinstance(progression, six.string_types): progression = [progression] result = [] for chord in progression: # strip preceding accidentals from the string (roman_numeral, acc, suffix) = parse_string(chord) # There is no roman numeral parsing, just a simple check. Sorry to # disappoint. warning Should throw exception if roman_numeral not in numerals: return [] # These suffixes don't need any post processing if suffix == "7" or suffix == "": roman_numeral += suffix # ahh Python. Everything is a dict. r = chords.__dict__[roman_numeral](key) else: r = chords.__dict__[roman_numeral](key) r = chords.chord_shorthand[suffix](r[0]) while acc < 0: r = [notes.diminish(x) for x in r] acc += 1 while acc > 0: r = [notes.augment(x) for x in r] acc -= 1 result.append(r) return result
def diminished_seventh(note): """Build a diminished seventh chord on note. Example: >>> diminished_seventh('C') ['C', 'Eb', 'Gb', 'Bbb'] """ return (diminished_triad(note) + [notes.diminish(intervals.minor_seventh(note))])
def dominant_flat_five(note): """Build a dominant flat five chord on note. Example: >>> dominant_flat_five('C') ['C', 'E', 'Gb', 'Bb'] """ res = dominant_seventh(note) res[2] = notes.diminish(res[2]) return res
def descending(self): notes = [self.tonic] for note in reversed(get_notes(self.key)): if intervals.determine(note, notes[-1]) == ('major second'): notes.append(reduce_accidentals(diminish(notes[-1]))) notes.append(note) else: notes.append(note) notes.pop() return notes * self.octaves + [notes[0]]
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 augment_or_diminish_until_the_interval_is_right(note1, note2, interval): """A helper function for the minor and major functions. You should probably not use this directly. """ cur = measure(note1, note2) while cur != interval: if cur > interval: note2 = notes.diminish(note2) elif cur < interval: note2 = notes.augment(note2) cur = measure(note1, note2) # We are practically done right now, but we need to be able to create the # minor seventh of Cb and get Bbb instead of B######### as the result val = 0 for token in note2[1:]: if token == '#': val += 1 elif token == 'b': val -= 1 # These are some checks to see if we have generated too much #'s or too much # b's. In these cases we need to convert #'s to b's and vice versa. if val > 6: val = val % 12 val = -12 + val elif val < -6: val = val % -12 val = 12 + val # Rebuild the note result = note2[0] while val > 0: result = notes.augment(result) val -= 1 while val < 0: result = notes.diminish(result) val += 1 return result
def get_note_pattern(pattern, key): if pattern[0] == 1 : note = intervals.unison(key) elif pattern[0] == 2 : note = intervals.second(key, key) elif pattern[0] == 3 : note = intervals.third(key, key) elif pattern[0] == 4 : note = intervals.fourth(key, key) elif pattern[0] == 5 : note = intervals.fifth(key, key) elif pattern[0] == 6 : note = intervals.sixth(key, key) elif pattern[0] == 7 : note = intervals.seventh(key, key) if pattern[3] == "bemol": note = notes.diminish(note) elif pattern[3] == "diese" : note = notes.augment(note) return note
def get_interval(note, interval, key='C'): """Return the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases. """ intervals = list(map(lambda x: (notes.note_to_int(key) + x) % 12, [ 0, 2, 4, 5, 7, 9, 11, ])) key_notes = keys.get_notes(key) for x in key_notes: if x[0] == note[0]: result = (intervals[key_notes.index(x)] + interval) % 12 if result in intervals: return key_notes[intervals.index(result)] + note[1:] else: return notes.diminish(key_notes[intervals.index((result + 1) % 12)] + note[1:])
def minor_unison(note): return notes.diminish(note)
# -*- coding: utf-8 -*- #2018/8/26 #python2 import mingus.core.notes as notes #检查音符合法性 notes.is_valid_note('C') # True #音符、值互转 notes.note_to_int('C') # 0 notes.int_to_note(1) # C# #半音升降 notes.augment('C') # C# notes.diminish('C#') # C #大小调转化(无方法) #notes.to_minor('C') # A #notes.to_major('A') # C #无模块 #import mingus.core.diatonic as diatonic #十二音 #diatonic.basic_keys #E调七音 #diatonic.get_notes('E') import mingus.core.intervals as interval #间隔半音数 interval.measure('C', 'D') #2 import mingus.core.scales as scales #爱奥尼音阶对象
def ascending(self): notes = Major(self.tonic).ascending()[:-1] notes[5] = diminish(notes[5]) return notes * self.octaves + [notes[0]]
def diminish(self): """Call notes.diminish with this note as argument.""" self.name = notes.diminish(self.name)
def ascending(self): notes = MinorPentatonic(self.tonic).ascending()[:-1] notes.insert(3, diminish(notes[3])) return notes * self.octaves + [notes[0]]
def ascending(self): notes = HarmonicMinor(self.tonic).ascending()[:-1] notes[1] = diminish(notes[1]) return notes * self.octaves + [notes[0]]
def descending(self): notes = NaturalMinor(self.tonic).descending()[:-1] notes[6] = diminish(notes[6]) return notes * self.octaves + [notes[0]]
''' Created on Jan 6, 2017 @author: stephenkoh ''' import mingus.core.notes as notes note = str(input('Please enter a note: ')) if (notes.is_valid_note(note)): note = notes.to_minor(note) note = notes.diminish(note) print(note)
def diminish(self): """Lowers the note by a half step""" self._mingus_note = _mingus_notes.diminish(str(self._mingus_note)) self._pitch.accidentals += 'b' return True
def scratch(): import mingus.core.notes as notes print notes.reduce_accidentals('B#') ## output is 'C' print notes.remove_redundant_accidentals('C###############') print notes.diminish('C##############')