def counter(self, keyProg=None, chordProg=None, _range=[69, 101]):
        #print("counter",len(chordProg), chordProg )
        melody = []
        for chord in chordProg:
            grp_name, patterns = random.choice(
                list(self._rhythmPatters.items()))
            grp_name2, patterns2 = random.choice(
                list(self._rhythmPatters.items()))

            a = patterns[np.random.randint(len(patterns))]
            a1 = patterns2[np.random.randint(len(patterns2))]

            tempMelody = np.r_[np.array(a), np.array(a1)]

            tempMelody = np.array(tempMelody[0::2])

            tempMelody_on = np.where(tempMelody > -1)[0]

            for idx in tempMelody_on:
                tempMelody[idx] = self._chordIdx.getTonesFromIdx(
                    chord[0])[np.random.randint(0, 4, 1)[0]]

            melody.extend(tempMelody)

        melody = func.processing(melody, _range)
        melody = np.array(melody)

        return melody
Beispiel #2
0
    def _approach(self, tempMelody, last_key, last_chord, last_chord_tone_degree = 0, range = [69,101] ):
        on_index = np.where(tempMelody > -1)

        if self._notePerBar_n == 16:
            if len(tempMelody) < self._notePerBar_n :
                print("ALERT IN MELODY _cherryB 1 ")
            else :
                last_melody = self._threeNotesApproach(last_key, last_chord, last_chord_tone_degree)

                for idx, note in enumerate(last_melody):
                    tempMelody[on_index[idx-4]] = note

        else:
            print("ALERT IN MELODY 2, Not Prepared")

        melody = func.processing(tempMelody, range)
        melody = np.array(tempMelody)
        return melody
Beispiel #3
0
    def _cherryB(self, tempMelody, last_chord_beat, last_key, last_chord, last_chord_tone_degree = 0, range = [69,101], lastFractal = False):
        rythm_dict = [\
                        [0,-1,-1,1, -1,-1,2,-1], \
                        [0,-1,1,-1, -1,-1,2,-1], \
                        [0,-1,-1,-1, 1,-1,2,-1], \
                        [0,-1,1,-1, 2,-1,-1,-1], \
                        [0,-1,1,-1, 2,-1,-1,-1], \
                        [0,-1,-1,-1, 1,2,-1,-1]\
                        ]

        if self._notePerBar_n == 16:
            if len(tempMelody) < self._notePerBar_n :
                print("ALERT IN MELODY _cherryB 1 ")
            else :
                rythm = rythm_dict[np.random.randint(len(rythm_dict))]
                if lastFractal :
                    #本当は全体の調性とかちゃんと決めるべき
                    last_melody = self._threeNotesApproach([0,0], 0, 0)
                    #last_melody = self._threeNotesApproach(last_key, last_chord, last_chord_tone_degree)
                    tempMelody[last_chord_beat] = last_melody[3]

                    approach_melody = np.full(8, -1)
                    for idx, val in enumerate(rythm):
                        if val > -1 :
                            approach_melody[idx] = last_melody[val]

                    tempMelody[last_chord_beat-len(approach_melody) : last_chord_beat] =  approach_melody
                else :
                    last_melody = self._threeNotesApproach(last_key, last_chord, last_chord_tone_degree)
                    tempMelody[last_chord_beat] = last_melody[3]

                    approach_melody = np.full(8, -1)
                    for idx, val in enumerate(rythm):
                        if val > -1 :
                            approach_melody[idx] = last_melody[val]
                    tempMelody[last_chord_beat-len(approach_melody) : last_chord_beat] =  approach_melody
        else:
            print("ALERT IN MELODY 2, Not Prepared")

        melody = func.processing(tempMelody, range)

        melody = np.array(tempMelody)
        return melody
Beispiel #4
0
    def counter(self, keyProg=None, chordProg=None, _range = [69,101]):

        melody = []
        for chord in chordProg:
            grp_name, patterns = random.choice(list(self._rhythmPatters.items()))
            grp_name, patterns2 = random.choice(list(self._rhythmPatters.items()))

            a = patterns[np.random.randint(len(patterns))]
            a1 = patterns2[np.random.randint(len(patterns2))]
            a.extend(a1)

            a = np.array(a[0::2] )
            a_on = np.where(a > -1)[0]

            for idx in a_on:
                a[idx] = self._chordIdx.getTonesFromIdx(chord[0])[np.random.randint(0, 4, 1)[0]]

            melody.extend(a)

        melody = func.processing(melody, _range)
        melody = np.array(melody)

        return keyProg, chordProg, melody
Beispiel #5
0
    def approach(self, keyProg=None, chordProg=None, _range = [69,101], otherNoteDegree = 4, lastFlg = False):

        melody = np.full(len(keyProg)*self._notePerBar_n , -1)
        targetNote = None

        #if len(keyProg) >= 4 and len(keyProg) % 4 == 0:
        if len(keyProg) > 1:
            trial_n = len(keyProg)-1
            for num in range(trial_n ):

                grp_name, patterns = random.choice(list(self._rhythmPatters.items()))

                key = keyProg[num]
                chord_idx = chordProg[num][-1] #取り急ぎ
                if key[1] == 0:
                    scale = self._majorScale+key[0]
                    scale = func.clipping(scale[0]) -scale[0] + scale
                    scale = [scale[0], scale[1] , scale[2], scale[3], scale[4], scale[5]-12, scale[6]]
                    penta = [scale[0], scale[1] , scale[2], scale[4], scale[5]]

                elif key[1] == 1:
                    scale = self._minorScale +key[0]
                    scale = func.clipping(scale[0]) -scale[0] + scale
                    scale = [scale[0], scale[1] , scale[2], scale[3], scale[4], scale[5]-12, scale[6]]
                    penta =  [scale[0], scale[2] , scale[3], scale[4], scale[6]]


                tempMelody = np.array(patterns[np.random.randint(len(patterns))])

                #全て置換
                onIdxs = np.where(tempMelody > -1)[0]
                for idx in onIdxs:
                    tempMelody[idx] = scale[otherNoteDegree]

                if targetNote is None:
                    tempMelody[onIdxs[0]] = scale[otherNoteDegree]
                else:
                    tempMelody[onIdxs[0]] = targetNote

                appNotes = self._threeNotesApproach(keyProg[num+1], chordProg[num+1][0], degree = np.random.randint(3))

                targetNote = appNotes[-1]
                tempMelody[onIdxs[-3]] = appNotes[-4]
                tempMelody[onIdxs[-2]] = appNotes[-3]
                tempMelody[onIdxs[-1]] = appNotes[-2]



                melody[num*self._notePerBar_n : (num+1)*self._notePerBar_n] = tempMelody

            #本当はもっとよく変えたい
            print("Melody 668 : ラストノート対応")
            melody[onIdxs[0]-self._notePerBar_n]  = targetNote

            if lastFlg and targetNote != scale[0] :
                melody[onIdxs[1]-self._notePerBar_n]  = scale[0]

        melody = func.processing(melody, _range)
        melody = np.array(melody)

        return  keyProg, chordProg, melody
Beispiel #6
0
    def _cherryA(self, keyProg, chordProg, range):
        """
        chordPrg's length must be two-bars
        Erorr History
        指定のkeyとコードが異なり、エラーが発生
        """
        melody = np.full(2*self._notePerBar_n ,-1)
        if len(chordProg) != 2 :
            print("ERROR IN Melody 1")
            return None

        melody[0] = self._chordIdx.getTonesFromIdx(chordProg[0][0])[np.random.randint(3)]
        melody[0] = func.clipping(melody[0], range[0], range[1])
        melody[1*self._notePerBar_n] = self._chordIdx.getTonesFromIdx(chordProg[1][0])[np.random.randint(3)]
        melody[1*self._notePerBar_n] = func.clipping(melody[1*self._notePerBar_n], range[0], range[1])

        if melody[0] < melody[1*self._notePerBar_n] :
            #issue1
            chord = chordProg[0][1] if len(chordProg[0]) == 2 else chordProg[0][0]
            root = self._chordIdx.getTonesFromIdx(chord)[np.random.randint(3)] #名前がrootなのははじめrootだけ指定してたから
            key = keyProg[0]
            if key[1] == 0:
                noteIdx = np.where((self._majorScale+key[0])%12 == root)[0]
                tempMelody = [root, \
                                self._majorScale[(noteIdx + 1)%len(self._majorScale)]+key[0], \
                                self._majorScale[(noteIdx + 2)%len(self._majorScale)]+key[0], \
                                self._majorScale[(noteIdx + 3)%len(self._majorScale)]+key[0] \
                                ]
            elif key[1] == 1:
                noteIdx = np.where((self._minorScale+key[0])%12 == root)[0]
                tempMelody = [root, \
                                self._minorScale[(noteIdx + 1)%len(self._minorScale)]+key[0], \
                                self._minorScale[(noteIdx + 2)%len(self._minorScale)]+key[0], \
                                self._minorScale[(noteIdx + 3)%len(self._minorScale)]+key[0] \
                                ]
        else : #同じときは?
            #issue1
            chord = chordProg[0][1] if len(chordProg[0]) == 2 else chordProg[0][0]
            root = self._chordIdx.getTonesFromIdx(chord)[np.random.randint(3)] #名前がrootなのははじめrootだけ指定してたから
            key = keyProg[0]
            if key[1] == 0:
                noteIdx = np.where((self._majorScale+key[0])%12 == root)[0]
                tempMelody = [root, \
                                self._majorScale[(noteIdx - 1)%len(self._majorScale)]+key[0], \
                                self._majorScale[(noteIdx - 2)%len(self._majorScale)]+key[0], \
                                self._majorScale[(noteIdx - 3)%len(self._majorScale)]+key[0] \
                                ]
            elif key[1] == 1:
                noteIdx = np.where((self._minorScale+key[0])%12 == root)[0]
                tempMelody = [root, \
                                self._minorScale[(noteIdx - 1)%len(self._minorScale)]+key[0], \
                                self._minorScale[(noteIdx - 2)%len(self._minorScale)]+key[0], \
                                self._minorScale[(noteIdx - 3)%len(self._minorScale)]+key[0] \
                                ]

        if self._notePerBar_n == 16:
            melody[int(self._notePerBar_n/2)] = tempMelody[0]
            melody[int(self._notePerBar_n/2 + self._notePerBar_n/4/2)] = tempMelody[1]
            melody[int(self._notePerBar_n/2 + self._notePerBar_n/4/2 * 2)] = tempMelody[2]
            melody[int(self._notePerBar_n/2 + self._notePerBar_n/4/2 * 3)] = tempMelody[3]
        else:
            print("ALERT IN MELODY 2, Not Prepared")

        melody = func.processing(melody, range)
        return melody