4.1.1.1. rpscripts.lib package

4.1.1.1.1. Submodules

4.1.1.1.2. rpscripts.lib.base module

This module provides RPScripts’ basic classes and methods

exception rpscripts.lib.base.CustomException[source]

Bases: Exception

Generic custom exception.

class rpscripts.lib.base.EventLocation(**kwargs)[source]

Bases: object

Temporal event location.

make_str_index()[source]

Return string index (measure number + offset).

parse_str_index()[source]

Parse string index and store in the class attributes.

class rpscripts.lib.base.GeneralSubparser(subparser: ArgumentParser)[source]

Bases: object

Argparse subparser abstract class.

add_arguments() None[source]

Add argparse.ArgumentParser arguments.

handle(args) None[source]

Parse arguments and run the module functions.

setup() None[source]

Basic setup.

Set program_name and help message.

class rpscripts.lib.base.RPData(path=None)[source]

Bases: object

Main Rhythmic Partitioning Data class.

get_agglomeration_dispersion(partition_str: str) list[source]

Find and return a given partition’s agglomeration and dispersion values as a two-element list.

These values must be present in the values_map class attribute and the partition value must be in string format.

get_events_location(attribute: str) dict[source]

Return a dictionary with the event locations where the measure number is the dictionary key, and the pair “offset, element”, the dictionary value. The element is the value in the attribute list.

If the attribute value is partitions, the element is the partition as string. For instance, 1.3, 2^2 and so on.

get_frequency_counter(attribute: str, proportional=True) dict[source]

Return a frequency counter of the values of a given attribute.

get_probability_counter(attribute: str, exclude_repeats=True, proportional=True) dict[source]

Return a probability counter of adjacent values of a given attribute.

load_from_file() None[source]

Load data from the file set into path attribute and fill the other class attributes with this loaded data.

make_class_graph(attribute: str) Digraph[source]

Return a graphviz.Digraph with the adjacent values of a list of values stored in the given attribute.

save_to_csv(equally_sized=False) None[source]

Save the data into a CSV file.

If equally_sized parameter is true, the events are proportionally divided into smaller events of a unique duration.

save_to_file(filename=None) None[source]

Save the class data into a JSON file.

to_json() dict[source]

Return the data as a dictionary with fractions formated to json.

trim(start_pointer: int, end_pointer: int)[source]

Return a new RPData object with trimmed attributes’ data.

Only values_map is kept as the original RPData object.

rpscripts.lib.base.aux_find_next_measure_number(global_offset: Fraction, offset_map: dict, index=0) tuple[source]

Return the nearest measure number that the global offset value is higher than the given one as parameter.

This function also updates and returns the given index.

rpscripts.lib.base.aux_sum_if_none(a, b)[source]

Return the sum if one or two given values is None.

rpscripts.lib.base.clean_filename(filename: str) str[source]

Clean the given filename.

Remove the special characters and spaces.

rpscripts.lib.base.convert_texture_data_from_json(data: dict) dict[source]

Convert texture data from JSON.

The fractions are converted from string to Fraction objects.

rpscripts.lib.base.convert_texture_data_to_json(data: dict) dict[source]

Convert texture data to JSON.

The fractions are converted from Fraction objects to strings.

rpscripts.lib.base.convert_to_equal_durations(dataframe: DataFrame, offset_map: dict) dict[source]

Convert texture data from a given DataFrame to dictionary format with events of the same duration.

For instance, a dataframe with two events with durations 1/2 and 1/3 are converted in 3 events and 2 events of duration 1/6.

rpscripts.lib.base.dump_json_data(filename: str, data) None[source]

Dump data to json file.

rpscripts.lib.base.file_rename(filename: str, extension: str, suffix=None) str[source]

Rename files to change extension value and add optional suffix.

rpscripts.lib.base.find_nearest_smaller(value, seq: list)[source]

Find the smaller nearest value of a given value from a given sequence.

rpscripts.lib.base.fraction_to_string(value) str[source]

Return a given value as a fraction represented as a string format.

rpscripts.lib.base.get_diff_lcm(seq: list) Fraction[source]

Return the lowest common multiple of the differences between the adjacent values of a given list.

rpscripts.lib.base.get_fractions_denominator_lcm(fractions_lst: list)[source]

Return the lowest common multiple value of a list of fractions denominators.

rpscripts.lib.base.get_number_combinations_pairs(n: int) float[source]

Return the number of pair combinations of a list of n elements.

Binomial coefficient.

rpscripts.lib.base.load_json_file(filename: str) dict[source]

Load JSON file.

rpscripts.lib.base.make_fraction(value) Fraction[source]

Return a Fraction object from a given Fraction or float value.

rpscripts.lib.base.make_general_graph(labels: list, name: str) Digraph[source]

Return a graphviz.Digraph with the adjacent values of a given list of labels.

rpscripts.lib.base.parse_fraction(value) Fraction[source]

Return a Fraction object from a given value.

rpscripts.lib.base.parse_pow(partition) str[source]

Superscript pow values in given partitions.

rpscripts.lib.base.save_dict_into_csv_file(dic: dict, filename: str) None[source]

Save a given dictionary into a CSV file.

4.1.1.1.3. rpscripts.lib.partition module

This module provides classes and functions for rhythmic partitioning analysis. For further information, see Gentil-Nunes 2009.

Gentil-Nunes, Pauxy. 2009. “Análise Particional: uma Mediação entre Composição Musical e a Teoria das Partições.” Ph.D. Dissertation, Universidade Federal do Estado do Rio de Janeiro.

class rpscripts.lib.partition.Partition(parts=None)[source]

Bases: object

Main partition class.

as_string() str[source]

Return the partition as a string such as “1^3.2”.

count_binary_relations()[source]

Count binary relations of partition’s parts.

get_agglomeration_index() int[source]

Return the partition’s agglomeration index.

get_density_number() int[source]

Return the partition’s density number.

get_dispersion_index() int[source]

Return the partition’s dispersion index.

get_parts_size() int[source]

Count the partition’s number of parts.

resize() list[source]

Return the list of current’s resized partitions.

revariate() list[source]

Return the list of current’s revariated partitions.

transfer(default=True) list[source]

Return the list of current’s transfered partitions.

class rpscripts.lib.partition.PartitionLattice(cardinality=10)[source]

Bases: object

Partition Lattice class. It helps in lattice creating and saving.

save_file()[source]

Save lattice map into file.

rpscripts.lib.partition.get_lexset(number: int) list[source]

Return the lexical set of a given number. The lexical set is the list of all partitions from 1 to number.

rpscripts.lib.partition.get_partitions(number: int) list[source]

Return the partitions of a given number as a list of lists.

rpscripts.lib.partition.make_ryp_map(higher_cardinality: int) dict[source]

Make a rhythmic partitioning Young lattice of a given cardinality.

rpscripts.lib.partition.make_subseq(partition, n) list[source]

Return a subset array from a given partition from 0 to n element.

4.1.1.1.4. Module contents