Пример #1
0
    def draw(self, ctx, x, y, width, height, drag = 0):
      canvas.TablatureDrawer.draw(self, ctx, x, y, width, height, drag)
      if not drag:
        ctx.setFont(self.canvas.small_font)
        ctx.setPen (self.canvas.string_type_2_pen[5])
        for i in range(len(self.strings)):
          label = model.note_label(self.strings[i].base_note, 0, self.partition.tonality)
          ctx.drawText(self.canvas.start_x - 3 * self.canvas.char_h_size, self.string_id_2_y(i), label)

        ctx.setFont(self.canvas.default_font)
        ctx.setPen (self.canvas.default_pen)
Пример #2
0
 def draw(self, ctx, x, y, width, height, drag = 0):
   canvas.TablatureDrawer.draw(self, ctx, x, y, width, height, drag)
   if not drag:
     ctx.set_source_rgb(0.4, 0.4, 0.4)
     ctx.set_font_size(self.canvas.default_font_size * 0.8)
     for i in range(len(self.strings)):
       label = model.note_label(self.strings[i].base_note, 0, self.partition.tonality)
       x_bearing, y_bearing, width, height, x_advance, y_advance = ctx.text_extents(label)
       ctx.move_to(self.canvas.start_x - width - self.canvas.char_h_size // 2, self.string_id_2_y(i) + height // 3)
       ctx.show_text(label)
       
     ctx.set_source_rgb(0.0, 0.0, 0.0)
     ctx.set_font_size(self.canvas.default_font_size)
Пример #3
0
 def __init__(self, gui, master, obj, attr, undo_stack):
   gtk.HBox.__init__(self)
   super(GtkNoteValueField, self).__init__(gui, master, obj, attr, undo_stack)
   
   self.octavo = gtk.combo_box_new_text()
   for i in range(0, 10):
     self.octavo.append_text(_(u"octavo %s") % i)
   self.pack_start(self.octavo, 1, 1)
   
   if hasattr(obj, "partition"): tonality = obj.partition.tonality
   else:                         tonality = "C"
   
   self.note = gtk.combo_box_new_text()
   for i in range(0, 12):
     self.note.append_text(model.note_label(i, False, tonality))
   self.pack_end(self.note, 1, 1)
   
   self.update()
   self.octavo.connect("changed", self.validate)
   self.note  .connect("changed", self.validate)
Пример #4
0
  DurationField  = GtkDurationField
  
else: # Qt
  import qt
  if editobj2.GUI == "Qt":
    import editobj2.field_qt as field_qt, editobj2.editor_qt as editor_qt
  else:
    import editobj2.field_qtopia as field_qt, editobj2.editor_qtopia as editor_qt
  
  editor_qt.SMALL_ICON_SIZE = 48
  
  choices = {}
  for octavo in range(8):
    for note in range(12):
      x = note + 12 * octavo
      choices[model.note_label(x)] = x
      
  NoteValueField = editobj2.field.EnumField(choices, long_list = 1, translate = 0)
  
  DurationField = NoteValueField
  
        
introsp.set_field_for_attr("details"      , None)
introsp.set_field_for_attr("icon_filename", None)

descr = introsp.description(globdef.Config)
descr.set_label  (_("Preferences"))
descr.set_details(_("__config_preamble__"))
descr.set_field_for_attr("MIDI_USE_TEMP_FILE", None)
descr.set_field_for_attr("PREVIOUS_FILES", None)
descr.set_field_for_attr("ASK_FILENAME_ON_EXPORT", field.BoolField)
Пример #5
0
def texttab(song, cut_tab_at = 80):
  "texttab(song) -> string -- Generates an ascii tablature from a song"
  min_duration = sys.maxint
  ternary      = 0
  partitions   = []
  
  for partition in song.partitions:
    if isinstance(partition, model.Partition) and isinstance(partition.view, model.TablatureView):
      partitions.append(partition)
      
      for note in partition.notes:
        dur = note.duration
        if note.is_triplet(): # Triplets are a hack...
          ternary = 1
          if note.duration == 32: dur = 48
          if note.duration == 16: dur = 24
          if note.duration ==  8: dur = 12
        else:
          rest = note.time % min_duration
          if rest > 0: min_duration = rest
          
        if dur < min_duration: min_duration = dur
        
  min_duration = float(min_duration)
  
  slotsize = 2
  for partition in song.partitions:
    if isinstance(partition, model.Partition) and isinstance(partition.view, model.TablatureView):
      for note in partition.notes:
        if note.is_triplet():
          slotsize = 3
          break
        
  duration = min_duration / slotsize
  
  alltabs = StringIO.StringIO()
  
  alltabs.write(u"%s (%s)\n" % (song.title, song.authors))
  if song.copyright: alltabs.write(song.copyright + u"\n")
  if song.comments : alltabs.write(song.comments  + u"\n")

  alltabs.write(u"\n")
  
  for partition in song.partitions:
    if   isinstance(partition, model.Lyrics):
      alltabs.write(partition.header + u"\n")
      text = partition.text.replace(u"\t_", u"").replace(u"_", u"").replace(u"-\t", u"").replace(u"\t", u" ").replace(u"\n", u"").replace(u"\\\\", u"\n").replace(u"  ", u" ")
      alltabs.write(u"\n".join(map(string_module.strip, text.split(u"\n"))))
      alltabs.write(u"\n")
      
    elif isinstance(partition.view, model.TablatureView):
      alltabs.write(partition.header + u"\n")
      strings = partition.view.strings
      tabs    = [array.array("u", u"-" * int(round(partition.end_time() / min_duration * slotsize))) for string in strings]
      
      def string_id(note): return getattr(note, "string_id", len(strings) - 1)
      
      for note in partition.notes:
        sid  = string_id(note)
        time = int(round(note.time / min_duration * slotsize))
        text = strings[sid].value_2_text(note)
        
        if note.linked_from:
          if   note.linked_from.link_fx == u"link":
            link_type = note.linked_from.link_type()
            if   link_type ==  0: continue # Don't show linked note, since ascii tab doesn't matter note duration !
            elif link_type == -1: tabs[sid][time] = u"p"
            elif link_type ==  1: tabs[sid][time] = u"h"
            
          elif note.linked_from.link_fx == u"slide":
            if note.linked_from.value > note.value: tabs[sid][time] = u"\\"
            else:                                   tabs[sid][time] = u"/"
              
        if   note.fx == u"dead"   : tabs[sid][time] = u"x"
        elif note.fx == u"tremolo": tabs[sid][time] = u"~"
        elif note.fx == u"bend"   : tabs[sid][time] = u"b"
        
        if (note.volume > 220) and (tabs[sid][time] == u"-"): tabs[sid][time] = u"'" # Stressed note
        
        if len(text) == 1: tabs[sid][time + 1] = text
        else:
          tabs[sid][time + 1] = text[0]
          tabs[sid][time + 2] = text[1]
          
      tabs = map(lambda tab: tab.tounicode(), tabs) # Turn arrays to strings.
      
      mesure = song.mesures[0]
      i = 0
      while i < len(song.mesures):
        mesures = []
        length = 1
        while i < len(song.mesures):
          length = length + mesure.duration / min_duration * slotsize + 1
          if length > cut_tab_at: break
          mesures.append(mesure)
          
          i = i + 1
          if i >= len(song.mesures): break
          mesure = song.mesures[i]
          

        string_base_note_length  = max([len(model.note_label(string.base_note, False)) for string in strings])
        string_base_note_pattern = u"%%-%ss" % string_base_note_length
        
        for sid in range(len(tabs)):
          tab = tabs[sid]
          
          # [email protected]: this screws up the importer
          # alltabs.write(string_base_note_pattern % model.note_label(strings[sid].base_note, False))
          
          for mes in mesures:
            content = tab[int(round(mes.time / min_duration * slotsize)) : int(round(mes.end_time() / min_duration * slotsize))]
            if not content:
              i = sys.maxint
              break
            alltabs.write(u"|" + content)
          alltabs.write(u"|\n")
          
        alltabs.write(u"\n")
        
  return alltabs.getvalue()