gsapi.GSBassmine¶
temporary place for documenting temporary bassmine
gsapi.GSBassmineAnalysis module¶
-
gsapi.GSBassmineAnalysis.
strip_suffix
(filename, suffix=None)[source]¶ Strip off the suffix of the given filename or string. Extracted from madmom
Parameters: - filename – (str) Filename or string to strip.
- suffix – (str, optional) Suffix to be stripped off (e.g. ‘.txt’ including the dot).
Returns: Filename or string without suffix.
Return type: filename
-
gsapi.GSBassmineAnalysis.
match_files
(filename, match_list, suffix=None, match_suffix=None)[source]¶ Match a filename or string against a list of other filenames or strings.
Parameters: - filename – (str) Filename or string to strip.
- match_list – (list) Match to this list of filenames or strings.
- suffix – (str, optional) Suffix of filename to be ignored.
- match_suffix – Match only files from match_list with this suffix.
Returns: (list) List of matched files.
Return type: matches
-
gsapi.GSBassmineAnalysis.
search_files
(path, suffix=None)[source]¶ Returns a list of files in path matching the given suffix or filters the given list to include only those matching the given suffix.
Parameters: - path – (str or list) Path or list of files to be searched / filtered.
- suffix – (str, optional) Return only files matching this suffix.
Returns: (list) List of files.
Return type: file_list
-
gsapi.GSBassmineAnalysis.
write2pickle
(name, data, path='../../models/')[source]¶ Write numpy array in pickle format to the selected location
Parameters: - name – name of the output pickle file
- data – numpy array to be exported to pickle format
- path – (optional) output folder path
-
gsapi.GSBassmineAnalysis.
corpus_analysis
(bass_path, drum_path)[source]¶ TEST : This functions implement the rhythmic analysis used by Bassmine (bassline generator). The input is a corpus of related Bass and Drum MIDI files. Input files must match their names : i.e. bass_[trackname].mid , drums_[trackname].mid
The algorithm computes a Markov model of the temporal context (probabilities of transitions between bass beat patterns) and the interlocking context between bass and kick-drum (probabilities of concurrency between bass and kick-drum patterns)
Markovian models are computed by GSBassmineMarkov module.
[The pitch model is still a work in progress]
Parameters: - bass_path – folder with bass midi files
- drum_path – folder with drums midi files
Returns: instance of GSBassmineMarkov.MarkovModel class. It contains initial, temporal and interlocking MTM kick_patterns: list of kick patterns in collection in Markov dictionary formatted ids
Return type:
gsapi.GSBassmineMarkov module¶
-
gsapi.GSBassmineMarkov.
normalize
(a)[source]¶ Normalize matrix by rows
Parameters: a – matrix (2D) Returns: normalized matrix Return type: a
-
gsapi.GSBassmineMarkov.
indices
(a, func)[source]¶ Return indices in an array matching to a given function
Examples: indices(array, lambda x: x <= 1)
Parameters: - a – array, list
- func – lambda function
Returns: Indices of ‘a’ matching lambda function
-
class
gsapi.GSBassmineMarkov.
MarkovModel
(model_size, order=1)[source]¶ Class to operate with markov models. Internal function used by GSBassmineAnalysis module.
-
model_size
¶ Dictionary size of the model
-
normalized
¶ Boolean to control if the model has been normalized
-
support_temporal
¶ internal matrix to compute markov model
-
support_initial
¶ internal matrix to compute markov model
-
support_interlocking
¶ internal matrix to compute markov model
-
initial_model
¶ matrix to store initial MTM
-
temporal_model
¶ matrix to store temporal MTM
-
interlocking_model
¶ matrix to store interlocking MTM
-
add_temporal
(pattern)[source]¶ Create markov transition matrix given a sequence
First element counts are stored in self.initial_model Rest of elements feed the transition matrix (no time-series)
Parameters: pattern – list or array with idx of the state dictionary
-
add_interlocking
(patt_kick, patt_bass)[source]¶ Create interlocking (concurrency) markov matrix given two sequences
Parameters: - patt_kick – kick drum pattern (anchor)
- patt_bass – bassline pattern
-
update_interlocking
(x, y)[source]¶ internal function to update interlocking matrix
Parameters: - x – row (anchor)
- y – col (bass)
-
update_temporal
(x, y)[source]¶ internal function to update temporal matrix
Parameters: - x – row (past)
- y – col (present)
-
update_initial
(x)[source]¶ internal function to update initial probabilites
Parameters: x – row (probabilities)
-
get_initial
()[source]¶ Get initial probabilites
Returns: list Return type: initial_model
-
get_temporal
()[source]¶ Get temporal model
Returns: 2D matrix Return type: temporal_model
-
get_interlocking
()[source]¶ Get interlocking model
Returns: 2D matrix Return type: interlocking_model
-
-
gsapi.GSBassmineMarkov.
constrainMM
(markov_model, target, _path='output/')[source]¶ Compute non-homogeneuous markov model (NHMM) based on interlocking constraint. Given a target pattern it constraint the original model and ensure arc-consistency
This function is also implemented as a pyext class.
Parameters: - markov_model – MarkovModel instance (output from GSBassmineUtils.corpus_analysis())
- target – Target pattern for interlocking (kick) represented by its pattern ids.
- _path – Path to where the Markov models will be stored
Returns: Interlocking model as dictionary in JSON format
-
gsapi.GSBassmineMarkov.
variationMM
(markov_model, target, _path='output/')[source]¶ Compute non-homogeneuous markov model (NHMM) based on variation constraint. Given a target Variation Mask(VM) it constraint the original model and ensure arc-consistency
Examples
VM should be a list representing a pattern (id formatted) with negative numbers on those frames to variate. Positive values will be preserved.
Parameters: - markov_model – MarkovModel instance (output from GSBassmineUtils.corpus_analysis())
- target – Variation Mask (list with negative numbers indicating variation of that time frame)
- _path – Path to where the Markov models will be stored
Returns: Variation model as a dictionary in JSON format
-
gsapi.GSBassmineMarkov.
markov_tm_2dict
(a)[source]¶ Convert markov transition matrix to dictionary of sets. Compact representation to avoid sparse matrices and better performance in the constrain model
Parameters: a – MarkovModel temporal/interlocking/pitch matrix Returns: dictionary{}
-
gsapi.GSBassmineMarkov.
createMarkovGenerationDictionary
(toJSON=False, _path='output/')[source]¶ Internal function to build a dictionary relating binarized patterns into start times (in beats) :param toJSON: boolean. If true it exports to JSON :param _path: path to store the dictionary as JSON
Returns: Pattern dictionary
-
gsapi.GSBassmineMarkov.
generateBassRhythm
(markov_model, beat_length=8, target=[])[source]¶ Function to generate a rhythmic bassline. If no target given the system assume no constraints and uses the regular Markov model (computed by MarkovModel.rhythm_model()). If target given it is assumed as target constraint for interlocking model. :param markov_model: output from MarkovModel.rhythm_model() :param beat_length: desired length of the generated pattern :param target: Pattern used as constraint in Interlocking Model.
Returns: GSPattern containing bassline onset pattern Return type: bassline
-
gsapi.GSBassmineMarkov.
generateBassRhythmVariation
(markov_model, target_pattern, variation_mask)[source]¶ Function that implements a variation model given an already generated pattern. Based on the variation mask it creates a Markov model that preserve desired beat measures while it models “variation” beats to be stylistically consistent. :param markov_model: output from MarkovModel.rhythm_model() :param target_pattern: GSPattern, for instance output from generateBassRhythm() :param variation_mask: List of the same length of the target_pattern(in beats). Positions with value 1 will be preserved, :param those with -1 will vary.:
Returns: generated GSPattern Return type: bassline