class TabGlyphList

Last modified: May 13, 2016

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.
Int gridnr
position in grid:
0 for glyph not within grid or flag, n for glyph in n-th chord under grid (starts at 1), -n for grid/flag including n chords.

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 staff, x_number, course, and offset_x (the latter is for symbols that are at the same position, e.g. flags with dots.

Note

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

to_abctab

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

Signature:

to_abctab(tabtype, title=OTR result, numlines=6, default_note_length=1.0/4.0)

with

tabtype:
Determines the type of the tablature. Currently supported values are french and italian.
title:
Value for T: header field.
numlines:
Number of Stafflines per staff
default_note_length:
Default length of notes for paramter L:

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.

split_diapasons

This method splits glyphs with an aspect ratio (ncols/nrows) > ratio_threshold into ncols/nrows parts.

It can be used to split connected diapasons and should be called before the glyphs are classified