hydrogen 1.2.3
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-2024 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;
34class AudioEngineLocking;
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;
190 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
191
193 std::vector<Pattern*>::iterator begin();
194 std::vector<Pattern*>::iterator end();
195
196 private:
197 std::vector<Pattern*> __patterns;
198
199};
200
201// DEFINITIONS
202
203inline int PatternList::size() const
204{
205 return __patterns.size();
206}
207
209{
210 __patterns.clear();
211}
212
213inline void PatternList::operator<<( Pattern* pattern )
214{
215 add( pattern );
216}
217
219 return get( idx );
220}
221
222};
223
224#endif // H2C_PATTERN_LIST_H
225
226/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:224
AudioEngineLocking.
PatternList is a collection of patterns.
Definition PatternList.h:43
void operator<<(Pattern *new_pattern)
add a pattern to the list
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
QString find_unused_pattern_name(QString sourceName, Pattern *ignore=NULL)
find unused patternName
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.
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