コード例 #1
0
 def restore(self, input):
     saver = tf.train.Saver()
     saver.restore(self.nnw.sess, self.ckpt_dir)
     input = input.reshape(1, len(input))
     output = self.nnw.sess.run(self.nnw.output,
                                feed_dict={self.nnw.X: input})
     return func.dice(func.softmax(np.array(output[0, ]), t=0.1))
コード例 #2
0
def Create(bars_n, notePerBar_n = 16):
    rwObj = rw.RythmWeight()
    rwObj.setWeight()
    #print rwObj.noteLength
    #print rwObj.noteWeight
    #print rwObj.noteWeightMaster

    noteDuration = func.dice(rwObj.noteWeightMaster)
    rythmLine = np.array(rwObj.noteLength[noteDuration])

    while len(rythmLine) < notePerBar_n  * (bars_n + 1):
        loopFlg = func.dice(rwObj.noteWeight[noteDuration])
        if loopFlg > 0 :
            rythmLine = np.r_[rythmLine,rwObj.noteLength[noteDuration]]
        else:
            noteDuration = func.dice(rwObj.noteWeightMaster)
    return rythmLine[:int(notePerBar_n  * bars_n)]
コード例 #3
0
    def crateStepSequence(self, partIdx = 0, notePerBar_n = 16, onePhrase_bars = 4):
        cnt = 0
        part = func.dice(self.master)
        self.sequence  = np.r_[self.sequence, part]

        while self.loopFlg:
            loopFlg = func.dice(self.noteWeight[part])
            if loopFlg > 0 :
                self.sequence  = np.r_[self.sequence, part]
            else:
                part = func.dice(self.master)
                self.sequence  = np.r_[self.sequence, part]

            if part == partIdx:
                cnt += 1
                if cnt > 3 :
                    self.loopFlg = False
コード例 #4
0
def Create(bars_n,
           notePerBar_n=16,
           mergin_n=100,
           std_f='softmax',
           pwObj=pw.PitchWeight()):
    """
    pwObj = pw.PitchWeight()はカスタマイズする必要がある時だけ引数にいれる。
    """
    melody = []

    #set first situation
    #prevNote = func.dice(pwObj.pitchWeight)
    prevNote = 0

    for i in range(int(notePerBar_n * bars_n + mergin_n)):
        pwObj.updateDW((notePerBar_n * bars_n) * 1.0 / (i + 1))
        pwObj.updateRelPW(prevNote, std_f=std_f)
        prevNote = func.dice(pwObj.relPitchWeight)
        melody.append(prevNote)
    return np.array(melody)
コード例 #5
0
ファイル: play_temp.py プロジェクト: ku70t6h1k6r1/auto_music
    while flg:
        start = time.time()

        #Lead
        if lead[i] != -1:
            o.note_off(note_past, 60, 0)
            fixedNote = smoothing(lead[i] + 60, note_past)
            o.note_on(fixedNote, int(95 * articuration[i]), 0)

            #o.note_off(note_past + 12, 60, 3)
            #o.note_on(fixedNote + 12, int(51*articuration[i]) ,3)

            note_past = fixedNote
        #Dr
        if bd[i] != -1:
            o.note_on(func.dice([1 - bd[i], bd[i]]) * 36, 80, 9)

        if sn[i] != -1:
            o.note_on(func.dice([1 - sn[i], sn[i]]) * 39, 80, 9)
        """MSGMだとなんかエラーになる。
        if hh[i] != -1 :
            o.note_on(func.throwSomeCoins(hh[i],12) * 42, int(70*articuration[i]) , 9)
        """

        #Ba
        if bass[i] != -1:
            baOn = func.throwSomeCoins(bass[i], 4)

            if baOn > 0:
                o.note_off(note_past_bs, 60, 1)
                #o.note_on(chordObj.tones[int(cds[i] * 1.0 / 8)][cds[i]  % 8][0] + 36 , int(85*articuration[i]), 1)
コード例 #6
0
ファイル: direction.py プロジェクト: ku70t6h1k6r1/auto_music
    def sendMsg(self, o, i, cnt):  #cnt <= self.sequence_l

        if self.flg:
            #Lead
            if self.lead[i] != -1:
                fixedNote = smoothing(self.lead[i] + 60, self.note_past)

                #part1
                o.note_off(self.note_past, 60, self.ldch)
                o.note_on(fixedNote, int(95 * self.articuration[i]), self.ldch)
                #part1
                o.note_off(self.note_past + 12, 60, self.ld2ch)
                o.note_on(fixedNote + 12, int(51 * self.articuration[i]),
                          self.ld2ch)

                self.note_past = fixedNote
            #Dr
            if self.bd[i] != -1:
                o.note_on(
                    func.dice([1 - self.bd[i], self.bd[i]]) * 36, 80,
                    self.drch)

            if self.sn[i] != -1:
                o.note_on(
                    func.dice([1 - self.sn[i], self.sn[i]]) * 39, 80,
                    self.drch)

            if self.hh[i] != -1:
                o.note_on(
                    func.throwSomeCoins(self.hh[i], 20) * 42,
                    int(70 * self.articuration[i]), self.drch)

            #Ba
            if self.bass[i] != -1:
                baOn = func.throwSomeCoins(self.bass[i], 4)

                if baOn > 0:
                    o.note_off(note_past_bs, 60, self.bach)
                    o.note_on(
                        self.chordObj.tones[int(
                            self.cds[i] * 1.0 / 8)][self.cds[i] % 8][0] + 36,
                        int(85 * self.articuration[i]), self.bach)
                    note_past_bs = self.chordObj.tones[int(
                        self.cds[i] * 1.0 / 8)][self.cds[i] % 8][0] + 36

                if baOn > 0:
                    o.note_off(note_past_v1, 60, self.bkch)
                    o.note_on(
                        self.chordObj.tones[int(
                            self.cds[i] * 1.0 / 8)][self.cds[i] % 8][1] + 48,
                        int(30 * self.articuration[i]), self.bkch)
                    note_past_v1 = self.chordObj.tones[int(
                        self.cds[i] * 1.0 / 8)][self.cds[i] % 8][1] + 48

                    o.note_off(note_past_v2, 60, self.bkch)
                    o.note_on(
                        self.chordObj.tones[int(
                            self.cds[i] * 1.0 / 8)][self.cds[i] % 8][2] + 48,
                        int(30 * self.articuration[i]), self.bkch)
                    note_past_v2 = self.chordObj.tones[int(
                        self.cds[i] * 1.0 / 8)][self.cds[i] % 8][2] + 48

            if i % 64 == 63:
                if self.sequence[cnt] == 0:
                    self.leadFlg += 1
                    self.lead = self.seqObj.update(self.melody, self.leadFlg)
                elif self.sequence[cnt] == 2:
                    self.chordsFlg += 1
                    self.baFlg += 1
                    self.cds = self.seqObj.update(self.chords, self.chordsFlg)
                    self.bass = self.seqObj.update(self.ba, self.baFlg)
                elif self.sequence[cnt] == 4:
                    self.drFlg += 1
                    self.hh = self.seqObj.update(self.cHH, self.drFlg)
                elif self.sequence[cnt] == 5:
                    self.drFlg2 += 1
                    self.sn = self.seqObj.update(self.sDr, self.drFlg2)
                elif self.sequence[cnt] == 6:
                    self.drFlg3 += 1
                    self.bd = self.seqObj.update(self.bDr, self.drFlg3)

            if cnt == len(sequence):
                flg = Fals
コード例 #7
0
    def create_stepSequencer(self, startPartIndex, stopPartIdx):
        self.loopFlg = 1
        cnt = 0
        part = startPartIndex
        self.sequence = np.zeros(0)
        self.sequence = np.r_[self.sequence, part]

        while self.loopFlg:
            loopFlg = func.dice(self.loopWeight[part])
            if loopFlg > 0:
                self.sequence = np.r_[self.sequence, part]
            else:
                part = func.dice(self.node_prob_control)
                self.sequence = np.r_[self.sequence, part]

            if part == stopPartIdx:
                cnt += 1
                if cnt > 3:  #4だと一つ多く感じた。
                    self.loopFlg = False
        print(self.sequence)

        #On OffのSequencer
        self.rythm_seq_OnOff = np.full(len(self.sequence) * 16 * 4, -1)
        self.harmony_seq_OnOff = np.full(len(self.sequence) * 16 * 4, -1)
        self.etc1_seq_OnOff = np.full(len(self.sequence) * 16 * 4, -1)
        self.rythm_seq_OnOff[0] = 0
        self.harmony_seq_OnOff[0] = 0
        self.etc1_seq_OnOff[0] = 0

        for beat, statement in enumerate(self.sequence):
            self.etc1_seq = np.r_[self.etc1_seq,
                                  self.etc1_seq_base.patterns[0]]

            if statement == 1:
                self.rythm_seq_base.update_Statement()
                self.rythm_seq = np.r_[self.rythm_seq, self.rythm_seq_base.
                                       patterns[self.rythm_seq_base.statement]]
                self.harmony_seq = np.r_[self.harmony_seq,
                                         self.harmony_seq_base.patterns[
                                             self.harmony_seq_base.statement]]
                if self.rythm_seq_base.statement == 1:
                    self.rythm_seq_OnOff[beat * 16 * 4] = 1
                    self.rythm_off = False
                elif self.rythm_seq_base.statement == 0:
                    self.rythm_seq_OnOff[beat * 16 * 4] = 0
                    self.rythm_off = True

                if self.rythm_off and self.harmony_off:
                    self.etc1_seq_OnOff[beat * 16 * 4] = 1
                #他のが消えた時の保険としてだけ使いたいときは下のを調整
                #else:
                #    self.etc1_seq_OnOff[beat*16*4]  = 0 # etc keep alive mode

            elif statement == 2:
                self.harmony_seq_base.update_Statement()
                self.harmony_seq = np.r_[self.harmony_seq,
                                         self.harmony_seq_base.patterns[
                                             self.harmony_seq_base.statement]]
                self.rythm_seq = np.r_[self.rythm_seq, self.rythm_seq_base.
                                       patterns[self.rythm_seq_base.statement]]
                if self.harmony_seq_base.statement == 1:
                    self.harmony_seq_OnOff[beat * 16 * 4] = 1
                    self.harmony_off = False
                elif self.harmony_seq_base.statement == 0:
                    self.harmony_seq_OnOff[beat * 16 * 4] = 0
                    self.harmony_off = True

                if self.rythm_off and self.harmony_off:
                    self.etc1_seq_OnOff[beat * 16 * 4] = 1
                #他のが消えた時の保険としてだけ使いたいときは下のを調整
                #else:
                #    self.etc1_seq_OnOff[beat*16*4]  = 0 # etc keep alive mode

            else:
                self.rythm_seq = np.r_[self.rythm_seq, self.rythm_seq_base.
                                       patterns[self.rythm_seq_base.statement]]
                self.harmony_seq = np.r_[self.harmony_seq,
                                         self.harmony_seq_base.patterns[
                                             self.harmony_seq_base.statement]]

        #floatになっちゃう対策
        self.rythm_seq = self.rythm_seq.astype(np.int64)
        self.harmony_seq = self.harmony_seq.astype(np.int64)
        self.etc1_seq = self.etc1_seq.astype(np.int64)
コード例 #8
0
    #Lead
    if note != -1:
        o.note_off(note_past, 60, 0)
        fixedNote = smoothing(note + 60, note_past)
        o.note_on(fixedNote, int(90 * articuration[i]), 0)

        o.note_off(note_past, 60, 3)
        o.note_on(fixedNote, int(50 * articuration[i]), 3)

        note_past = fixedNote
    #Dr
    if i % leadSheet.notePerBar_n == 0:
        #if i % leadSheet.notePerBar_n == 0 or i % leadSheet.notePerBar_n == 4 or i % leadSheet.notePerBar_n == 8 or i % leadSheet.notePerBar_n == 12 :
        o.note_on(36, 50, 9)
    else:
        o.note_on(func.dice([1 - bDr[i], bDr[i]]) * 36, 50, 9)
        o.note_on(func.dice([1 - sDr[i], sDr[i]]) * 39, 50, 9)

    #throwSomeCoins
    o.note_on(
        func.throwSomeCoins(cHH[i], 20) * 42, int(21 * articuration[i]), 9)
    o.note_on(42, 20, 9)

    #Ba
    #baOn = dice([1 - ba_rythm[i] , ba_rythm[i] ]) + dice([1 - ba_rythm[i] , ba_rythm[i] ]) + dice([1 - ba_rythm[i] , ba_rythm[i] ])
    baOn = func.throwSomeCoins(ba[i], 4)
    if baOn > 0:
        #print melodyObj.voice[0][0]
        o.note_off(note_past_bs, 60, 1)
        o.note_on(
            chordObj.tones[int(chords[i] * 1.0 / 8)][chords[i] % 8][0] + 48,