Esempio n. 1
0
 def testNotes(self):
     print('testing notes')
     for i in range(0, 12):
         if not Note.isWhite(i):
             continue
         print('chromatic index :' + str(i))
         print('chromatitc name :' + str(Note(i)))
         d = Diatonic(Diatonic.index(Note(i).value)).name
         ch = Note(i).name
         print('diatonic name :' + d)
         assert(d == ch)
Esempio n. 2
0
 def isChord(self):
     if self.index < 2:
         return False
     j = Diatonic.interval(self.parent, self.note)
     j_ = Diatonic.interval(self.sequence[self.index - 2], self.parent)
     if j == -2 and j_ == -3:
         return True
     if j == 2 and j_ == 3:
         return True
     if j == -2 and j_ == -2:
         return True
     if j == 2 and j_ == 2:
         return True
     return False
Esempio n. 3
0
    def validMelody(self, size=11, counter=False, mode=None):
        index = self.index
        note = self.note
        if index > 0:
            '''si nota es parent, rompe regla de nota repetida'''
            '''contrapunto tiene permitido repetir a los mas dos'''
            if note == self.parent:
                if not counter:
                    print('here repeated note')
                    return False
                elif index >= 2 and self.sequence[index - 2] == note:
                    print('AAA AT COUNTER')
                    return False

            if index == 1 and not self.checkEnd(index, note, counter, mode):
                print('invalid ending ' + str(self.sequence))
                return False
            if not self.checkTritone(note):
                print('tritone movement')
                return False
            if index < 2:
                return True
            lastJump = self.sequence[index - 1] - self.sequence[index - 2]
            if lastJump != 0 and not self.checkTritoneIsolated(lastJump):
                print('isolated tritone')
                return False
            if not self.checkJumpEnd():
                return False
            j = Diatonic.index(note) - Diatonic.index(self.parent)
            if j != 0 and not self.checkLegalJump(j):
                print('illegal jump')
                return False
            if index < 3:
                return True
            jump = Diatonic.interval(self.parent, self.note)
            seq = self.sequence
            if not self.checkMovement(jump, seq, index):
                print('invalid movement')
                return False
            if not self.checkSequences(seq, index):
                print('sequences found')
                return False
            if index == size - 1 and not self.checkStart(counter, mode):
                print('invalid start')
                return False

        return True
Esempio n. 4
0
 def testNotes(self):
     if testNotes:
         print('TESTING DIATONIC-CHROMATIC CORRESPONDANCE')
         print('TESTING CHROMATIC TO DIATONIC SCALE')
         for i in range(0, 15):
             note = Note.diatonicScale(0, -i)
             print('note :'+str(Note(note % 12)) + ' octave :' + str(int(note / 12)))
         for i in range(0, 12):
             if not Note.isWhite(i):
                 continue
             print('chromatic index :' + str(i))
             print('chromatitc name :' + str(Note(i)))
             d = Diatonic(Diatonic.index(Note(i).value)).name
             ch = Note(i).name
             print('diatonic name :' + d)
             assert(d == ch)
         for i in range(0, 24):
             print(Note(i % 12))
             print('dIndex : ' + str(Diatonic.index(i)))
         for i in range(0, 24):
             print(Note((-i) % 12))
             print('dIndex : ' + str(Diatonic.index(-i)))
         print('testing intervals')
         for i in range(0, 26):
             if not Note.isWhite(i):
                 continue
             print(Note(i % 12).name + str(i//12))
             print(Diatonic.interval(0, i))
         for i in range(0, 26):
             if not Note.isWhite(-i):
                 continue
             print(Note((-i) % 12).name + str(-i//12))
             print(Diatonic.interval(0, -i))
Esempio n. 5
0
    def checkSequences(self, sequence, index):
        print('check sequence ' + str(self.note))
        i = index
        note = self.note
        parent = self.parent
        s = sequence
        jump = Diatonic.interval(parent, note)
        if i < 3:
            return True
        interval02 = Diatonic.interval(s[i - 2], s[i - 0])
        interval13 = Diatonic.interval(s[i - 3], s[i - 1])
        print(interval02 == 0)
        print(interval13)
        if interval02 == interval13 and (abs(jump) > 1 or interval02 == 0):

            print('ab , a+x b+x')
            return False
        if i > 5:
            interval25 = Diatonic.interval(s[i - 5], s[i - 2])
            interval14 = Diatonic.interval(s[i - 4], s[i - 1])
            if interval25 == interval14 and abs(jump) > 1:
                if interval14 == Diatonic.interval(s[i - 3], note):
                    print('abc , a+x b+x c+x')
                    return False
        return True
Esempio n. 6
0
 def checkMovement(self, jump, seq, index):
     j = Diatonic.interval(seq[index - 2], seq[index - 1])
     if j == 1 and jump > 1:
         parent = str(self.parent)
         note = str(self.note)
         p = str(seq[index - 2])
         print('jump down + continuos ' + note + ' ' + parent + ' ' + p)
         return False
     elif jump == -1 and j < -1:
         print(index)
         print(self.note)
         print(self.jump())
         print('continous + jumpUp')
         return False
     return True
Esempio n. 7
0
 def checkMovement(self, jump, seq, index):
     j = Diatonic.interval(seq[index - 2], seq[index - 1])
     print('check movement {}'.format(self.note))
     if j == 1 and jump > 1:
         parent = self.parent
         note = self.note
         p = seq[index - 2]
         print('{} {} {}: jump down + continuos '.format(note, parent, p))
         return False
     elif jump == -1 and j < -1:
         parent = self.parent
         note = self.note
         p = seq[index - 2]
         print('{} {} {}: continous + jumpUp'.format(note, parent, p))
         return False
     return True
Esempio n. 8
0
    def validMelody(self, counterMode=False, mode=None):
        index = self.index
        note = self.note
        if index > 0:
            '''si nota es parent, rompe regla de nota repetida'''
            '''contrapunto tiene permitido repetir a los mas dos'''
            if note == self.parent:
                if not counterMode:
                    print('here repeated note')
                    return False
                elif index >= 2 and self.sequence[index - 2] == note:
                    print('AAA AT COUNTER')
                    return False
            '''haciendo el arbol al reves, index = 1,
                representa penultima nota'''
            '''debe ser 2ndo grado en el cantusFirmus y sensible para
            contrapunto, sensible = modo - 1, en la escala cromatica y diat'''
            if index == 1:
                print('caca' + str(self))
                if not self.checkEnd(index, note, counterMode, mode):
                    print('invalid ending')
                    return False
            if not self.checkTritone(note):
                print('tritone movement')
                return False
            if index >= 2:
                lastJump = self.sequence[index - 1] - self.sequence[index - 2]
                if lastJump != 0:
                    if self.jump() / lastJump < 0:
                        lastPivot = self.pivot
                        self.pivot = index - 1
                        if lastPivot is not None:
                            if (self.sequence[lastPivot] -
                                    self.parent) % 12 == 6:
                                print(note)
                                print(self.jump())
                                print('surrounding tritone ' +
                                      str(self.parent))
                                self.pivot = index - 1
                                return False

                if index == 2 and self.jump() >= 7:
                    print('.jump down before end')
                    return False
                ''''index in whiteScale'''
                note = int(note + int(note / 5)) / 2
                parent = self.parent
                parent = int((parent + int(parent / 5)) / 2)
                '''salto en terminos de blancas , intervalos diatonicos'''
                j = note - parent
                if j > 1:
                    if j != 2 and j != 3 and j != 4 and j != 5 and j != 7:
                        print('salto ilegal ' + str(j + 1) + 'a')
                        return False
                    j_chrome = self.note - self.parent
                    if self.parent - self.sequence[index - 2] > 2:
                        if not self.isChord():
                            print(
                                'salto en la misma direccion ,debe ser acorde')
                            return False
                    if j == 5:
                        if abs(j_chrome) == 9:
                            print('sexta menor no permitida')
                elif j < -1:
                    if j != -2 and j != -3 and j != -4 and j != -5 and j != -7:
                        return False
                    if self.parent - self.sequence[index - 2] < -2:
                        if not self.isChord():
                            return False
                    if j == -5:
                        j_chrome = self.note - self.parent
                        if j_chrome == 9:
                            print('note , note + 6M')
            if index >= 3:
                note = self.note
                jump = Diatonic.interval(self.parent, note)
                seq = self.sequence
                if not self.checkMovement(jump, seq, index):
                    print(jump)
                    print('note' + str(self.note))
                    print(self.sequence)
                    print(Diatonic.index(note))
                    print('invalid movement')
                    return False
                if not self.checkSequences(seq, index):
                    print('sequences found')
                    return False
                if index == 10 and not self.checkStart(counterMode, mode):
                    print('invalid start')

        return True