예제 #1
0
파일: test_notes.py 프로젝트: anzev/mingus
	def test_augment(self):
		known = { "C" : "C#",
				  "C#" : "C##",
				  "Cb" : "C",
				  "Cbb" : "Cb"}
		map(lambda x: self.assertEqual(known[x], notes.augment(x),\
				"The augmented note of %s is not %s, expecting %s" % (x, notes.augment(x), known[x])), known.keys())
예제 #2
0
 def test_augment(self):
     known = {'C': 'C#', 'C#': 'C##', 'Cb': 'C', 'Cbb': 'Cb'}
     map(
         lambda x: self.assertEqual(
             known[x], notes.augment(
                 x), 'The augmented note of %s is not %s, expecting %s' %
             (x, notes.augment(x), known[x])), known.keys())
예제 #3
0
 def test_augment(self):
     known = {"C": "C#", "C#": "C##", "Cb": "C", "Cbb": "Cb"}
     for x in known:
         self.assertEqual(
             known[x],
             notes.augment(x),
             "The augmented note of %s is not %s, expecting %s" %
             (x, notes.augment(x), known[x]),
         )
예제 #4
0
 def test_augment(self):
     known = {
         'C': 'C#',
         'C#': 'C##',
         'Cb': 'C',
         'Cbb': 'Cb',
         }
     map(lambda x: self.assertEqual(known[x], notes.augment(x),
         'The augmented note of %s is not %s, expecting %s' % (x,
         notes.augment(x), known[x])), known.keys())
예제 #5
0
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
예제 #6
0
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
예제 #7
0
	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
예제 #8
0
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
예제 #9
0
def lydian_dominant_seventh(note):
    """Build the lydian dominant seventh (7#11) on note.

    Example:
    >>> lydian_dominant_seventh('C')
    ['C', 'E', 'G', 'Bb', 'F#']
    """
    return (dominant_seventh(note) +
            [notes.augment(intervals.perfect_fourth(note))])
예제 #10
0
def lydian_dominant_seventh(note):
    """Build the lydian dominant seventh (7#11) on note.

    Example:
    >>> lydian_dominant_seventh('C')
    ['C', 'E', 'G', 'Bb', 'F#']
    """
    return (dominant_seventh(note) +
            [notes.augment(intervals.perfect_fourth(note))])
예제 #11
0
def augmented_triad(note):
    """Build an augmented triad on note.

    Example:
    >>> augmented_triad('C')
    ['C', 'E', 'G#']
    """
    return [note, intervals.major_third(note),
            notes.augment(intervals.major_fifth(note))]
예제 #12
0
 def ascending(self):
     notes = [self.tonic]
     for note in get_notes(self.key)[1:] + [self.tonic]:
         if intervals.determine(notes[-1], note) == ('major second'):
             notes.append(augment(notes[-1]))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
예제 #13
0
def dominant_sharp_ninth(note):
    """Build a dominant sharp ninth chord on note.

    Example:
    >>> dominant_ninth('C')
    ['C', 'E', 'G', 'Bb', 'D#']
    """
    res = dominant_ninth(note)
    res[4] = notes.augment(intervals.major_second(note))
    return res
예제 #14
0
def dominant_sharp_ninth(note):
    """Build a dominant sharp ninth chord on note.

    Example:
    >>> dominant_ninth('C')
    ['C', 'E', 'G', 'Bb', 'D#']
    """
    res = dominant_ninth(note)
    res[4] = notes.augment(intervals.major_second(note))
    return res
예제 #15
0
 def ascending(self):
     notes = [self.tonic]
     for note in get_notes(self.key)[1:] + [self.tonic]:
         if intervals.determine(notes[-1], note) == ('major second'):
             notes.append(augment(notes[-1]))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
예제 #16
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;
예제 #17
0
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
예제 #18
0
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
예제 #19
0
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
예제 #20
0
def transpose_to_relative_minor(track, original_key, harmonic):
    transposed_track = copy.deepcopy(track)
    if original_key in keys.major_keys:
        old_scale = keys.get_notes(original_key)
        new_key = keys.relative_minor(original_key)
        new_scale = keys.get_notes(new_key)

        if harmonic:
            new_scale[6] = notes.augment(new_scale[6])
            new_scale[6] = notes.reduce_accidentals(new_scale[6])

        input_notes = transposed_track.get_notes()
        for bar in input_notes:

            #Check if the nc contained in the bar/"note" is a pause, then do nothing
            nc = bar[-1]
            if nc is None:
                continue

            #Otherwise
            else:
                #For every actual note in the note containers (important if there is a chord)
                for note in nc:
                    #old_note = copy.deepcopy(note)
                    if note.name in old_scale:
                        index = old_scale.index(note.name)
                        note.name = new_scale[index]

                    else:
                        note.transpose("b3")
                        note.name = notes.reduce_accidentals(note.name)

                    # Fix octaves
                    if note.name[0] == 'A' or note.name[0] == 'B':
                        note.octave_down()

    else:
        print("input key is not major key")
    return transposed_track
예제 #21
0
 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;
예제 #22
0
'''
Created on Jan 6, 2017

@author: stephenkoh
'''

import mingus.core.keys as keys
import mingus.core.notes as notes

while (True):
    key = str(input('Please enter a key: '))
    keyz = keys.get_notes(key)
    #print(keys)
    for i in range(len(keyz)):
        keyz[i] = notes.augment(keyz[i])
    print(keyz)
예제 #23
0
def augmented_unison(note):
    return notes.augment(note)
예제 #24
0
# -*- 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
#爱奥尼音阶对象
예제 #25
0
 def augment(self):
     """Call notes.augment with this note as argument."""
     self.name = notes.augment(self.name)
예제 #26
0
def lydian_major_seventh(note):
    """Build the lydian major seventh (M7#11) on note.

    """
    return (major_seventh(note) +
            [notes.augment(intervals.perfect_fourth(note))])
예제 #27
0
 def augment(self):
     """Call notes.augment with this note as argument."""
     self.name = notes.augment(self.name)
예제 #28
0
 def ascending(self):
     notes = NaturalMinor(self.tonic).ascending()[:-1]
     notes[5] = augment(notes[5])
     notes[6] = augment(notes[6])
     return notes * self.octaves + [notes[0]]
예제 #29
0
파일: music.py 프로젝트: calebw3/Pitchr
 def augment(self):
     """Raises the note by a half step"""
     self._mingus_note = _mingus_notes.augment(str(self._mingus_note))
     self._pitch.accidentals += '#'
     return True
예제 #30
0
def augmented_unison(note):
    return notes.augment(note)
예제 #31
0
    key = dict_musickey[h]

    return (key)


#
#
#
#
#
if __name__ == "__main__":
    image = "Average-Color.png"

    avgcolor_img = cv2.imread(image)

    cica = more_average(avgcolor_img)
    print(cica)

    octave = pick_octave(cica)
    print("Octave: " + str(octave))

    major = pick_major(avgcolor_img)
    print("Major/Minor?: " + major)

    #pixel_key = pick_key(avgcolor_img) #Note: Overflow error. do key later

    note_list = []
    note_list.append(notes.augment("C"))
    note_list.append(notes.int_to_note(138 % 12))
    print(note_list)
예제 #32
0
 def ascending(self):
     notes = NaturalMinor(self.tonic).ascending()[:-1]
     notes[5] = augment(notes[5])
     notes[6] = augment(notes[6])
     return notes * self.octaves + [notes[0]]
예제 #33
0
'''
Created on Jan 5, 2017

@author: stephenkoh
'''

import mingus.core.notes as notes

note = str(input("Please enter a note: "))
if (notes.is_valid_note(note)):
    for i in range(4):
        note = notes.augment(note)
note_int = notes.note_to_int(note)
note = notes.int_to_note(note_int)
print(note)