예제 #1
0
 def setUp(self):
     self.i = Instrument()
     self.p = Piano()
     self.g = Guitar()
     self.notes = NoteContainer(['A', 'B', 'C', 'D', 'E'])
     self.noteslow = NoteContainer(['C-0', 'D-0', 'E-0'])
     self.noteshigh = NoteContainer(['A-12', 'B-12', 'C-12', 'D-12', 'E-12'])
예제 #2
0
 def setUp(self):
     self.commonbar = Bar()
     self.ebar = Bar('E', (4, 4))
     self.fbar = Bar('F', (6, 8))
     self.tbar = Bar('C', (4, 4))
     self.mbar = Bar('C', (4, 4))
     for y in [self.commonbar, self.ebar, self.fbar]:
         map(lambda x: y + x, ['C', 'E', 'G', 'B'])
     map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [
         'C',
         'E',
         'G',
         'B',
         'C',
         'E',
     ])
     map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E'])
     map(lambda x: self.mbar.place_notes(NoteContainer(x), 6),
         ['G', 'B', 'C'])
     self.track1 = Track()
     self.track1 + self.commonbar
     self.track2 = Track()
     self.track2 + self.commonbar
     self.track2 + self.ebar
     self.composition1 = Composition()
     self.composition1.add_track(self.track1)
     self.composition2 = Composition()
     self.composition2.add_track(self.track1)
     self.composition2.add_track(self.track2)
예제 #3
0
 def test_dotted_notes(self):
     self.assertEqual(
         LilyPond.from_NoteContainer(NoteContainer('C'),
                                     value.dots(8),
                                     standalone=False), "c'8.")
     self.assertEqual(
         LilyPond.from_NoteContainer(NoteContainer('C'),
                                     value.dots(4, 2),
                                     standalone=False), "c'4..")
 def setUp(self):
     self.n1 = NoteContainer()
     self.n2 = NoteContainer('A')
     self.n3 = NoteContainer(['A', 'C', 'E'])
     self.n4 = NoteContainer(['A', 'C', 'E', 'F', 'G'])
     self.n5 = NoteContainer([
         'A',
         'C',
         'E',
         'F',
         'G',
         'A',
         ])
 def setUp(self):
     self.n1 = NoteContainer()
     self.n2 = NoteContainer('A')
     self.n3 = NoteContainer(['A', 'C', 'E'])
     self.n4 = NoteContainer(['A', 'C', 'E', 'F', 'G'])
     self.n5 = NoteContainer([
         'A',
         'C',
         'E',
         'F',
         'G',
         'A',
     ])
 def test_sort(self):
     n1 = NoteContainer(['Eb', 'Gb', 'C'])
     n2 = NoteContainer(['Eb', 'Gb', 'Cb'])
     n1.sort()
     n2.sort()
     self.assertEqual(Note('Eb'), n1[0])
     self.assertEqual(Note('Gb'), n2[1])
 def test_add_notes(self):
     self.assertEqual(self.n3, self.n1.add_notes(['A', 'C', 'E']))
     self.n1.empty()
     self.assertEqual(self.n3,
                      self.n1.add_notes([['A', 4], ['C', 5], ['E', 5]]))
     self.n1.empty()
     self.assertEqual(self.n2, self.n1.add_notes(Note('A')))
     self.n1.empty()
     self.assertEqual(self.n2, self.n1.add_notes([Note('A')]))
     self.n1.empty()
     self.assertEqual(self.n2, self.n1.add_notes('A'))
     self.n1.empty()
     self.assertEqual(self.n3,
                      self.n2 + NoteContainer([['C', 5], ['E', 5]]))
     self.n2 = NoteContainer('A')
예제 #8
0
파일: tunings.py 프로젝트: valrus/mingus3
    def find_note_names(
        self,
        notelist,
        string=0,
        maxfret=24,
        ):
        """Returns a list [(fret, notename)] in ascending order.
Notelist should be a list of Notes, note-strings or a NoteContainer.
{{{
>>> t = tunings.StringTuning(\"test\", \"test\", ['A-3', 'A-4'])
>>> t.find_note_names([\"A\", \"C\", \"E\"], 0, 12)
[(0, 'E'), (5, 'A'), (8, 'C'), (12, 'E')]
}}}"""

        n = notelist
        if notelist != [] and type(notelist[0]) == str:
            n = NoteContainer(notelist)
        result = []
        names = [x.name for x in n]
        int_notes = [notes.note_to_int(x) for x in names]

                # Base of the string

        s = int(self.tuning[string]) % 12
        for x in range(0, maxfret + 1):
            if (s + x) % 12 in int_notes:
                result.append((x, names[int_notes.index((s + x) % 12)]))
        return result
 def test_add_note(self):
     self.assertEqual(self.n2, self.n2.add_note('A'))
     self.assertEqual(NoteContainer('A'), self.n1.add_note('A'))
     self.n1 - 'A'
     self.assertEqual(self.n3 + ['F', 'G'], self.n4)
     self.assertEqual(self.n2 + ['C', 'E'], self.n3 - ['F', 'G'])
     self.n2 - ['C', 'E']
예제 #10
0
 def test_is_consonant(self):
     self.assert_(NoteContainer().from_chord('Am').is_consonant())
     self.assert_(NoteContainer().from_chord('C').is_consonant())
     self.assert_(NoteContainer().from_chord('G').is_consonant())
     self.assert_(NoteContainer().from_chord('Dm').is_consonant())
     self.assert_(NoteContainer().from_chord('E').is_consonant())
     self.assert_(not NoteContainer().from_chord('E7').is_consonant())
     self.assert_(not NoteContainer().from_chord('Am7').is_consonant())
     self.assert_(not NoteContainer().from_chord('Gdim').is_consonant())
예제 #11
0
파일: tunings.py 프로젝트: valrus/mingus3
    def frets_to_NoteContainer(self, fingering):
        """Converts a list such as returned by find_fret to a NoteContainer."""

        res = []
        for (string, fret) in enumerate(fingering):
            if fret is not None:
                res.append(self.get_Note(string, fret))
        return NoteContainer(res)
예제 #12
0
 def test_set_item(self):
     b = Bar()
     b + ['A', 'C', 'E']
     c = Bar()
     c + ['A', 'C', 'E']
     self.assertEqual(b, c)
     c[0] = NoteContainer(['A', 'C', 'E'])
     self.assertEqual(b, c)
     c[0] = ['A', 'C', 'E']
     self.assertEqual(b, c)
     c[0] = Note('A')
     c[0] = c[0][2] + NoteContainer(['C', 'E'])
     self.assertEqual(b, c)
     c[0] = Note('A')
     c[0] = c[0][2] + 'C'
     c[0] = c[0][2] + 'E'
     self.assertEqual(b, c)
예제 #13
0
 def test_to_pdf(self):
     self.assert_(
         LilyPond.to_pdf(
             '{ %s }' %
             LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8)),
             'pdftest first test'))
     self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), 'pdftest2'))
     self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), 'pdftest3'))
예제 #14
0
 def test_is_perfect_consonant(self):
     self.assert_(NoteContainer(['A', 'E']).is_perfect_consonant())
     self.assert_(NoteContainer(['A-4', 'A-6']).is_perfect_consonant())
     self.assert_(NoteContainer(['A', 'D']).is_perfect_consonant())
     self.assert_(not NoteContainer(['A', 'D']).is_perfect_consonant(False))
     self.assert_(
         not NoteContainer().from_chord('Am').is_perfect_consonant())
     self.assert_(
         not NoteContainer().from_chord('C').is_perfect_consonant())
     self.assert_(
         not NoteContainer().from_chord('G').is_perfect_consonant())
     self.assert_(
         not NoteContainer().from_chord('Dm').is_perfect_consonant())
     self.assert_(
         not NoteContainer().from_chord('E').is_perfect_consonant())
 def test_remove_note(self):
     n = NoteContainer(['C', 'E', 'G'])
     n.remove_note('C')
     self.assertEqual(NoteContainer(['E', 'G']), n)
     n.remove_note('E')
     self.assertEqual(NoteContainer(['G']), n)
     n.remove_note('G')
     self.assertEqual(NoteContainer([]), n)
예제 #16
0
	def test_remove_note(self):
		n = NoteContainer(["C", "E", "G"])
		n.remove_note("C")
		self.assertEqual(NoteContainer(["E", "G"]), n)
		n.remove_note("E")
		self.assertEqual(NoteContainer(["G"]), n)
		n.remove_note("G")
		self.assertEqual(NoteContainer([]), n)
예제 #17
0
파일: beastie.py 프로젝트: valrus/tone_poem
class NoteCollector(object):
    """Gather notes into a NoteContainer as MIDI msgs come in."""
    def __init__(self):
        self.pending_notes = {}
        self.received_notes = NoteContainer()

    def hear(self, msg):
        if is_note_on(msg):
            self.pending_notes[msg.note] = Note().from_int(msg.note)
        elif is_note_off(msg) and msg.note in self.pending_notes:
            self.received_notes.add_notes(self.pending_notes.pop(msg.note))

    def heard_count(self):
        return len(self.received_notes) if self.received_notes else 0

    def retrieve(self):
        returnVal = NoteContainer(self.received_notes)
        self.received_notes.empty()
        return returnVal
예제 #18
0
 def test_is_imperfect_consonant(self):
     self.assert_(NoteContainer(['A', 'C']).is_imperfect_consonant())
     self.assert_(NoteContainer(['A', 'C#']).is_imperfect_consonant())
     self.assert_(NoteContainer(['A', 'F']).is_imperfect_consonant())
     self.assert_(NoteContainer(['A', 'F#']).is_imperfect_consonant())
     self.assert_(not NoteContainer(['A', 'B']).is_imperfect_consonant())
     self.assert_(not NoteContainer(['A', 'E']).is_imperfect_consonant())
     self.assert_(
         not NoteContainer(['A-4', 'A-5']).is_imperfect_consonant())
 def test_sort(self):
     n1 = NoteContainer(['Eb', 'Gb', 'C'])
     n2 = NoteContainer(['Eb', 'Gb', 'Cb'])
     n1.sort()
     n2.sort()
     self.assertEqual(Note('Eb'), n1[0])
     self.assertEqual(Note('Gb'), n2[1])
예제 #20
0
	def test_add_notes(self):
		self.assertEqual(self.n3, self.n1.add_notes(["A", "C", "E"]))
		self.n1.empty()
		self.assertEqual(self.n3, self.n1.add_notes([["A", 4], ["C", 5], ["E", 5]]))
		self.n1.empty()
		self.assertEqual(self.n2, self.n1.add_notes(Note("A")))
		self.n1.empty()
		self.assertEqual(self.n2, self.n1.add_notes([Note("A")]))
		self.n1.empty()
		self.assertEqual(self.n2, self.n1.add_notes("A"))
		self.n1.empty()
		self.assertEqual(self.n3, self.n2 + NoteContainer([["C", 5], ["E", 5]]))
		self.n2 = NoteContainer("A")
예제 #21
0
	def test_sort(self):
		n1 = NoteContainer(["Eb", "Gb", "C"])
		n2 = NoteContainer(["Eb", "Gb", "Cb"])
		n1.sort()
		n2.sort()

		self.assertEqual(Note("Eb"), n1[0])
		self.assertEqual(Note("Gb"), n2[1])
 def test_add_notes(self):
     self.assertEqual(self.n3, self.n1.add_notes(['A', 'C', 'E']))
     self.n1.empty()
     self.assertEqual(self.n3, self.n1.add_notes([['A', 4], ['C', 5], ['E',
                      5]]))
     self.n1.empty()
     self.assertEqual(self.n2, self.n1.add_notes(Note('A')))
     self.n1.empty()
     self.assertEqual(self.n2, self.n1.add_notes([Note('A')]))
     self.n1.empty()
     self.assertEqual(self.n2, self.n1.add_notes('A'))
     self.n1.empty()
     self.assertEqual(self.n3, self.n2 + NoteContainer([['C', 5], ['E', 5]]))
     self.n2 = NoteContainer('A')
예제 #23
0
    def test_from_NoteContainer(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         standalone=False), "c'")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 4,
                         standalone=False), "c'4")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']),
                         standalone=False), "<c' e'>")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']),
                         4, standalone=False), "<c' e'>4")

        # issue #37

        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16,
                         standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16.0,
                         standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(16), standalone=False), "c'16.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.25,
                         standalone=False), "c'\\longa")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.5,
                         standalone=False), "c'\\breve")
예제 #24
0
 def test_can_play_notes(self):
     self.assert_(self.i.can_play_notes(self.notes))
     self.assert_(self.p.can_play_notes(self.notes))
     self.assert_(self.g.can_play_notes(self.notes))
     self.assertEqual(False, self.p.can_play_notes(self.noteslow))
     self.assertEqual(False, self.g.can_play_notes(self.noteslow))
     self.assertEqual(False, self.p.can_play_notes(self.noteshigh))
     self.assertEqual(False, self.g.can_play_notes(self.noteshigh))
     self.assertEqual(False, self.g.can_play_notes(NoteContainer([
         'A',
         'B',
         'C',
         'D',
         'E',
         'F',
         'G',
         ])))
예제 #25
0
파일: Snooki.py 프로젝트: 31415us/snooki-dj
    def _next_bar(self):
        prev = None
        while True:
            chord_bar = Bar()

            nxt_chord = next(self.sim)

            nxt_voiced = voice(prev, nxt_chord)

            prev = nxt_voiced

            chord_bar + NoteContainer(nxt_voiced)

            chord_bar[0][1] = 1

            self.current = nxt_chord

            yield (chord_bar, bassline(nxt_chord, self.bassproba),
                   drum_beat(self.bassproba))
예제 #26
0
        def add_chord(chord, duration):
            if type(chord) == list:
                for c in chord:
                    add_chord(c, duration * 2)
            else:
                chord = NoteContainer().from_chord(chord)
                if tun:
                    chord = tun.find_chord_fingering(
                        chord, return_best_as_NoteContainer=True)
                if not self.add_notes(chord, duration):

                    # This should be the standard behaviour
                    # of add_notes

                    dur = self.bars[-1].value_left()
                    self.add_notes(chord, dur)

                    # warning should hold note

                    self.add_notes(chord, value.subtract(duration, dur))
예제 #27
0
파일: tunings.py 프로젝트: valrus/mingus3
    def find_chord_fingering(
        self,
        notes,
        max_distance=4,
        maxfret=18,
        return_best_as_NoteContainer=False,
        ):
        """Returns a list of fret lists that are considered possible fingerings. \
This function only looks at and matches on the note _names_ so it does \
more than `find_fingering`. For example: {{{
>>> t = tunings.get_tuning(\"guitar\", \"standard\", 6, 1)
>>> t.find_chord_fingering(NoteContainer().from_chord(\"Am\"))
[[0, 0, 2, 2, 1, 0],
 [0, 3, 2, 2, 1, 0], ......]
}}}"""

        def follow(
            string,
            next,
            name,
            prev=-1,
            ):
            """Follow the fret `next` on `string`. And build result on the way."""

            if string >= len(self.tuning) - 1:
                return [[(next, name)]]
            result = []
            cur = res[string][next]
            if cur != []:
                for y in cur[1]:
                    for sub in follow(string + 1, y[0], y[1]):
                        if prev < 0:
                            result.append([(next, name)] + sub)
                        else:
                            if sub[0][0] == 0 or abs(sub[0][0] - prev)\
                                 < max_distance:
                                result.append([(next, name)] + sub)
            for s in follow(string + 1, maxfret + 1, None, next):
                result.append([(next, name)] + s)
            return [[(next, name)]] if result == [] else result

        def make_lookup_table():
            """Prepare the lookup table. table[string][fret] = (name, dest_frets)"""

            res = [[[] for x in range(maxfret + 2)] for x in
                   range(len(self.tuning) - 1)]
            for x in range(0, len(self.tuning) - 1):
                addedNone = -1
                next = fretdict[x + 1]
                for (fret, name) in fretdict[x]:
                    for (f2, n2) in next:
                        if n2 != name and (f2 == 0 or abs(fret - f2)
                                 < max_distance):
                            if res[x][fret] != []:
                                res[x][fret][1].append((f2, n2))
                            else:
                                res[x][fret] = (name, [(f2, n2)])
                        if addedNone < x:
                            if res[x][maxfret + 1] != []:
                                res[x][maxfret + 1][1].append((f2, n2))
                            else:
                                res[x][maxfret + 1] = (None, [(f2, n2)])
                    addedNone = x
            return res

                # Convert to NoteContainer if necessary

        n = notes
        if notes != [] and type(notes) == list and type(notes[0]) == str:
            n = NoteContainer(notes)

                # Check number of note names.

        notenames = [x.name for x in n]
        if len(notenames) == 0 or len(notenames) > len(self.tuning):
            return []

                # Make string-fret dictionary

        fretdict = []
        for x in range(0, len(self.tuning)):
            fretdict.append(self.find_note_names(notes, x, maxfret))

                # Build table

        res = make_lookup_table()

                # Build result using table

        result = []

                # For each fret on the first string

        for (i, y) in enumerate(res[0]):
            if y != []:
                (yname, next) = (y[0], y[1])

                                # For each destination fret in y

                for (fret, name) in next:

                                        # For each followed result

                    for s in follow(1, fret, name):
                        subresult = [(i, yname)] + s

                                                # Get boundaries

                        (mi, ma, names) = (1000, -1000, [])
                        for (f, n) in subresult:
                            if n is not None:
                                if f != 0 and f <= mi:
                                    mi = f
                                if f != 0 and f >= ma:
                                    ma = f
                                names.append(n)

                                                # Enforce boundaries

                        if abs(ma - mi) < max_distance:

                                                        # Check if all note
                                                        # names are present

                            covered = True
                            for n in notenames:
                                if n not in names:
                                    covered = False

                                                        # Add to result

                            if covered and names != []:
                                result.append([y[0] if y[1]
                                         is not None else y[1] for y in
                                        subresult])

                # Return semi-sorted list

        s = sorted(result, key=lambda x: sum([t if t is not None else 1000
                   for (i, t) in enumerate(x)]))
        if not return_best_as_NoteContainer:
            return s
        else:
            rnotes = self.frets_to_NoteContainer(s[0])
            for (i, x) in enumerate(rnotes):
                if x.string < len(self.tuning) - 1:
                    if res[x.string][x.fret] != []:
                        rnotes[i].name = res[x.string][x.fret][0]
            return rnotes
class test_NoteContainers(unittest.TestCase):

    def setUp(self):
        self.n1 = NoteContainer()
        self.n2 = NoteContainer('A')
        self.n3 = NoteContainer(['A', 'C', 'E'])
        self.n4 = NoteContainer(['A', 'C', 'E', 'F', 'G'])
        self.n5 = NoteContainer([
            'A',
            'C',
            'E',
            'F',
            'G',
            'A',
            ])

    def test_add_note(self):
        self.assertEqual(self.n2, self.n2.add_note('A'))
        self.assertEqual(NoteContainer('A'), self.n1.add_note('A'))
        self.n1 - 'A'
        self.assertEqual(self.n3 + ['F', 'G'], self.n4)
        self.assertEqual(self.n2 + ['C', 'E'], self.n3 - ['F', 'G'])
        self.n2 - ['C', 'E']

    def test_add_notes(self):
        self.assertEqual(self.n3, self.n1.add_notes(['A', 'C', 'E']))
        self.n1.empty()
        self.assertEqual(self.n3, self.n1.add_notes([['A', 4], ['C', 5], ['E',
                         5]]))
        self.n1.empty()
        self.assertEqual(self.n2, self.n1.add_notes(Note('A')))
        self.n1.empty()
        self.assertEqual(self.n2, self.n1.add_notes([Note('A')]))
        self.n1.empty()
        self.assertEqual(self.n2, self.n1.add_notes('A'))
        self.n1.empty()
        self.assertEqual(self.n3, self.n2 + NoteContainer([['C', 5], ['E', 5]]))
        self.n2 = NoteContainer('A')

    def test_remove_note(self):
        n = NoteContainer(['C', 'E', 'G'])
        n.remove_note('C')
        self.assertEqual(NoteContainer(['E', 'G']), n)
        n.remove_note('E')
        self.assertEqual(NoteContainer(['G']), n)
        n.remove_note('G')
        self.assertEqual(NoteContainer([]), n)

    def test_determine(self):
        n = NoteContainer(['C', 'E', 'G'])
        self.assertEqual(['C major triad'], n.determine())
        n.transpose('3')
        self.assertEqual(['E major triad'], n.determine())

    def test_remove_notes(self):
        pass

    def test_sort(self):
        n1 = NoteContainer(['Eb', 'Gb', 'C'])
        n2 = NoteContainer(['Eb', 'Gb', 'Cb'])
        n1.sort()
        n2.sort()
        self.assertEqual(Note('Eb'), n1[0])
        self.assertEqual(Note('Gb'), n2[1])

    def test_getitem(self):
        self.assertEqual(self.n2[0], Note('A'))
        self.assertEqual(self.n3[0], Note('A'))
        self.assertEqual(self.n4[0], Note('A'))
        self.assertEqual(self.n4[1], Note('C', 5))
        self.assertEqual(self.n4[2], Note('E', 5))

    def test_transpose(self):
        n = NoteContainer(['C', 'E', 'G'])
        self.assertEqual(NoteContainer(['E', 'G#', 'B']), n.transpose('3'))
        n = NoteContainer(['C-6', 'E-4', 'G-2'])
        self.assertEqual(NoteContainer(['E-6', 'G#-4', 'B-2']), n.transpose('3'
                         ))

    def test_get_note_names(self):
        self.assertEqual(['A', 'C', 'E'], self.n3.get_note_names())
        self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n4.get_note_names())
        self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n5.get_note_names())

    def test_from_chord_shorthand(self):
        self.assertEqual(self.n3, NoteContainer().from_chord_shorthand('Am'))

    def test_from_progression_shorthand(self):
        self.assertEqual(self.n3,
                         NoteContainer().from_progression_shorthand('VI'))

    def test_from_interval_shorthand(self):
        self.assertEqual(NoteContainer(['C-4', 'G-4']),
                         NoteContainer().from_interval_shorthand('C', '5'))
        self.assertEqual(NoteContainer(['F-3', 'C-4']),
                         NoteContainer().from_interval_shorthand('C', '5',
                         False))

    def test_is_consonant(self):
        self.assert_(NoteContainer().from_chord('Am').is_consonant())
        self.assert_(NoteContainer().from_chord('C').is_consonant())
        self.assert_(NoteContainer().from_chord('G').is_consonant())
        self.assert_(NoteContainer().from_chord('Dm').is_consonant())
        self.assert_(NoteContainer().from_chord('E').is_consonant())
        self.assert_(not NoteContainer().from_chord('E7').is_consonant())
        self.assert_(not NoteContainer().from_chord('Am7').is_consonant())
        self.assert_(not NoteContainer().from_chord('Gdim').is_consonant())

    def test_is_perfect_consonant(self):
        self.assert_(NoteContainer(['A', 'E']).is_perfect_consonant())
        self.assert_(NoteContainer(['A-4', 'A-6']).is_perfect_consonant())
        self.assert_(NoteContainer(['A', 'D']).is_perfect_consonant())
        self.assert_(not NoteContainer(['A', 'D']).is_perfect_consonant(False))
        self.assert_(not NoteContainer().from_chord('Am'
                     ).is_perfect_consonant())
        self.assert_(not NoteContainer().from_chord('C').is_perfect_consonant())
        self.assert_(not NoteContainer().from_chord('G').is_perfect_consonant())
        self.assert_(not NoteContainer().from_chord('Dm'
                     ).is_perfect_consonant())
        self.assert_(not NoteContainer().from_chord('E').is_perfect_consonant())

    def test_is_imperfect_consonant(self):
        self.assert_(NoteContainer(['A', 'C']).is_imperfect_consonant())
        self.assert_(NoteContainer(['A', 'C#']).is_imperfect_consonant())
        self.assert_(NoteContainer(['A', 'F']).is_imperfect_consonant())
        self.assert_(NoteContainer(['A', 'F#']).is_imperfect_consonant())
        self.assert_(not NoteContainer(['A', 'B']).is_imperfect_consonant())
        self.assert_(not NoteContainer(['A', 'E']).is_imperfect_consonant())
        self.assert_(not NoteContainer(['A-4', 'A-5']).is_imperfect_consonant())

    def test_is_dissonant(self):
        self.assert_(NoteContainer().from_chord('E7').is_dissonant())
        self.assert_(NoteContainer().from_chord('Am7').is_dissonant())
        self.assert_(NoteContainer().from_chord('Gdim').is_dissonant())
        self.assert_(not NoteContainer().from_chord('Am').is_dissonant())
        self.assert_(not NoteContainer().from_chord('C').is_dissonant())
        self.assert_(not NoteContainer().from_chord('G').is_dissonant())
        self.assert_(not NoteContainer().from_chord('Dm').is_dissonant())
예제 #29
0
def get_longest_progression(f):
    try:
        (comp, bpm) = get_composition(f)

        progression = []
        progressions = []
        curr_chord = None
        chord_length = 1

        for track in comp:
            for bar in track:
                for cont in bar:
                    notes = cont[2]

                    if len(notes) > 2:
                        if curr_chord is not None:
                            progression.append((curr_chord, chord_length))
                            curr_chord = NoteContainer(notes).determine(shorthand=True)

                            if len(curr_chord) != 0 and curr_chord[0][0].isupper():
                                curr_chord = curr_chord[0]
                            else:
                                curr_chord = None
                                break

                            chord_length = 1
                        else:
                            curr_chord = NoteContainer(notes).determine(shorthand=True)

                            if len(curr_chord) != 0 and curr_chord[0][0].isupper():
                                curr_chord = curr_chord[0]
                            else:
                                curr_chord = None
                                break
                    else:
                        chord_length += 1

            progressions.append(progression)

        max = 0;
        max_progression = None
        for p in progressions:
            if len(p) > max:
                max_progression = p

        prev_progression = max_progression[0][0]
        count = max_progression[0][1]
        progression = []

        for p in max_progression[1:]:
            if prev_progression == p[0]:
                count += p[1]
            else:
                progression.append((prev_progression, count))
                prev_progression = p[0]
                count = p[1]

        return progression
    
    except:
        return []
예제 #30
0
 def test_from_chord_shorthand(self):
     self.assertEqual(self.n3, NoteContainer().from_chord_shorthand('Am'))
 def test_transpose(self):
     n = NoteContainer(['C', 'E', 'G'])
     self.assertEqual(NoteContainer(['E', 'G#', 'B']), n.transpose('3'))
     n = NoteContainer(['C-6', 'E-4', 'G-2'])
     self.assertEqual(NoteContainer(['E-6', 'G#-4', 'B-2']), n.transpose('3'
                      ))
예제 #32
0
	def test_transpose(self):
		n = NoteContainer(["C", "E", "G"])
		self.assertEqual(NoteContainer(["E", "G#", "B"]), n.transpose("3"))
		n = NoteContainer(["C-6", "E-4", "G-2"])
		self.assertEqual(NoteContainer(["E-6", "G#-4", "B-2"]), n.transpose("3"))
 def test_determine(self):
     n = NoteContainer(['C', 'E', 'G'])
     self.assertEqual(['C major triad'], n.determine())
     n.transpose('3')
     self.assertEqual(['E major triad'], n.determine())
예제 #34
0
 def test_get_range(self):
     self.b + NoteContainer(['C', 'E'])
     self.assertEqual((Note('C'), Note('E')), self.b.get_range())
예제 #35
0
    m.tracks = t
    while repeat >= 0:
        for i in range(len(composition.tracks)):
            m.tracks[i].play_Track(composition.tracks[i])
        repeat -= 1
    return m.write_file(file, verbose)


if __name__ == '__main__':
    from mingus.containers.NoteContainer import NoteContainer
    from mingus.containers.Bar import Bar
    from mingus.containers.Track import Track
    from mingus.containers.Instrument import MidiInstrument
    b = Bar()
    b2 = Bar('Ab', (3, 4))
    n = NoteContainer(['A', 'C', 'E'])
    t = Track()
    b + n
    b + []
    b + n
    b + n
    b2 + n
    b2 + n
    b2 + []
    t + b
    t + b
    m = MidiInstrument()
    m.instrument_nr = 13
    t.instrument = m
    t.name = 'Track Name Test'
    write_NoteContainer('test.mid', n)
예제 #36
0
 def test_transpose(self):
     n = NoteContainer(['C', 'E', 'G'])
     self.assertEqual(NoteContainer(['E', 'G#', 'B']), n.transpose('3'))
     n = NoteContainer(['C-6', 'E-4', 'G-2'])
     self.assertEqual(NoteContainer(['E-6', 'G#-4', 'B-2']),
                      n.transpose('3'))
예제 #37
0
 def generate_discord_container(self, number):
     return NoteContainer(Note(number))
예제 #38
0
 def generate_triad_container(self, number, key):
     scale = scales.diatonic(key)
     pos = number % len(scale)
     triad = chords.triad(scale[pos], key)
     return NoteContainer(triad)
예제 #39
0
 def generate_base_container(self, key):
     return NoteContainer(Note(scales.diatonic(key)[0], 2))
예제 #40
0
class test_NoteContainers(unittest.TestCase):
    def setUp(self):
        self.n1 = NoteContainer()
        self.n2 = NoteContainer('A')
        self.n3 = NoteContainer(['A', 'C', 'E'])
        self.n4 = NoteContainer(['A', 'C', 'E', 'F', 'G'])
        self.n5 = NoteContainer([
            'A',
            'C',
            'E',
            'F',
            'G',
            'A',
        ])

    def test_add_note(self):
        self.assertEqual(self.n2, self.n2.add_note('A'))
        self.assertEqual(NoteContainer('A'), self.n1.add_note('A'))
        self.n1 - 'A'
        self.assertEqual(self.n3 + ['F', 'G'], self.n4)
        self.assertEqual(self.n2 + ['C', 'E'], self.n3 - ['F', 'G'])
        self.n2 - ['C', 'E']

    def test_add_notes(self):
        self.assertEqual(self.n3, self.n1.add_notes(['A', 'C', 'E']))
        self.n1.empty()
        self.assertEqual(self.n3,
                         self.n1.add_notes([['A', 4], ['C', 5], ['E', 5]]))
        self.n1.empty()
        self.assertEqual(self.n2, self.n1.add_notes(Note('A')))
        self.n1.empty()
        self.assertEqual(self.n2, self.n1.add_notes([Note('A')]))
        self.n1.empty()
        self.assertEqual(self.n2, self.n1.add_notes('A'))
        self.n1.empty()
        self.assertEqual(self.n3,
                         self.n2 + NoteContainer([['C', 5], ['E', 5]]))
        self.n2 = NoteContainer('A')

    def test_remove_note(self):
        n = NoteContainer(['C', 'E', 'G'])
        n.remove_note('C')
        self.assertEqual(NoteContainer(['E', 'G']), n)
        n.remove_note('E')
        self.assertEqual(NoteContainer(['G']), n)
        n.remove_note('G')
        self.assertEqual(NoteContainer([]), n)

    def test_determine(self):
        n = NoteContainer(['C', 'E', 'G'])
        self.assertEqual(['C major triad'], n.determine())
        n.transpose('3')
        self.assertEqual(['E major triad'], n.determine())

    def test_remove_notes(self):
        pass

    def test_sort(self):
        n1 = NoteContainer(['Eb', 'Gb', 'C'])
        n2 = NoteContainer(['Eb', 'Gb', 'Cb'])
        n1.sort()
        n2.sort()
        self.assertEqual(Note('Eb'), n1[0])
        self.assertEqual(Note('Gb'), n2[1])

    def test_getitem(self):
        self.assertEqual(self.n2[0], Note('A'))
        self.assertEqual(self.n3[0], Note('A'))
        self.assertEqual(self.n4[0], Note('A'))
        self.assertEqual(self.n4[1], Note('C', 5))
        self.assertEqual(self.n4[2], Note('E', 5))

    def test_transpose(self):
        n = NoteContainer(['C', 'E', 'G'])
        self.assertEqual(NoteContainer(['E', 'G#', 'B']), n.transpose('3'))
        n = NoteContainer(['C-6', 'E-4', 'G-2'])
        self.assertEqual(NoteContainer(['E-6', 'G#-4', 'B-2']),
                         n.transpose('3'))

    def test_get_note_names(self):
        self.assertEqual(['A', 'C', 'E'], self.n3.get_note_names())
        self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n4.get_note_names())
        self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n5.get_note_names())

    def test_from_chord_shorthand(self):
        self.assertEqual(self.n3, NoteContainer().from_chord_shorthand('Am'))

    def test_from_progression_shorthand(self):
        self.assertEqual(self.n3,
                         NoteContainer().from_progression_shorthand('VI'))

    def test_from_interval_shorthand(self):
        self.assertEqual(NoteContainer(['C-4', 'G-4']),
                         NoteContainer().from_interval_shorthand('C', '5'))
        self.assertEqual(
            NoteContainer(['F-3', 'C-4']),
            NoteContainer().from_interval_shorthand('C', '5', False))

    def test_is_consonant(self):
        self.assert_(NoteContainer().from_chord('Am').is_consonant())
        self.assert_(NoteContainer().from_chord('C').is_consonant())
        self.assert_(NoteContainer().from_chord('G').is_consonant())
        self.assert_(NoteContainer().from_chord('Dm').is_consonant())
        self.assert_(NoteContainer().from_chord('E').is_consonant())
        self.assert_(not NoteContainer().from_chord('E7').is_consonant())
        self.assert_(not NoteContainer().from_chord('Am7').is_consonant())
        self.assert_(not NoteContainer().from_chord('Gdim').is_consonant())

    def test_is_perfect_consonant(self):
        self.assert_(NoteContainer(['A', 'E']).is_perfect_consonant())
        self.assert_(NoteContainer(['A-4', 'A-6']).is_perfect_consonant())
        self.assert_(NoteContainer(['A', 'D']).is_perfect_consonant())
        self.assert_(not NoteContainer(['A', 'D']).is_perfect_consonant(False))
        self.assert_(
            not NoteContainer().from_chord('Am').is_perfect_consonant())
        self.assert_(
            not NoteContainer().from_chord('C').is_perfect_consonant())
        self.assert_(
            not NoteContainer().from_chord('G').is_perfect_consonant())
        self.assert_(
            not NoteContainer().from_chord('Dm').is_perfect_consonant())
        self.assert_(
            not NoteContainer().from_chord('E').is_perfect_consonant())

    def test_is_imperfect_consonant(self):
        self.assert_(NoteContainer(['A', 'C']).is_imperfect_consonant())
        self.assert_(NoteContainer(['A', 'C#']).is_imperfect_consonant())
        self.assert_(NoteContainer(['A', 'F']).is_imperfect_consonant())
        self.assert_(NoteContainer(['A', 'F#']).is_imperfect_consonant())
        self.assert_(not NoteContainer(['A', 'B']).is_imperfect_consonant())
        self.assert_(not NoteContainer(['A', 'E']).is_imperfect_consonant())
        self.assert_(
            not NoteContainer(['A-4', 'A-5']).is_imperfect_consonant())

    def test_is_dissonant(self):
        self.assert_(NoteContainer().from_chord('E7').is_dissonant())
        self.assert_(NoteContainer().from_chord('Am7').is_dissonant())
        self.assert_(NoteContainer().from_chord('Gdim').is_dissonant())
        self.assert_(not NoteContainer().from_chord('Am').is_dissonant())
        self.assert_(not NoteContainer().from_chord('C').is_dissonant())
        self.assert_(not NoteContainer().from_chord('G').is_dissonant())
        self.assert_(not NoteContainer().from_chord('Dm').is_dissonant())
예제 #41
0
	def test_determine(self):
		n = NoteContainer(["C", "E", "G"])
		self.assertEqual(["C major triad"], n.determine())	
		n.transpose("3")
		self.assertEqual(["E major triad"], n.determine())
예제 #42
0
 def test_from_progression_shorthand(self):
     self.assertEqual(self.n3,
                      NoteContainer().from_progression_shorthand('VI'))
예제 #43
0
class test_NoteContainers(unittest.TestCase):
	
	def setUp(self):
		self.n1 = NoteContainer()
		self.n2 = NoteContainer("A")
		self.n3 = NoteContainer(["A", "C", "E"])
		self.n4 = NoteContainer(["A", "C", "E", "F", "G"])
		self.n5 = NoteContainer(["A", "C", "E", "F", "G", "A"])

	def test_add_note(self):
		self.assertEqual(self.n2 , self.n2.add_note("A"))
		self.assertEqual(NoteContainer("A"), self.n1.add_note("A"))
		self.n1 - "A"
		self.assertEqual(self.n3 + ["F", "G"], self.n4)
		self.assertEqual(self.n2 + ["C", "E"], self.n3 - ["F", "G"])
		self.n2 - ["C", "E"]

	def test_add_notes(self):
		self.assertEqual(self.n3, self.n1.add_notes(["A", "C", "E"]))
		self.n1.empty()
		self.assertEqual(self.n3, self.n1.add_notes([["A", 4], ["C", 5], ["E", 5]]))
		self.n1.empty()
		self.assertEqual(self.n2, self.n1.add_notes(Note("A")))
		self.n1.empty()
		self.assertEqual(self.n2, self.n1.add_notes([Note("A")]))
		self.n1.empty()
		self.assertEqual(self.n2, self.n1.add_notes("A"))
		self.n1.empty()
		self.assertEqual(self.n3, self.n2 + NoteContainer([["C", 5], ["E", 5]]))
		self.n2 = NoteContainer("A")

	def test_remove_note(self):
		n = NoteContainer(["C", "E", "G"])
		n.remove_note("C")
		self.assertEqual(NoteContainer(["E", "G"]), n)
		n.remove_note("E")
		self.assertEqual(NoteContainer(["G"]), n)
		n.remove_note("G")
		self.assertEqual(NoteContainer([]), n)

	def test_determine(self):
		n = NoteContainer(["C", "E", "G"])
		self.assertEqual(["C major triad"], n.determine())	
		n.transpose("3")
		self.assertEqual(["E major triad"], n.determine())

	def test_remove_notes(self):
		pass

	def test_sort(self):
		n1 = NoteContainer(["Eb", "Gb", "C"])
		n2 = NoteContainer(["Eb", "Gb", "Cb"])
		n1.sort()
		n2.sort()

		self.assertEqual(Note("Eb"), n1[0])
		self.assertEqual(Note("Gb"), n2[1])

	def test_getitem(self):
		self.assertEqual(self.n2[0], Note("A"))
		self.assertEqual(self.n3[0], Note("A"))
		self.assertEqual(self.n4[0], Note("A"))
		self.assertEqual(self.n4[1], Note("C", 5))
		self.assertEqual(self.n4[2], Note("E", 5))

	def test_transpose(self):
		n = NoteContainer(["C", "E", "G"])
		self.assertEqual(NoteContainer(["E", "G#", "B"]), n.transpose("3"))
		n = NoteContainer(["C-6", "E-4", "G-2"])
		self.assertEqual(NoteContainer(["E-6", "G#-4", "B-2"]), n.transpose("3"))

	def test_get_note_names(self):
		self.assertEqual(['A', 'C', 'E'], self.n3.get_note_names())
		self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n4.get_note_names())
		self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n5.get_note_names())

        def test_from_chord_shorthand(self):
                self.assertEqual(self.n3, NoteContainer().from_chord_shorthand("Am"))

        def test_from_progression_shorthand(self):
                self.assertEqual(self.n3, NoteContainer().from_progression_shorthand("VI"))

        def test_from_interval_shorthand(self):
                self.assertEqual(NoteContainer(['C-4', 'G-4']), NoteContainer().from_interval_shorthand("C", "5"))
                self.assertEqual(NoteContainer(['F-3', 'C-4']), NoteContainer().from_interval_shorthand("C", "5", False))

        def test_is_consonant(self):
                self.assert_(NoteContainer().from_chord("Am").is_consonant())
                self.assert_(NoteContainer().from_chord("C").is_consonant())
                self.assert_(NoteContainer().from_chord("G").is_consonant())
                self.assert_(NoteContainer().from_chord("Dm").is_consonant())
                self.assert_(NoteContainer().from_chord("E").is_consonant())
                self.assert_(not NoteContainer().from_chord("E7").is_consonant())
                self.assert_(not NoteContainer().from_chord("Am7").is_consonant())
                self.assert_(not NoteContainer().from_chord("Gdim").is_consonant())

        def test_is_perfect_consonant(self):
                self.assert_(NoteContainer(['A', 'E']).is_perfect_consonant())
                self.assert_(NoteContainer(['A-4', 'A-6']).is_perfect_consonant())
                self.assert_(NoteContainer(['A', 'D']).is_perfect_consonant())
                self.assert_(not NoteContainer(['A', 'D']).is_perfect_consonant(False))
                self.assert_(not NoteContainer().from_chord("Am").is_perfect_consonant())
                self.assert_(not NoteContainer().from_chord("C").is_perfect_consonant())
                self.assert_(not NoteContainer().from_chord("G").is_perfect_consonant())
                self.assert_(not NoteContainer().from_chord("Dm").is_perfect_consonant())
                self.assert_(not NoteContainer().from_chord("E").is_perfect_consonant())


        def test_is_imperfect_consonant(self):
                self.assert_(NoteContainer(['A', 'C']).is_imperfect_consonant())
                self.assert_(NoteContainer(['A', 'C#']).is_imperfect_consonant())
                self.assert_(NoteContainer(['A', 'F']).is_imperfect_consonant())
                self.assert_(NoteContainer(['A', 'F#']).is_imperfect_consonant())
                self.assert_(not NoteContainer(['A', 'B']).is_imperfect_consonant())
                self.assert_(not NoteContainer(['A', 'E']).is_imperfect_consonant())
                self.assert_(not NoteContainer(['A-4', 'A-5']).is_imperfect_consonant())

        def test_is_dissonant(self):
                self.assert_(NoteContainer().from_chord("E7").is_dissonant())
                self.assert_(NoteContainer().from_chord("Am7").is_dissonant())
                self.assert_(NoteContainer().from_chord("Gdim").is_dissonant())
                self.assert_(not NoteContainer().from_chord("Am").is_dissonant())
                self.assert_(not NoteContainer().from_chord("C").is_dissonant())
                self.assert_(not NoteContainer().from_chord("G").is_dissonant())
                self.assert_(not NoteContainer().from_chord("Dm").is_dissonant())
예제 #44
0
파일: beastie.py 프로젝트: valrus/tone_poem
 def __init__(self):
     self.pending_notes = {}
     self.received_notes = NoteContainer()
예제 #45
0
	def setUp(self):
		self.n1 = NoteContainer()
		self.n2 = NoteContainer("A")
		self.n3 = NoteContainer(["A", "C", "E"])
		self.n4 = NoteContainer(["A", "C", "E", "F", "G"])
		self.n5 = NoteContainer(["A", "C", "E", "F", "G", "A"])
예제 #46
0
 def test_place_notes_types(self):
     self.assertEqual(True, self.meterless + NoteContainer(['A', 'C']))
     self.assertEqual(True, self.meterless + 'A')
     self.assertEqual(True, self.meterless + Note('A'))
     self.assertEqual(True, self.meterless + ['A', 'B'])
     self.assertEqual(True, self.meterless + [Note('A'), Note('B')])