Пример #1
0
def Create(chord_idx, melody, bars_n, notePerBar_n = 16, ct_w = 1.5):
    """
    chordは一つだけ
    ct_w は大きい方がインサイド

    """
    #create melody
    chordObj = hm.Dataset()
    pitchObj = pw.PitchWeight()

    melody_hist = chordObj.translateMelody(melody)
    chord_tone = chordObj.tones[chord_idx]

    pitch_weight_a = np.zeros(12)
    pitch_weight_a[chord_tone] = ct_w #コードトーンの重さ

    for note, n in enumerate(melody_hist) :
        pitch_weight_a[note] += n

    pitchObj.updatePW(pitch_weight_a, std_f = 'simpleStd')

    improvise_melody  = mel.Create(bars_n, notePerBar_n = notePerBar_n, std_f = 'simpleStd', pwObj = pitchObj)

    #create rythm
    improvise_rythm = rythm.Create(bars_n, notePerBar_n = notePerBar_n )

    return mergeMelodyAndRythm.Merge(improvise_rythm, improvise_melody, bars_n, 1, notePerBar_n, lastNote = chord_tone[0])
Пример #2
0
o.write_short(0xb2, 10, 74)
o.write_short(0xb3, 10, 90)

#load lead sheet
leadSheet = ls.SampleComposition()
rehA_length = leadSheet.vamp_onePhrase_bars * leadSheet.vamp_loop * leadSheet.notePerBar_n
rehB_length = leadSheet.vamp2_onePhrase_bars * leadSheet.vamp2_loop * leadSheet.notePerBar_n
rehC_length = leadSheet.vamp3_onePhrase_bars * leadSheet.vamp3_loop * leadSheet.notePerBar_n
start_rehC = rehA_length + rehB_length
end_reh = rehA_length + rehB_length + rehC_length + 1

# parse section
melody = leadSheet.leadLine[0:rehA_length]
chords = leadSheet.chordProgress[0:rehA_length]
counterMelody = leadSheet.counterMelody[0:rehA_length]
chordObj = hm.Dataset()
ba = leadSheet.perc4[0:rehA_length]
bDr = leadSheet.perc1[0:rehA_length]
sDr = leadSheet.perc2[0:rehA_length]
cHH = leadSheet.perc3[0:rehA_length]
articuration = leadSheet.articuration[0:rehA_length]

#sleepTime = np.random.normal(0.08,0.04)
sleepTime = 0.18

flg = True
leadFlg = 3
leadFlg2 = -1
chordsFlg = -1
counterMelodyFlg = -1
drFlg = -1
Пример #3
0
    def __init__(self):
        self.notePerBar_n = 16
        self.noteParChord_n = 16

        #create leadLine
        self.a_onePhrase_bars = 4
        self.a_loop = 1
        self.a_lastNote = 0
        self.b_onePhrase_bars = 4
        self.b_loop = 1
        self.b_lastNote = 0
        self.vamp_onePhrase_bars = 4
        self.vamp_loop = 4
        self.vamp_lastNote = 0

        self.a = melody.Create(self.a_onePhrase_bars, self.a_loop,
                               self.notePerBar_n, self.a_lastNote)
        self.b = melody.Create(self.b_onePhrase_bars, self.b_loop,
                               self.notePerBar_n, self.b_lastNote)
        self.vamp = melody.Create(self.vamp_onePhrase_bars, self.vamp_loop,
                                  self.notePerBar_n, self.vamp_lastNote)

        self.leadLine = np.r_[self.a, self.b, self.vamp]

        pastNote = 60  #適切な値は?
        for i, note in enumerate(self.leadLine):
            if note > -1:
                note = note + 60
                pastNote = func.smoothing(note, pastNote)
                self.leadLine[i] = pastNote

        #create chordProgeression
        chordObj = hm.Dataset()
        self.chordProgress = hm.Create(self.leadLine, self.noteParChord_n)
        self.bk = perc.Create(self.leadLine, temperature=0.005)
        self.bk = perc.tranBinary(self.bk, 4)

        #create Bucking
        self.ba = np.full(len(self.leadLine), -1)
        self.v1 = np.full(len(self.leadLine), -1)
        self.v2 = np.full(len(self.leadLine), -1)

        note_ba = 60  #適切な値は
        note_v1 = 60  #適切な値は
        note_v2 = 60  #適切な値は
        for i, chord in enumerate(self.chordProgress):
            if self.bk[i] > 0:
                note_ba = func.smoothing(chordObj.tones[chord][0] + 36,
                                         note_ba, 28, 55)
                note_v1 = func.smoothing(chordObj.tones[chord][1] + 60,
                                         note_v1, 50, 70)
                note_v2 = func.smoothing(chordObj.tones[chord][2] + 60,
                                         note_v2, 50, 70)

                self.ba[i] = note_ba
                self.v1[i] = note_v1
                self.v2[i] = note_v2

        #create rythmSection *INST_NO +1 -1はOFFSET
        self.hiHat = perc.Create(self.leadLine, temperature=0.01)
        self.hiHat = perc.tranBinary(self.hiHat, 18) * 43 - 1
        self.snare = perc.Create(self.leadLine, temperature=0.016)
        self.snare = perc.tranBinary(self.snare, 8) * 40 - 1
        self.baDrum = perc.Create(self.leadLine, temperature=0.007)
        self.baDrum = perc.tranBinary(self.baDrum, 8) * 37 - 1

        #create counter melody FUNCTIONとして切り出す?
        self.counterMelody = np.zeros(0)
        for i in range(int(len(self.chordProgress) / self.noteParChord_n)):
            chord_index = self.chordProgress[i * self.noteParChord_n]
            tempCounterMelody = counterMelody.Create(
                chord_index,
                self.leadLine[int(i * 16):int(i * 16 + 16)],
                int(1 * self.noteParChord_n / self.notePerBar_n),
                oct=60)
            self.counterMelody = np.r_[self.counterMelody, tempCounterMelody]

        #floatになっちゃう対策
        self.counterMelody = self.counterMelody.astype(np.int64)

        #create articuration
        self.articuration = ac.Create(self.leadLine,
                                      notePerBar_n=self.notePerBar_n,
                                      r=0.96)
Пример #4
0
    def __init__(self):
        self.notePerBar_n = 16
        self.noteParChord_n = 16

        #create leadLine
        self.a_onePhrase_bars = 4
        self.a_loop = 1
        self.a_lastNote = 0

        #waveToMidi
        wav_dir = r'C:\\work\\ai_music\\freesound\\newSong_100.wav'
        self.wav_dir = wav_dir
        #bpm, idx, peaks_f, , pitch_list
        self.bpmObj = wav.calBpm(wav_dir)
        ts = wav.calcTimeSeries(self.bpmObj[0],
                                self.bpmObj[1],
                                fs=44100,
                                max_s=60)
        self.melodyObj = wav.waveToMidi(ts, self.bpmObj[2][0], self.bpmObj[3],
                                        self.bpmObj[4])

        print("ts is :", ts)
        self.a = self.melodyObj[0]
        self.a_wav = self.melodyObj[1]
        self.a_dur = self.melodyObj[2]
        self.leadLine = self.a[0:self.notePerBar_n * self.a_onePhrase_bars *
                               self.a_loop]
        self.leadLine_wav = self.a_wav[0:self.notePerBar_n *
                                       self.a_onePhrase_bars * self.a_loop]
        self.leadLine_dur = self.a_dur  #[0:self.notePerBar_n  * self.a_onePhrase_bars * self.a_loop]
        self.bpm = self.bpmObj[0]

        #create chordProgeression
        chordObj = hm.Dataset()
        self.chordProgress = hm.Create(self.leadLine, self.noteParChord_n)
        self.bk = perc.Create(self.leadLine, temperature=0.005)
        self.bk = perc.tranBinary(self.bk, 4)

        #create Bucking
        self.ba = np.full(len(self.leadLine), -1)
        self.v1 = np.full(len(self.leadLine), -1)
        self.v2 = np.full(len(self.leadLine), -1)

        note_ba = 60  #適切な値は
        note_v1 = 60  #適切な値は
        note_v2 = 60  #適切な値は
        for i, chord in enumerate(self.chordProgress):
            if self.bk[i] > 0:
                note_ba = func.smoothing(chordObj.tones[chord][0] + 36,
                                         note_ba, 28, 55)
                note_v1 = func.smoothing(chordObj.tones[chord][1] + 60,
                                         note_v1, 50, 70)
                note_v2 = func.smoothing(chordObj.tones[chord][2] + 60,
                                         note_v2, 50, 70)

                self.ba[i] = note_ba
                self.v1[i] = note_v1
                self.v2[i] = note_v2

        #create rythmSection *INST_NO +1 -1はOFFSET
        self.hiHat = perc.Create(self.leadLine, temperature=0.01)
        self.hiHat = perc.tranBinary(self.hiHat, 18) * 43 - 1
        self.snare = perc.Create(self.leadLine, temperature=0.016)
        self.snare = perc.tranBinary(self.snare, 8) * 40 - 1
        self.baDrum = perc.Create(self.leadLine, temperature=0.007)
        self.baDrum = perc.tranBinary(self.baDrum, 8) * 37 - 1

        #create counter melody FUNCTIONとして切り出す?
        self.counterMelody = np.zeros(0)
        for i in range(int(len(self.chordProgress) / self.noteParChord_n)):
            chord_index = self.chordProgress[i * self.noteParChord_n]
            tempCounterMelody = counterMelody.Create(
                chord_index,
                self.leadLine[int(i * 16):int(i * 16 + 16)],
                int(1 * self.noteParChord_n / self.notePerBar_n),
                oct=60)
            self.counterMelody = np.r_[self.counterMelody, tempCounterMelody]

        #floatになっちゃう対策
        self.counterMelody = self.counterMelody.astype(np.int64)

        #create articuration
        self.articuration = ac.Create(self.leadLine,
                                      notePerBar_n=self.notePerBar_n,
                                      r=0.96)