class TabGlyphList

Last modified: February 16, 2010

Contents

TabGlyphList

In module gamera.toolkits.otr.otr_glyph

Class for storing a list of image objects.

An object of the class TabGlyphList provides the following functionality:

  • Storing all connected components (glyphs) of a tablature in a list
  • Providing information about the position (staff, course) of each glyph
  • Sorting glyphs by their positions (staff, course, chord)
  • Output of all glyphs in a specified format

The constructor of a TabGlyphList object adds several public properties to each image of its image list. Those properties can be used to determine the logical position of each symbol in the tablature.

Author:Christoph Dalitz and Thomas Karsten

__init__

Creates and returns a TabGlyphList object.

Signature:

__init__(imgs)

with

imgs:
List of images (connected components or glyphs) that is referenced by the TabGlyphList object. The images have to be Onebit-images.

A TabGlyphList contains the public properties as described below:

ImageList glyphs Reference to the list of images as given in the constructor

Additionally, new public properties are introduced in the constructor of this object for each item in glyphs:

Int staff Number of staff to which the glyph belongs (from top to bottom, starting with 1)
Int course Number of the course on which the glyph is located (from top to bottom, starting with 1 in its staff). Glyphs above the first course get the course number 0 (e.g. flags).
Int x_number Position of the glyph in its staff. x_number starts with 1 and is the same for all glyphs of a vertically aligned chord. The value of x_number is incremented when detecting a new glyph that does not belong to the current chord.
Int middle_x x-position of the center of the glyph.
Int middle_y y-position of the center of the glyph.

The properties offset_x and offset_y in Gamera images refer to the upper left corner. Thus the area middle point is (offset_x + ncols / 2, offset_y + nrows / 2). Although it was possible to use the center of gravity (also known as first moment) instead, its computation was more time consuming. A TabGlyphList object uses the middle point of the area of a glyph to determine its position.

The initial value of staff, course and x_number is set to -1. These values are determined and set properly in the public method set_glyph_properties.

set_glyph_properties

Sets important properties of each glyph to determine its position.

Signature:

set_glyph_properties(tab)

with

tab:
Initialized TabPage object where its method remove_staves has to be called before.

This method gets the tablature position of each glyph in self.glyphs and sets its properties staff, x_number and course. These properties describe the position of each glyph in the tablature (see the image below and the constructor).

images/pagelayout.png

After the method has finished, the glyphs of the TabGlyphList are sorted by using these 3 properties (in the order mentioned above).

Note

Glyphs without sensible staff or course obtain the value -1 for staff or course.

classify_bars

Classifies bars heuristically.

Signature:

classify_bars(tab)

with

tab:
Initialized TabPage object where its method remove_staves has to be called before.

classify_bars finds, groups (in case of broken bar lines) and classifies bar lines heuristically. It is however preferable when bar lines are randomly broken. This function uses the logical position of a glyph (i.e. staff, x_number and course). Therefor, this method should be called after set_glyph_properties.

Note

The detected bar lines will be marked as being classified heuristically. Do not use this method when you want to classify bar lines statistically with the Gamera functions classify_list_automatic or group_list_automatic! These functions will reclassify the glyphs with classification_state = HEURISTIC.

In case some bars have been classified, the return value of this method is 1, otherwise 0.

to_abctab

Gives an output of the sorted list self.glyphs as an abc-formatted string.

Signature:

to_abctab(tabtype)

with

tabtype:
Determines the type of the tablature. Currently supported values are french and italian.
title:
Value for T: header field.

The returned string can be given as input to the external program abctab2ps.

Note

The properties of the glyphs have to be set by calling set_glyph_properties before.

to_abcmusic

Gives an output of the sorted list self.glyphs as an abc music-formatted string.

Signature:

to_abcmusic(tuning="gdAFCG,", key="auto", factor=0)

with

tuning:
The tuning of each course, from top to bottom. Each note is specified as abc code (sharp = prefix '^', flat = prefix '_', octave up = postfix single quote, octave down = postfix comma)
key:
Key signature, e.g. the value Eb stands for E flat Major or Cm for C Minor. When set to auto the key is guessed automatically.
factor:
Logarithmic length factor for slowing down. For example, when set to 2 the sixteenth notes are printed as quarter notes. A negative integer leads to a speedup.

The returned string can be given as input to the external program abctab2ps.

Note

The properties of the glyphs have to be set by calling set_glyph_properties before.