Ejemplo n.º 1
0
def main():
   parser = argparse.ArgumentParser()
   parser.add_argument("input", #nargs="1" , 
                       help="Score to be played, without extension.",
                       #default=config.defaultGenScore
                      )
   parser.add_argument("modelFilename", #nargs="1" , 
                       help="Model filename",
                       #default=config.defaultModelFilename
                      )
   parser.add_argument("outputDir", nargs="?" , 
                       help="Music output directory",
                       default = config.defaultOutputDir
                      )
   args = parser.parse_args()


   genScore = sampleLoader.loadGenScore(args.input)
   genFeat = featureManager.extractGenFeat(genScore)
   #wrap genFeat by {} because trainFeats is {score1, score2}
   featureManager.saveJson([genFeat], config.getGenInFeatFilename(args))
   #perfFeats = model.genPerfFeats(config.defaultGenFeatFilename, args.modelFilename)
   m = model.getModelObj()
   perfFeats = m.gen(args)
   #wrap perfFeat by {} because trainFeats is {score1, score2}
   featureManager.saveJson([perfFeats], config.getGenOutFeatFilename(args))

   musicGenerator.genMusic(genScore, args)
Ejemplo n.º 2
0
   def gen(self, args):
      genFeats = featureManager.loadJson(config.getGenInFeatFilename(args))
      genFeat = genFeats[0]
      scoreName = genFeat['name']
      scoreFeats = genFeat['scoreFeats']
      #wrap genFeats in [] to match data structure in train
      lines = self.formatLineDirect([genFeat]) 
      #logging.printDebug(lines)
      allLines = map(lambda l: "0 " + l, lines)
      #logging.printDebug(allLines)

      #TODO: collect filenames

      SVMGenInputFilename = self.getGenInputFilename(args)

      with open(SVMGenInputFilename, 'w') as f:
         f.writelines(map(lambda x:x+"\n", allLines))

      for featName in config.perfFeatsList:
         cmd = [self.genBinPath]
         cmd.append(SVMGenInputFilename)
         singleModelFilename= self.getSingleModelFilename(args, featName)
         cmd.append(singleModelFilename)
         perfFeatFilename= self.getGenOutputFilename(args, featName)
         cmd.append(perfFeatFilename)

         #logging.printDebug(" ".join(cmd))
         subprocess.call(" ".join(cmd), shell=True)

         #TODO: read all perfFeatFilename, transform to dict and return 


      perfFeats = {}
      for featName in config.perfFeatsList:
         #TODO: put all filename definition in one place
         #perfFeatFilename= self.getGenOutputFilename(args, featName)
         with open(perfFeatFilename, 'r') as f:
             lines = f.readlines()
         #dequantize
         q = quantizer.getQuantizerObj(self.getQuantizeFilename(args, featName))
         realVals= q.dequantize(lines)
         #feat = map(float, lines)
         perfFeats[featName]=realVals

      #logging.printDebug(perfFeats)
      return featureManager.formatFeatFile(scoreName, {}, perfFeats)
Ejemplo n.º 3
0
    def gen(self, args):
        genFeats = featureManager.loadJson(config.getGenInFeatFilename(args))
        genFeat = genFeats[0]
        scoreName = genFeat['name']
        scoreFeats = genFeat['scoreFeats']
        #wrap genFeats in [] to match data structure in train
        lines = self.formatLineDirect([genFeat])
        #logging.printDebug(lines)
        allLines = map(lambda l: "0 " + l, lines)
        #logging.printDebug(allLines)

        #TODO: collect filenames

        SVMGenInputFilename = self.getGenInputFilename(args)

        with open(SVMGenInputFilename, 'w') as f:
            f.writelines(map(lambda x: x + "\n", allLines))

        for featName in config.perfFeatsList:
            cmd = [self.genBinPath]
            cmd.append(SVMGenInputFilename)
            singleModelFilename = self.getSingleModelFilename(args, featName)
            cmd.append(singleModelFilename)
            perfFeatFilename = self.getGenOutputFilename(args, featName)
            cmd.append(perfFeatFilename)

            #logging.printDebug(" ".join(cmd))
            subprocess.call(" ".join(cmd), shell=True)

            #TODO: read all perfFeatFilename, transform to dict and return

        perfFeats = {}
        for featName in config.perfFeatsList:
            #TODO: put all filename definition in one place
            #perfFeatFilename= self.getGenOutputFilename(args, featName)
            with open(perfFeatFilename, 'r') as f:
                lines = f.readlines()
            #dequantize
            q = quantizer.getQuantizerObj(
                self.getQuantizeFilename(args, featName))
            realVals = q.dequantize(lines)
            #feat = map(float, lines)
            perfFeats[featName] = realVals

        #logging.printDebug(perfFeats)
        return featureManager.formatFeatFile(scoreName, {}, perfFeats)