Ejemplo n.º 1
0
 def save(self, collection=None, name=None, force=False):
   """Save the annotation to the corpus"""
   if not collection:
     choice = cgui.menu(self.stdscr, 'Collection', annotationcorpus.collections() + ['Add new collection'])
     if choice == -1: return
     elif choice == len(annotationcorpus.collections()):
       collection = cgui.prompt(self.stdscr, 'Collection?')
     else: collection = annotationcorpus.collections()[choice]
   
   if not name:
     name = self.name
   metadata = {'beatdiv':self.meter.beatdiv, 'beatspb':self.meter.beatspb, 'offset':self.offset, 'bpm':self.bpm, 'name':self.name}
   if annotationcorpus.exists(collection, name) and not force:
     if cgui.menu(self.stdscr, 'Item exists, overwrite?', ['No', 'Yes']) != 1: return
   annotationcorpus.save(collection, name, metadata, sorted(self.annotations, key=lambda x: x[0]), self.notelist, self.midifile)
Ejemplo n.º 2
0
  def load(self, collection=None, name=None):
    if not collection:
      collection = annotationcorpus.collections()[\
          cgui.menu(self.stdscr, 'Choose collection', annotationcorpus.collections())]
    results = annotationcorpus.load(collection, name)
    if results:
      self.annotations = []
      self.midifile = annotationcorpus.load_midifile(collection, name)
      for result in results:
        self.annotations += result.annotation

      metadata = results[0].metadata
      self.notelist = results[0].notes
      self.bpm = metadata['bpm']
      self.offset = metadata['offset']
      self.name = metadata['name']
      self.meter = meter.Meter(metadata['beatspb'], metadata['beatdiv'])
      self.refreshAnnotation = True
      self.refreshMidi = True
      return True
    return False