コード例 #1
0
    def _zenzenzense(self, key, oneBar, range, otherNoteDegree, lastNoteDegree):
        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]]

        noteOnIndicies = []
        for idx, note in enumerate(oneBar):
            if note > -1:
                #全て置換
                oneBar[idx] = scale[otherNoteDegree]
                noteOnIndicies.append(idx)

        #最後の音置換
        oneBar[noteOnIndicies[-1]] = scale[lastNoteDegree]

        if len(noteOnIndicies) > 2:
            midIndicies = np.arange(1,len(noteOnIndicies)-1)
            idx = noteOnIndicies[midIndicies[np.random.randint(len(midIndicies))]]
            oneBar[idx] =  penta[np.random.randint(len(penta))]

        return oneBar
コード例 #2
0
    def doubleStop(self,
                   chordProg,
                   kickScore,
                   bassScore,
                   range,
                   subMethodName="synchroniseBass"):
        chordScore = None

        if subMethodName == self.synchroniseKick:
            chordScore = self._subMethods.synchroniseKick(chordProg, kickScore)
        elif subMethodName == self.synchroniseBass:
            chordScore = self._subMethods.synchroniseBass(chordProg, bassScore)
        elif subMethodName == self.wholeNote:
            chordScore = self._subMethods.wholeNote(chordProg)
        elif subMethodName == self.kick:
            chordScore = self._subMethods.kick(chordProg)
        else:
            print("ERROR IN VoiceProgression")
            return None

        score = np.full([len(chordProg) * self._notePerBar_n, 2], -1)
        for i, chord in enumerate(chordScore):
            if chord > -1:
                score[i][0] = func.clipping(
                    self._chordIdx.getTonesFromIdx(chord)[1], range[0],
                    range[1])
                score[i][1] = func.clipping(
                    self._chordIdx.getTonesFromIdx(chord)[3], range[0],
                    range[1])
            elif chord == -2:
                score[i][0] = -2
                score[i][1] = -2
        return score
コード例 #3
0
    def unisonBass(self, chordProg, bassScore, range):
        chordScore = None
        chordScore = self._subMethods.synchroniseBass(chordProg, bassScore)

        score = np.full([len(chordProg) * self._notePerBar_n, 3], -1)
        for i, chord in enumerate(chordScore):
            if chord > -1:
                score[i][0] = func.clipping(bassScore[i], range[0], range[1])
                score[i][1] = func.clipping(
                    self._chordIdx.getTonesFromIdx(chord)[2], range[0],
                    range[1])
                score[i][2] = func.clipping(bassScore[i], range[0],
                                            range[1]) + 12
        return score
コード例 #4
0
    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
コード例 #5
0
ファイル: Effects.py プロジェクト: ku70t6h1k6r1/auto_music
    def _tranBinary(self, probArray, tryN=1):
        output = np.full(len(probArray), -1)

        for i, p in enumerate(probArray):
            output[i] = func.throwSomeCoins(p, tryN) - 1  #On:0 Off:-1にするため

        return output
コード例 #6
0
ファイル: Bass.py プロジェクト: ku70t6h1k6r1/auto_music
    def riff8(self, chordProg, range):
        """
        一旦minorで考える
        """

        grp_name, patterns = random.choice(list(self._rhythmPatters.items()))
        a = np.array(patterns[np.random.randint(len(patterns))])

        for idx, note in enumerate(a):
            if note > -1:
                break
            else:
                a[idx] = -2

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

            bassLine.extend(a)

        for beat, note in enumerate(bassLine):
            if note > -1:
                bassLine[beat] = func.clipping(note, range[0], range[1])

        return bassLine
コード例 #7
0
ファイル: Effects.py プロジェクト: ku70t6h1k6r1/auto_music
    def _pickUpAccent(self, melody, notePerBar_n=16):
        output = np.zeros(0)
        oneBar = np.zeros(len(melody))

        for j in range(int(len(melody) / notePerBar_n)):
            for i in range(notePerBar_n):
                if melody[notePerBar_n * j + i] > -1:
                    oneBar[notePerBar_n * j +
                           i] = oneBar[notePerBar_n * j + i] + 1
        output = np.r_[output, func.softmax(oneBar)]
        return output
コード例 #8
0
ファイル: Effects.py プロジェクト: ku70t6h1k6r1/auto_music
    def _pickUpSectionAccent(self,
                             melody,
                             notePerBar_n=16,
                             barsPerOneSection=4):
        output = np.zeros(0)
        oneBar = np.zeros(notePerBar_n)

        # minimum beat length sixteen-beat and then 16
        for j in range(int(len(melody) / notePerBar_n)):
            for i in range(notePerBar_n):
                if melody[j * notePerBar_n + i] > -1:
                    oneBar[i] = oneBar[i] + 1
            if j % barsPerOneSection == barsPerOneSection - 1:
                for k in range(barsPerOneSection):
                    output = np.r_[output, func.softmax(
                        oneBar)]  #ランダム性はコントロールできる。*3でいけないのか。
                oneBar = np.zeros(notePerBar_n)
        return output
コード例 #9
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
コード例 #10
0
ファイル: Bass.py プロジェクト: ku70t6h1k6r1/auto_music
    def eightBeat(self, chordProg, range, chordTone=0):
        bassLine = np.full(len(chordProg) * self._notePerBar_n, -1)
        for bar, chords in enumerate(chordProg):
            for beat, chord in enumerate(chords):
                #issue1
                #bassLine[int(bar*self._notePerBar_n + beat*self._notePerBar_n/4*2) : int((bar+1)*self._notePerBar_n)] \
                #= np.full( int(self._notePerBar_n/(beat+1) ) , self._chordIdx.getTonesFromIdx(chord)[0])
                bassLine[int(bar * self._notePerBar_n +
                             beat * self._notePerBar_n / 4 *
                             2):int((bar + 1) * self._notePerBar_n)] = [
                                 self._chordIdx.getTonesFromIdx(chord)
                                 [chordTone], -1
                             ] * int(8 / (beat + 1))

        for beat, note in enumerate(bassLine):
            if note > -1:
                bassLine[beat] = func.clipping(note, range[0], range[1])

        return bassLine
コード例 #11
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
コード例 #12
0
ファイル: Effects.py プロジェクト: ku70t6h1k6r1/auto_music
    def _accentRandom(self,
                      score,
                      barsPerOneSection=4,
                      temperature=0.0005,
                      n=2):
        merge = self._pickUpAccent(
            score, self._notePerBar_n) * self._pickUpSectionAccent(
                score, self._notePerBar_n, barsPerOneSection)

        output = np.zeros(0)
        oneBar = np.full(self._notePerBar_n, -1)

        for j in range(int(len(merge) / self._notePerBar_n)):
            for i in range(self._notePerBar_n):
                oneBar[i] = merge[j * self._notePerBar_n + i]
            output = np.r_[output, func.softmax(oneBar,
                                                t=temperature)]  #0.0005がちょうどよい
            oneBar = np.zeros(self._notePerBar_n)

        return self._tranBinary(output, n)  #変数にしなくていいのか
コード例 #13
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
コード例 #14
0
ファイル: Bass.py プロジェクト: ku70t6h1k6r1/auto_music
    def pedal(self, keyProg, range):
        patterns = [[
            0,
            0,
            0,
            -1,
            0,
            0,
            -1,
            0,
            0,
            0,
            0,
            -1,
            0,
            0,
            -1,
            0,
        ]]

        pattern = np.array(patterns[np.random.randint(0, len(patterns), 1)[0]])

        key = keyProg[0]
        if key[1] == 0:
            scale = self._majorScale + key[0]
        elif key[1] == 1:
            scale = self._minorScale + key[0]

        bassLine = np.full(len(pattern), -1)
        onSets = np.where(pattern > -1)[0]

        for idx in onSets:
            bassLine[idx] = func.clipping(scale[4], range[0], range[1])

        bassLine = np.tile(bassLine, len(keyProg))

        return bassLine
コード例 #15
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
コード例 #16
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