コード例 #1
0
 def __init__(self,tracks):
     rhythms = [None]*len(tracks)
     melodies = [None]*len(tracks)
     for i,t in enumerate(tracks):
         rhythms[i] = rh.makeTrackRhythm(t)
         melodies[i] = mel.makeTrackMelody(t,0)
     (self.rhythmSamps,self.rhythmLens) = rh.makeRhythmSamples(rhythms)
     self.rhythmTimesteps = [r.timesteps for r in rhythms]
     self.melodyDS = mel.makeMelodyDataSet(melodies)
コード例 #2
0
 def generateBar(self, track, rdmLam=4.0):
     # Format data for prediction
     rhythm = rh.makeTrackRhythm(track)
     (rhythmSamps,_) = rh.makeRhythmSamples([rhythm])
     melody = mel.makeTrackMelody(track,0)
     melodyDS = mel.makeMelodyDataSet([melody])
     # Generate notes
     rhythmOutTS = lrd.generateNextBar(self.rdm, self.hmm, rdmLam, rhythmSamps)
     #self.net.reset()
     #for sample in melodyDS.getSequenceIterator(0):
     #    self.net.activate(sample[0])
     #Whatever
     pitchOutTS = mel.getNextPitches(self.net, melody.pitches[-1], melodyDS,
                                     rhythm.timesteps[-1], rhythmOutTS)
     # Load output into classes
     t = 0
     for t in range(len(rhythmOutTS)):
         rhythm.addTimestep(rhythmOutTS[t])
         newNote = (rhythmOutTS[t] == 1)
         melody.addNote(pitchOutTS[t],newNote)
     trackOut = makeTrackFromRhythmMelody(rhythm, melody, self.octave)
     return trackOut