hydrogen 1.2.6
PatternList.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef H2C_PATTERN_LIST_H
24#define H2C_PATTERN_LIST_H
25
26#include <vector>
27#include <core/Object.h>
29
30namespace H2Core
31{
32
33class Pattern;
35class InstrumentList;
36class XMLNode;
37
42 class PatternList : public H2Core::Object<PatternList>, public H2Core::AudioEngineLocking
43{
45 public:
54 PatternList( PatternList* other );
55
64 static PatternList* load_from( XMLNode* pNode, std::shared_ptr<InstrumentList> pInstrumentList, bool bSilent = false );
65 void save_to( XMLNode* pNode, const std::shared_ptr<Instrument> pInstrumentOnly = nullptr ) const;
66
68 int size() const;
69
74 void operator<<( Pattern* new_pattern );
79 Pattern* operator[]( int idx );
86 void add( Pattern* pattern, bool bAddVirtuals = false );
92 void insert( int idx, Pattern* pattern );
97 Pattern* get( int idx );
98 Pattern* get( int idx ) const;
104 Pattern* del( int idx );
110 Pattern* del( Pattern* pattern );
116 int index( const Pattern* pattern ) const;
123 Pattern* replace( int idx, Pattern* pattern );
127 void clear();
131 void set_to_old();
137 Pattern* find( const QString& name );
143 void swap( int idx_a, int idx_b );
149 void move( int idx_a, int idx_b );
158 void virtual_pattern_del( Pattern* pattern );
164 bool check_name( QString patternName, Pattern* ignore = NULL );
170 QString find_unused_pattern_name( QString sourceName, Pattern* ignore = NULL );
171
181 int longest_pattern_length( bool bIncludeVirtuals = true ) const;
182
183 friend bool operator==( const PatternList& lhs, const PatternList& rhs );
184 friend bool operator!=( const PatternList& lhs, const PatternList& rhs );
185
186
195 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
196
198 std::vector<Pattern*>::iterator begin();
199 std::vector<Pattern*>::iterator end();
200 std::vector<Pattern*>::const_iterator cbegin() const;
201 std::vector<Pattern*>::const_iterator cend() const;
202
203 private:
204 std::vector<Pattern*> __patterns;
205
206};
207
208// DEFINITIONS
209
210inline int PatternList::size() const
211{
212 return __patterns.size();
213}
214
216{
217 __patterns.clear();
218}
219
220inline void PatternList::operator<<( Pattern* pattern )
221{
222 add( pattern );
223}
224
226 return get( idx );
227}
228
229};
230
231#endif // H2C_PATTERN_LIST_H
232
233/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:227
AudioEngineLocking.
InstrumentList is a collection of instruments used within a song, a drumkit, ...
void operator<<(Pattern *new_pattern)
add a pattern to the list
friend bool operator==(const PatternList &lhs, const PatternList &rhs)
void save_to(XMLNode *pNode, const std::shared_ptr< Instrument > pInstrumentOnly=nullptr) const
bool check_name(QString patternName, Pattern *ignore=NULL)
check if a pattern with name patternName already exists in this list
void add(Pattern *pattern, bool bAddVirtuals=false)
add a pattern to the list
std::vector< Pattern * >::iterator end()
static PatternList * load_from(XMLNode *pNode, std::shared_ptr< InstrumentList > pInstrumentList, bool bSilent=false)
load a PatternList from an XMLNode
int index(const Pattern *pattern) const
get the index of the pattern within the patterns
void set_to_old()
mark all patterns as old
Pattern * replace(int idx, Pattern *pattern)
replace the pattern at a given index with a new one
~PatternList()
destructor
Pattern * operator[](int idx)
get a pattern from the list
void move(int idx_a, int idx_b)
move a pattern from a position to another
std::vector< Pattern * >::const_iterator cend() const
QString find_unused_pattern_name(QString sourceName, Pattern *ignore=NULL)
find unused patternName
std::vector< Pattern * >::const_iterator cbegin() const
Pattern * del(int idx)
remove the pattern at a given index, does not delete it
void flattened_virtual_patterns_compute()
call compute_flattened_virtual_patterns on each pattern
PatternList()
constructor
std::vector< Pattern * >::iterator begin()
Iteration.
friend bool operator!=(const PatternList &lhs, const PatternList &rhs)
int longest_pattern_length(bool bIncludeVirtuals=true) const
Get the length of the longest pattern in the list.
std::vector< Pattern * > __patterns
the list of patterns
void swap(int idx_a, int idx_b)
swap the patterns of two different indexes
Pattern * find(const QString &name)
find a pattern within the patterns
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
void clear()
empty the pattern list
void virtual_pattern_del(Pattern *pattern)
call del_virtual_pattern on each pattern
int size() const
returns the numbers of patterns
void insert(int idx, Pattern *pattern)
insert a pattern into the list
Pattern * get(int idx)
get a pattern from the list
Pattern class is a Note container.
Definition Pattern.h:46
XMLNode is a subclass of QDomNode with read and write values methods.
Definition Xml.h:39