musical_games.dice_games package

Submodules

musical_games.dice_games.base module

class musical_games.dice_games.base.Bars(bars)[source]

Bases: object

Container for the bars in use in a single tract.

Parameters:bars (list of Bar) – the list of Bar objects
get_at_index(index)[source]

Get the bar at the given index.

This is 0-based and should not be used with the index of a bar from a DiceTable.

Parameters:index (int) – the index to return the Bar at.
Returns:the bar at the given index
Return type:Bar
get_dice_table_indexed(dice_table_index)[source]

Get the bar at the given dice table index.

This is 1-based and should be used when holding the index of a Bar from a Dice Table.

Parameters:dice_table_index (int) – the index to return the Bar at.
Returns:the bar at the given index
Return type:Bar
length()[source]

Get the number of bars in this Bars object.

Returns:the number of bars contained in this Bars object.
Return type:int
class musical_games.dice_games.base.Composition(name, composer_name, parts, composition_manager, page_limit_composition, page_limit_measure_overview)[source]

Bases: object

Holds basic information about a composition and is able to create various views on the composition.

Parameters:
  • name (str) – the name of the composition
  • composer_name (str) – the name of the composer
  • parts (list of CompositionPart) – the list of parts, in the order of appearance
  • composition_manager (CompositionManager) – the composition manager for managing the composition scores
  • page_limit_composition (int or None) – if not None it indicates the page limit for compositions
  • page_limit_measure_overview (int or None) – if not None it indicates the page limit for the measure overviews
are_dice_tables_linked(part_name=None)[source]

Check if the dice tables in the given part are linked or not.

If no part name is given we return a list of booleans for all parts in the composition.

Parameters:part_name (str) – the part for which we want to check if the dice tables are linked
Returns:a boolean if the dice tables are linked or not or, or a list of booleans if no part name is given.
count_unique_compositions()[source]

Get a count of the number of unique compositions possible from this composition.

Returns:the number of unique compositions
Return type:int
get_composition_info()[source]

Get the info necessary to recreate this composition using the composition factory.

Returns:with keys: composer, composition, instruments. If the instruments are all the same for all the parts we return a string for that single instrument
Return type:dict
get_dice_tables()[source]

Get the dice tables used to create compositions.

Returns:as keys composition parts and as values the list of dice tables to be used for that composition part. The order is in the order of appearance of the parts.
Return type:OrderedDict
get_duplicates(part_name, staff=None)[source]

Get the duplicate measures in the given composition part when using the given staffs to find the duplicates.

Parameters:
  • part_name (str) – the composition part for which we want the single measure
  • staff (str) – the staff to use when finding the duplicates. If None we use all the staffs.
Returns:

the duplicate measures the list of dice table ids in which that measure occurs

Return type:

list of list of int

get_midi_options()[source]

Get the default midi options in use in this composition.

The exact same data structure can be handed over to the typeset_composition function if you want to overwrite parts of these defaults

Returns:midi_options – a dictionary with for every part in the
composition a list with per tract the midi options
Return type:dict with list of MidiOption objects
typeset_composition(table_indices, comments=(), midi_options=None)[source]

Typeset a whole composition with all the pieces.

Parameters:
  • table_indices (dict) – per musical part and per staff the list of indices we want to use for that part.
  • comments (list of MusicBookComment) – the list of comments we append at the end of the composition
  • midi_options (dict with list of MidiOption objects) – a dictionary with for every part in the composition a list with per tract additional midi options. The default is used for options set to None.
Returns:

the lilypond book for a single whole composition

Return type:

LilypondBook

typeset_measure_overview()[source]

Typeset the overview of the measures.

Returns:the lilypond book with the measures for all the parts
Return type:LilypondBook
typeset_single_measure(part_name, table_measure_ids)[source]

Typeset a single measure in this composition.

Parameters:
  • part_name (str) – the composition part for which we want the single measure
  • table_measure_ids (dict) – for one or more staffs the id of the measure we want to return
Returns:

the lilypond score for the single measure

Return type:

LilypondBook

class musical_games.dice_games.base.CompositionPart(name, instrument, show_title=True)[source]

Bases: object

Contains information about one part of a composition.

Parameters:
  • name (str) – the part name
  • instrument (Instrument) – the instrumental information
  • show_title (boolean) – if we show the title of this part in the compositions
are_dice_tables_linked()[source]

Check if the dice tables are linked or not.

Returns:if the dice tables are linked or not
Return type:bool
count_unique_compositions()[source]

Get a count of the number of unique compositions possible from this composition part.

Returns:the number of unique compositions
Return type:int
get_composition_scores(indices, part_manager, midi_options=None)[source]

Get the score used in a composition.

Parameters:
  • indices (dict) – per staff the list of the indices to the measures we want to use for this composition.
  • part_manager (CompositionPartManager) – the manager we use when we want to create a composition
  • midi_options (list of MidiOption) – a list with per tract additional midi options. The default is used for options set to None.
Returns:

the visual and midi score for a composition with the given indices

Return type:

list of LilypondScore

get_dice_tables()[source]

Get the dice tables for the staffs (in the instrument) in this composition part

Returns:as keys the staffs as values the dice tables to be used for creating compositions
Return type:dict
get_duplicates(staff=None)[source]

Get the duplicate measures using the given staffs to find the duplicates.

Parameters:staff (str) – the staff to use when finding the duplicates. If None we use all the staffs.
Returns:the duplicate measures the list of dice table ids in which that measure occurs
Return type:list of list of int
get_measure_overview_score()[source]

Typeset the overview of the measures.

Returns:the lilypond score for this composition part
Return type:LilypondScore
get_midi_options()[source]

Get the default midi options in use in this composition.

The exact same data structure can be handed over to the typeset_composition function if you want to overwrite parts of these defaults

Returns:midi_options – a dictionary with for every part in the
composition a list with per tract the midi options
Return type:list of MidiOption objects
typeset_single_measure(table_measure_ids)[source]

Typeset a single measure in this composition.

Parameters:table_measure_ids (dict) – for one or more staffs the id of the measure we want to return
Returns:the lilypond score for the single measure
Return type:LilypondBook
class musical_games.dice_games.base.DiceTable(table)[source]

Bases: object

The dice table to use for playing a dice game.

Parameters:table (ndarray) – numpy array containing the dice table
column_split(column)[source]

Split this dice table into two dice tables depending on the given column.

We split at the given column. So if you have columns 1,2,3,4 and split on 3 you get 1,2 and 3,4.

Parameters:column (int) – the column to split on
Returns:one per split
Return type:list of DiceTable
columns

Get the number of columns in this table.

Returns:the number of columns in the table
Return type:int
count_unique_combinations(duplicates)[source]

Count the number of possible unique combinations over the columns.

Duplicates in the same column will reduce the total number of combinations.

Parameters:duplicates (list of list of int) – the list of double positions. This contains a list holding lists with per similar measures the index of that measure
Returns:the total number of unique combinations possible
Return type:int
get_all_indices()[source]

Get a sorted list of all the indices in this table.

Returns:list of all sorted indices in this table.
Return type:list
get_row(row)[source]

Get the elements on the given row.

Parameters:row (int) – the row we want the elements of
Returns:the list of elements on that row
Return type:list
get_rows()[source]

Get a list of all the rows.

Returns:the list of rows in the table, from top to bottom
Return type:list of list
random_index(column, seed=None)[source]

Get the index of a random row in the dice table given the given column.

Parameters:
  • column (int) – the column number we want to get a random row index from.
  • seed (int) – the optional seed number to use for the random number generator
Returns:

the index to a measure for one specific column and a random row

Return type:

int

random_indices(seed=None)[source]

Get a random list of indices, one for each column.

Parameters:seed (int) – the optional seed number to use for the random number generator
Returns:list of indices, one per column
Return type:list
rows

Get the number of rows in this table.

Returns:the number of rows in the table
Return type:int
class musical_games.dice_games.base.Instrument(name, staffs, tempo_indication, repeats, staff_layout, bar_converter, dice_tables_linked)[source]

Bases: object

Create an instruments information object for the given tracts.

Parameters:
  • name (str) – the name of this instrument
  • staffs (list of Staff) – the list of staffs for this instrument
  • tempo_indication (TempoIndication) – the tempo indication for this instrument
  • repeats (list of tuples of int) – the bars we repeat. For example: [(0, 8), (8, 16)] indicates two repeats, one in which 0 to 8 is repeated and one in which 8 to 16 is repeated.
  • staff_layout (StaffLayout) – the staff layout used when rendering the staffs
  • bar_converter (BarConverter) – the bar converter to use when typesetting the staffs
  • dice_tables_linked (bool) – if the dice tables are linked or not. Normally when they are equal they are linked. If they are linked the staffs in this composition part are linked to each other. Measure 1 in staff one should then correspond (by default) with measure 1 in staff 2. If they are not linked by default the measures in both staffs should be treated independent of each other.
count_unique_compositions()[source]

Get a count of the number of unique compositions possible from the tracts in this instrument.

Returns:the number of unique compositions
Return type:int
get_composition_scores(title, indices, part_manager, midi_options=None, show_title=True)[source]

Get the scores used in a composition.

Parameters:
  • title (str) – the title of this part
  • indices (dict) – per staff the list of the indices to the measures we want to use for this composition.
  • part_manager (CompositionPartManager) – the manager we use when we want to create a composition
  • midi_options (list of MidiOption) – a list with per tract additional midi options. The default is used for options set to None.
  • show_title (boolean) – if we show the title of this part or not
Returns:

the visual and midi score for a composition with the given indices

Return type:

list of LilypondScore

get_dice_tables()[source]

Get the dice tables for the staffs in this instrument

Returns:as keys the staff name as values the dice tables to be used for creating compositions
Return type:dict
get_duplicates(staff=None)[source]

Get the duplicate measures using the given staffs to find the duplicates.

This is useful if you want to mark in the dice table all measures that have duplicates somewhere.

Parameters:staff (str) – the staff to use when finding the duplicates. If None we use all the staffs.
Returns:the duplicate measures the list of dice table ids in which that measure occurs
Return type:list of list of int
get_measure_overview_score(title, show_title=True)[source]

Typeset the overview of the measures.

Parameters:
  • title (str) – the title of this score
  • show_title (boolean) – if we show the title of this part or not
Returns:

the lilypond score for this composition part

Return type:

LilypondScore

get_midi_options()[source]

Get the default midi options in use in this composition.

The exact same data structure can be handed over to the typeset_composition function if you want to overwrite parts of these defaults

Returns:midi_options – a dictionary with for every part in the
composition a list with per tract the midi options
Return type:list of MidiOption objects
typeset_single_measure(table_measure_ids)[source]

Typeset a single measure.

This is supposed to be used to illustrate a single measure referenced in one of the dice tables. The given argument should contain a dictionary with as key the table we want to index and as value the id of the bars.

If there are more staffs in this instrument than those defined in the given argument we will only render measures for which we have an index defined.

The given measure ids should be in Dice Table space, that is, 1-based.

Parameters:table_measure_ids (dice) – per dice table the indices (1-based) from the dice table.
Returns:the lilypond book containing the visual score for one measure.
Return type:LilypondBook
Raises:ValueError – if only one measure index was given while the dice tables are not equal
class musical_games.dice_games.base.Staff(name, dice_table, clef, bars, key_signature, time_signature, instrument_name, midi_options)[source]

Bases: object

Information about a single staff.

For example, you can have two of these, one for the left hand of a piece and one for the right hand (in the case of a piano).

Parameters:
  • name (str) – the name of the staff
  • dice_table (DiceTable) – the dice table for this part
  • clef (str) – lilypond clef notation string. Like ‘treble’ or ‘bass’
  • bars (Bars) – the Bars object containing the bars
  • key_signature (KeySignature) – the key signature
  • time_signature (TimeSignature) – the time signature
  • instrument_name (str) – the name of this instrument
  • midi_options (MidiOptions) – the container for the midi options

musical_games.dice_games.composition_managers module

class musical_games.dice_games.composition_managers.CompositionManager[source]

Bases: object

Composition managers take care of the order of the scores in the final composition.

get_scores(parts, table_indices, midi_options=None)[source]

Get the scores for all the parts.

Parameters:
  • parts (list of CompositionPart) – the list of parts we want to get the scores from
  • table_indices (dict) – per musical part and per dice table the list of indices we want to use for that part.
  • midi_options (dict with list of MidiOption objects) – a dictionary with for every part in the composition a list with per tract additional midi options. The default is used for options set to None.
class musical_games.dice_games.composition_managers.CompositionPartManager[source]

Bases: object

Composition managers take care of generating the right scores for a composition.

You can use this for composition parts that requires a specific staff annotator or generate multiple midi scores.

get_scores(instrument_info, title, bars, midi_options=None, show_title=True)[source]

Get the scores rendered by this composition part manager.

Parameters:
  • instrument_info (Instrument) – the instrumental information
  • title (str) – the title of this part
  • bars (list of list of Bars) – the list of Bars we use per staff
  • midi_options (list) – if set, a list with extra midi options per tract
  • show_title (bool) – if we show the title of this part in visual scores
Returns:

the list of scores, returned by this manager. Can contain one or more visual and/or midi scores.

Return type:

list of LilypondScore

class musical_games.dice_games.composition_managers.KirnbergerPolonaiseCompositionManager[source]

Bases: musical_games.dice_games.composition_managers.CompositionManager

This composition manager uses the KirnbergerPolonaisePartManager for rendering the composition.

get_scores(parts, table_indices, midi_options=None)[source]
class musical_games.dice_games.composition_managers.KirnbergerPolonaisePartManager(staff_annotator)[source]

Bases: musical_games.dice_games.composition_managers.SimpleCompositionPartManager

This composition part manager will render one visual and one midi score with repeats.

get_scores(instrument_info, title, bars, midi_options=None, show_title=True)[source]
class musical_games.dice_games.composition_managers.MidiAlFine[source]

Bases: musical_games.dice_games.composition_managers.CompositionPartManager

This composition manager only renders a midi score

get_scores(instrument_info, title, bars, midi_options=None, show_title=True)[source]
class musical_games.dice_games.composition_managers.SimpleCompositionManager[source]

Bases: musical_games.dice_games.composition_managers.CompositionManager

This composition manager uses the SimpleCompositionPartManager for every composition part.

get_scores(parts, table_indices, midi_options=None)[source]
class musical_games.dice_games.composition_managers.SimpleCompositionPartManager(staff_annotator)[source]

Bases: musical_games.dice_games.composition_managers.CompositionPartManager

This composition part manager will render one visual and one midi score with repeats.

get_scores(instrument_info, title, bars, midi_options=None, show_title=True)[source]
class musical_games.dice_games.composition_managers.SimpleTwoPiece[source]

Bases: musical_games.dice_games.composition_managers.CompositionManager

This composition manager is meant for compositions consisting of two pieces.

At the end of the first piece we will add a ‘Fine’ and at the end of the second piece we will add a ‘DC al Fine’. Next to that, we will add one extra midi score for the first part without repeats.

get_scores(parts, table_indices, midi_options=None)[source]

musical_games.dice_games.factory module

class musical_games.dice_games.factory.ComposerInfo[source]

Bases: object

get_composer_name()[source]

Get the name of the composer contained in this composer info.

Returns:the name of the composer
Return type:str
get_composition(composer_name, composition_name, instruments_name)[source]

Get the composition for the given settings.

Parameters:
  • composer_name (str) – the name of the composer
  • composition_name (str) – the name of the composition
  • instruments_name (str or list of str) – the instrument name or a list of names with one name per compositional part.
Returns:

the generated composition object

Return type:

Composition

get_composition_parts(composition)[source]

Get a list of the composition parts in the given composition.

Parameters:composition (str) – the name of the composition
Returns:the list of composition parts in the asked composition.
Return type:list of str
get_compositions()[source]

Get a list of available compositions for this composer.

Returns:the list of composition names available for this composer
Return type:list of str
get_instruments(composition)[source]

Get a list of the available instruments for the given composition of the given composer.

Parameters:composition (str) – the name of the composition
Returns:the list of instruments available per music part.
Return type:list of list of str
is_applicable(composer_name, composition_name, instruments_name)[source]

Check if this class can generate a composition with the given settings.

Parameters:
  • composer_name (str) – the name of the composer
  • composition_name (str) – the name of the composition
  • instruments_name (str or list of str) – the instrument name or a list of names with one name per compositional part. If one name is given we use it for all the parts in the composition, else one name per part should be given.
Returns:

true if this object can generate a composition for the given settings.

Return type:

boolean

class musical_games.dice_games.factory.DiceGameFactory[source]

Bases: object

composers_info = [<musical_games.dice_games.factory.SimpleComposerInfo object at 0x7fefc3d406a0>, <musical_games.dice_games.factory.SimpleComposerInfo object at 0x7fefc3d5ed30>, <musical_games.dice_games.factory.SimpleComposerInfo object at 0x7fefca856160>, <musical_games.dice_games.factory.SimpleComposerInfo object at 0x7fefc3d4ac88>]
get_composers()[source]

Get a list of available composers

Parameters:of str (list) – the list of available composers sorted alphabetically
get_composition(composer, composition, instruments)[source]

Get a Composition object for a composition of the given composer with the given instruments.

Parameters:
  • composer (str) – the name of the composer
  • composition (str) – the name of the composition
  • instruments (str or list of str) – the instrument name or a list of names with one name per compositional part.
Returns:

the composition object

Return type:

Composition

get_composition_parts(composer, composition)[source]

Get a list of the names of the composition parts in this composition.

The order of the list is the same as that in the ‘get_instruments’ function.

Parameters:
  • composer (str) – the name of the composer
  • composition (str) – the name of the composition
Returns:

the list of composition parts in this composition

Return type:

list of str

get_compositions(composer)[source]

Get a list of available compositions for the given composer.

Parameters:composer (str) – the name of the composer
Returns:the list of composition names available for this composer
Return type:list of str
get_instruments(composer, composition)[source]

Get a list of the available instruments for the given composition of the given composer.

Parameters:
  • composer (str) – the name of the composer
  • composition (str) – the name of the composition
Returns:

the list of instruments available for this composition

Return type:

list of list of str

exception musical_games.dice_games.factory.NotFoundException[source]

Bases: Exception

class musical_games.dice_games.factory.SimpleComposerInfo(directory)[source]

Bases: musical_games.dice_games.factory.ComposerInfo

Reads all the necessary information from a directory.

This assumes that there is a file named ‘manifest.conf’ in the root of the given directory and that the directory is structured in the order:

  • composition name
    • composition parts
      • dice table

      • instruments
        • staff files

      ...

    ...

...

classmethod from_internal(dir_name)[source]
get_composer_name()[source]
get_composition(composer_name, composition_name, instruments_name)[source]
get_composition_parts(composition)[source]
get_compositions()[source]
get_instruments(composition)[source]
is_applicable(composer_name, composition_name, instruments_name)[source]

musical_games.dice_games.shell_utils module

class musical_games.dice_games.shell_utils.CompositionsCompleter[source]

Bases: object

class musical_games.dice_games.shell_utils.InstrumentsCompleter[source]

Bases: object

musical_games.dice_games.utils module

musical_games.dice_games.utils.find_duplicate_bars(bars_list)[source]

Find the bars that are double in the given bar lists

This will find the positions in which all bars on a given position have the same data. Suppose you have two Bars with the following items:

[‘a’, ‘b’, ‘a’, ‘e’] [‘g’, ‘c’, ‘g’, ‘c’]

This function will then return [[0, 2]] indicating that it has found one set of doubles and that set of doubles occurs at positions zero and two.

Positions 1 and 3 are not doubles since they are not equal over all Bars.

Parameters:bars_list (list of Bars) – the list of Bars from which we want to find the overall doubles
Returns:the tuples with information about the doubles. This returns a list holding lists with per similar measures the positions of that measure. The indices returned are in Dice Table space (that is 1-based).
Return type:list of list of int
musical_games.dice_games.utils.load_bars_from_file(filename)[source]

Load bars from a given file.

The file is supposed to be a CSV file with as first column the list of positions this bar appears in and the second column the lilypond code for that measure. The third and further columns can be alternatives for that measure.

Parameters:filename (str) – the name of the file we will load.
Returns:the bars object holding the list of Bar objects
Return type:Bars
musical_games.dice_games.utils.load_dice_table(filename)[source]

Load one of the dicetables from CSV format.

Parameters:filename (str) – the filename of the dice table (in CSV format)
Returns:the dice table with the data loaded from the given file
Return type:DiceTable

Module contents