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
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
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
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
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
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
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
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