hydrogen 1.2.3
Pattern Class Reference

Pattern class is a Note container. More...

#include <Pattern.h>

Inheritance diagram for Pattern:
Object< Pattern > Base

Public Types

typedef notes_t::const_iterator notes_cst_it_t
 note set type;
 
typedef notes_t::iterator notes_it_t
 multimap note const iterator type
 
typedef std::multimap< int, Note * > notes_t
 < multimap note type
 
typedef virtual_patterns_t::const_iterator virtual_patterns_cst_it_t
 
typedef virtual_patterns_t::iterator virtual_patterns_it_t
 note set const iterator type;
 
typedef std::set< Pattern * > virtual_patterns_t
 note set iterator type;
 

Public Member Functions

 Pattern (const QString &name="Pattern", const QString &info="", const QString &category="not_categorized", int length=MAX_NOTES, int denominator=4)
 constructor
 
 Pattern (Pattern *other)
 copy constructor
 
 ~Pattern ()
 destructor
 
void addFlattenedVirtualPatterns (PatternList *pPatternList)
 Add content of __flattened_virtual_patterns into pPatternList.
 
std::set< Pattern * >::iterator begin ()
 allow iteration of all contained virtual patterns.
 
std::set< Pattern * >::iterator end ()
 
Notefind_note (int idx_a, int idx_b, std::shared_ptr< Instrument > instrument, bool strict=true) const
 search for a note at a given index within __notes which correspond to the given arguments
 
Notefind_note (int idx_a, int idx_b, std::shared_ptr< Instrument > instrument, Note::Key key, Note::Octave octave, bool strict=true) const
 search for a note at a given index within __notes which correspond to the given arguments
 
void flattened_virtual_patterns_clear ()
 
void flattened_virtual_patterns_compute ()
 compute virtual_pattern_transitive_closure_set based on virtual_pattern_transitive_closure_set virtual_pattern_transitive_closure_set must have been cleared before which is the case is called from PatternList::compute_flattened_virtual_patterns
 
const QString & get_category () const
 set the length of the pattern
 
int get_denominator () const
 get the note multimap
 
const virtual_patterns_tget_flattened_virtual_patterns () const
 
const QString & get_info () const
 get the category of the pattern
 
int get_length () const
 set the denominator of the pattern
 
const QString & get_name () const
 set the category of the pattern
 
const notes_tget_notes () const
 get the virtual pattern set
 
const virtual_patterns_tget_virtual_patterns () const
 get the flattened virtual pattern set
 
void insert_note (Note *note)
 insert a new note within __notes
 
bool isVirtual () const
 Whether the pattern holds at least one virtual pattern.
 
int longestVirtualPatternLength () const
 
void purge_instrument (std::shared_ptr< Instrument > instr, bool bRequiredLock=true)
 delete the notes referencing the given instrument The function is thread safe (it locks the audio data while deleting notes)
 
bool references (std::shared_ptr< Instrument > instr)
 check if this pattern contains a note referencing the given instrument
 
void remove_note (Note *note)
 removes a given note from __notes, it's not deleted
 
void removeFlattenedVirtualPatterns (PatternList *pPatternList)
 Add content of __flattened_virtual_patterns into pPatternList.
 
bool save_file (const QString &drumkit_name, const QString &author, const License &license, const QString &pattern_path, bool overwrite=false) const
 save a pattern into an xml file
 
void save_to (XMLNode *node, const std::shared_ptr< Instrument > instrumentOnly=nullptr) const
 save the pattern within the given XMLNode
 
void set_category (const QString &category)
 set the info of the pattern
 
void set_denominator (int denominator)
 get the denominator of the pattern
 
void set_info (const QString &info)
 get the info of the pattern
 
void set_length (int length)
 get the length of the pattern
 
void set_name (const QString &name)
 get the name of the pattern
 
void set_to_old ()
 mark all notes as old
 
QString toQString (const QString &sPrefix="", bool bShort=true) const override
 Formatted string version for debugging purposes.
 
void virtual_patterns_add (Pattern *pattern)
 add a pattern to __virtual_patterns
 
void virtual_patterns_clear ()
 
void virtual_patterns_del (Pattern *pattern)
 remove a pattern from virtual_pattern set, flattened virtual patterns have to be rebuilt
 
bool virtual_patterns_empty () const
 clear __virtual_patterns
 
- Public Member Functions inherited from Object< Pattern >
 Object ()
 
 Object (const Object< Pattern > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 

Static Public Member Functions

static Patternload_file (const QString &pattern_path, std::shared_ptr< InstrumentList > instruments)
 load a pattern from a file
 
static Patternload_from (XMLNode *node, std::shared_ptr< InstrumentList > instruments, bool bSilent=false)
 load a pattern from an XMLNode
 
- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 

Static Private Member Functions

static bool loadDoc (const QString &sPatternPath, std::shared_ptr< InstrumentList > pInstrumentList, XMLDoc *pDoc, bool bSilent=false)
 Loads the pattern stored in sPatternPath into pDoc and takes care of all the error handling.
 

Private Attributes

QString __category
 the category of the pattern
 
int __denominator
 the meter denominator of the pattern used in meter (eg 4/4)
 
virtual_patterns_t __flattened_virtual_patterns
 the complete list of virtual patterns
 
QString __info
 a description of the pattern
 
int __length
 Determines the accessible range or notes within the pattern.
 
QString __name
 the name of thepattern
 
notes_t __notes
 a multimap (hash with possible multiple values for one key) of note
 
virtual_patterns_t __virtual_patterns
 a list of patterns directly referenced by this one
 

Additional Inherited Members

- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from Object< Pattern >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 

Detailed Description

Pattern class is a Note container.

Definition at line 45 of file Pattern.h.

Member Typedef Documentation

◆ notes_cst_it_t

typedef notes_t::const_iterator notes_cst_it_t

note set type;

Definition at line 54 of file Pattern.h.

◆ notes_it_t

typedef notes_t::iterator notes_it_t

multimap note const iterator type

Definition at line 52 of file Pattern.h.

◆ notes_t

typedef std::multimap<int, Note*> notes_t

< multimap note type

multimap note iterator type

Definition at line 50 of file Pattern.h.

◆ virtual_patterns_cst_it_t

typedef virtual_patterns_t::const_iterator virtual_patterns_cst_it_t

Definition at line 60 of file Pattern.h.

◆ virtual_patterns_it_t

typedef virtual_patterns_t::iterator virtual_patterns_it_t

note set const iterator type;

Definition at line 58 of file Pattern.h.

◆ virtual_patterns_t

typedef std::set<Pattern*> virtual_patterns_t

note set iterator type;

Definition at line 56 of file Pattern.h.

Constructor & Destructor Documentation

◆ Pattern() [1/2]

Pattern ( const QString & name = "Pattern",
const QString & info = "",
const QString & category = "not_categorized",
int length = MAX_NOTES,
int denominator = 4 )

constructor

Parameters
namethe name of the pattern
infoInitialized with an empty string.
categorythe category of the pattern
lengththe length of the pattern
denominatorthe denominator for meter representation (eg 4/4)

Definition at line 38 of file Pattern.cpp.

◆ Pattern() [2/2]

Pattern ( Pattern * other)

copy constructor

Definition at line 47 of file Pattern.cpp.

◆ ~Pattern()

~Pattern ( )

destructor

Definition at line 59 of file Pattern.cpp.

Member Function Documentation

◆ addFlattenedVirtualPatterns()

void addFlattenedVirtualPatterns ( PatternList * pPatternList)

Add content of __flattened_virtual_patterns into pPatternList.

Companion function of removeFlattenedVirtualPatterns();

Definition at line 319 of file Pattern.cpp.

◆ begin()

std::set< Pattern * >::iterator begin ( )

allow iteration of all contained virtual patterns.

Definition at line 349 of file Pattern.cpp.

◆ end()

std::set< Pattern * >::iterator end ( )

Definition at line 353 of file Pattern.cpp.

◆ find_note() [1/2]

Note * find_note ( int idx_a,
int idx_b,
std::shared_ptr< Instrument > instrument,
bool strict = true ) const

search for a note at a given index within __notes which correspond to the given arguments

Parameters
idx_athe first __notes index to search in
idx_bthe second __notes index to search in, will be omitted if is -1
instrumentthe instrument the note should be playing
strictif set to false, will search for a note around the given idx
Returns
the note if found, 0 otherwise

Definition at line 217 of file Pattern.cpp.

◆ find_note() [2/2]

Note * find_note ( int idx_a,
int idx_b,
std::shared_ptr< Instrument > instrument,
Note::Key key,
Note::Octave octave,
bool strict = true ) const

search for a note at a given index within __notes which correspond to the given arguments

Parameters
idx_athe first __notes index to search in
idx_bthe second __notes index to search in, will be omitted if is -1
instrumentthe instrument the note should be playing
keythe key that should be set to the note
octavethe octave that should be set to the note
strictif set to false, will search for a note around the given idx
Returns
the note if found, 0 otherwise

Definition at line 192 of file Pattern.cpp.

◆ flattened_virtual_patterns_clear()

void flattened_virtual_patterns_clear ( )
inline

Definition at line 396 of file Pattern.h.

◆ flattened_virtual_patterns_compute()

void flattened_virtual_patterns_compute ( )

compute virtual_pattern_transitive_closure_set based on virtual_pattern_transitive_closure_set virtual_pattern_transitive_closure_set must have been cleared before which is the case is called from PatternList::compute_flattened_virtual_patterns

Definition at line 303 of file Pattern.cpp.

◆ get_category()

const QString & get_category ( ) const
inline

set the length of the pattern

Definition at line 330 of file Pattern.h.

◆ get_denominator()

int get_denominator ( ) const
inline

get the note multimap

Definition at line 350 of file Pattern.h.

◆ get_flattened_virtual_patterns()

const Pattern::virtual_patterns_t * get_flattened_virtual_patterns ( ) const
inline

Definition at line 365 of file Pattern.h.

◆ get_info()

const QString & get_info ( ) const
inline

get the category of the pattern

Definition at line 320 of file Pattern.h.

◆ get_length()

int get_length ( ) const
inline

set the denominator of the pattern

Definition at line 340 of file Pattern.h.

◆ get_name()

const QString & get_name ( ) const
inline

set the category of the pattern

Definition at line 310 of file Pattern.h.

◆ get_notes()

const Pattern::notes_t * get_notes ( ) const
inline

get the virtual pattern set

Definition at line 355 of file Pattern.h.

◆ get_virtual_patterns()

const Pattern::virtual_patterns_t * get_virtual_patterns ( ) const
inline

get the flattened virtual pattern set

Definition at line 360 of file Pattern.h.

◆ insert_note()

void insert_note ( Note * note)
inline

insert a new note within __notes

Parameters
notethe note to be inserted

Definition at line 370 of file Pattern.h.

◆ isVirtual()

bool isVirtual ( ) const

Whether the pattern holds at least one virtual pattern.

Definition at line 345 of file Pattern.cpp.

◆ load_file()

Pattern * load_file ( const QString & pattern_path,
std::shared_ptr< InstrumentList > instruments )
static

load a pattern from a file

Parameters
pattern_paththe path to the file to load the pattern from
instrumentsthe current instrument list to search instrument into

Definition at line 106 of file Pattern.cpp.

◆ load_from()

Pattern * load_from ( XMLNode * node,
std::shared_ptr< InstrumentList > instruments,
bool bSilent = false )
static

load a pattern from an XMLNode

Parameters
nodethe XMLDode to read from
instrumentsthe current instrument list to search instrument into
bSilentWhether infos, warnings, and errors should be logged.
Returns
a new Pattern instance

Definition at line 121 of file Pattern.cpp.

◆ loadDoc()

bool loadDoc ( const QString & sPatternPath,
std::shared_ptr< InstrumentList > pInstrumentList,
XMLDoc * pDoc,
bool bSilent = false )
staticprivate

Loads the pattern stored in sPatternPath into pDoc and takes care of all the error handling.

Returns
true on success.

Definition at line 66 of file Pattern.cpp.

◆ longestVirtualPatternLength()

int longestVirtualPatternLength ( ) const

Definition at line 333 of file Pattern.cpp.

◆ purge_instrument()

void purge_instrument ( std::shared_ptr< Instrument > instr,
bool bRequiredLock = true )

delete the notes referencing the given instrument The function is thread safe (it locks the audio data while deleting notes)

Parameters
instrthe instrument

Definition at line 267 of file Pattern.cpp.

◆ references()

bool references ( std::shared_ptr< Instrument > instr)

check if this pattern contains a note referencing the given instrument

Parameters
instrthe instrument

Definition at line 255 of file Pattern.cpp.

◆ remove_note()

void remove_note ( Note * note)

removes a given note from __notes, it's not deleted

Parameters
notethe note to be removed

Definition at line 244 of file Pattern.cpp.

◆ removeFlattenedVirtualPatterns()

void removeFlattenedVirtualPatterns ( PatternList * pPatternList)

Add content of __flattened_virtual_patterns into pPatternList.

Companion function of addFlattenedVirtualPatterns();

Definition at line 326 of file Pattern.cpp.

◆ save_file()

bool save_file ( const QString & drumkit_name,
const QString & author,
const License & license,
const QString & pattern_path,
bool overwrite = false ) const

save a pattern into an xml file

Parameters
drumkit_namethe name of the drumkit it is supposed to play with
authorthe name of the author
licensethe license that applies to it
pattern_paththe path to save the pattern into
overwriteallows to write over existing pattern file
Returns
true on success set the name of the pattern

Definition at line 152 of file Pattern.cpp.

◆ save_to()

void save_to ( XMLNode * node,
const std::shared_ptr< Instrument > instrumentOnly = nullptr ) const

save the pattern within the given XMLNode

Parameters
nodethe XMLNode to feed
instrumentOnlyexport only the notes of that instrument if given

Definition at line 169 of file Pattern.cpp.

◆ set_category()

void set_category ( const QString & category)
inline

set the info of the pattern

Definition at line 325 of file Pattern.h.

◆ set_denominator()

void set_denominator ( int denominator)
inline

get the denominator of the pattern

Definition at line 345 of file Pattern.h.

◆ set_info()

void set_info ( const QString & info)
inline

get the info of the pattern

Definition at line 315 of file Pattern.h.

◆ set_length()

void set_length ( int length)
inline

get the length of the pattern

Definition at line 335 of file Pattern.h.

◆ set_name()

void set_name ( const QString & name)
inline

get the name of the pattern

Definition at line 305 of file Pattern.h.

◆ set_to_old()

void set_to_old ( )

mark all notes as old

return true if __virtual_patterns is empty

Definition at line 294 of file Pattern.cpp.

◆ toQString()

QString toQString ( const QString & sPrefix = "",
bool bShort = true ) const
overridevirtual

Formatted string version for debugging purposes.

Parameters
sPrefixString prefix which will be added in front of every new line
bShortInstead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks.
Returns
String presentation of current object.

Reimplemented from Base.

Definition at line 357 of file Pattern.cpp.

◆ virtual_patterns_add()

void virtual_patterns_add ( Pattern * pattern)
inline

add a pattern to __virtual_patterns

Parameters
patternthe pattern to add

Definition at line 385 of file Pattern.h.

◆ virtual_patterns_clear()

void virtual_patterns_clear ( )
inline

Definition at line 380 of file Pattern.h.

◆ virtual_patterns_del()

void virtual_patterns_del ( Pattern * pattern)
inline

remove a pattern from virtual_pattern set, flattened virtual patterns have to be rebuilt

clear flattened_virtual_patterns

Definition at line 390 of file Pattern.h.

◆ virtual_patterns_empty()

bool virtual_patterns_empty ( ) const
inline

clear __virtual_patterns

Definition at line 375 of file Pattern.h.

Field Documentation

◆ __category

QString __category
private

the category of the pattern

Definition at line 253 of file Pattern.h.

◆ __denominator

int __denominator
private

the meter denominator of the pattern used in meter (eg 4/4)

Definition at line 251 of file Pattern.h.

◆ __flattened_virtual_patterns

virtual_patterns_t __flattened_virtual_patterns
private

the complete list of virtual patterns

Definition at line 257 of file Pattern.h.

◆ __info

QString __info
private

a description of the pattern

Definition at line 254 of file Pattern.h.

◆ __length

int __length
private

Determines the accessible range or notes within the pattern.

Notes are allow to be located at positions larger than __length. This can happen when programming a pattern and decreasing its length later on. Those notes will be stored in the associated .h2pattern and .h2song but won't be played back or exported into a MIDI file.

Definition at line 250 of file Pattern.h.

◆ __name

QString __name
private

the name of thepattern

Definition at line 252 of file Pattern.h.

◆ __notes

notes_t __notes
private

a multimap (hash with possible multiple values for one key) of note

Definition at line 255 of file Pattern.h.

◆ __virtual_patterns

virtual_patterns_t __virtual_patterns
private

a list of patterns directly referenced by this one

Definition at line 256 of file Pattern.h.