1 /* This file is part of the KDE project 2 * Copyright (C) 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 #ifndef MUSIC_CORE_PART_H 20 #define MUSIC_CORE_PART_H 21 22 #include <QObject> 23 #include <QString> 24 25 namespace MusicCore { 26 27 class Staff; 28 class Voice; 29 class Sheet; 30 31 /** 32 * A Part in a piece of music can be for example one instrument. A Part consists of one or more staves (a 33 * piano part will typically have two staves, but most other instruments typically have one staff), and one 34 * or more voices. Musical elements can be added to a voice+staff combination, where the voice decides where 35 * in a bar a musical element should be placed, and the staff controls on what staff to draw the element. 36 */ 37 class Part : public QObject { 38 Q_OBJECT 39 public: 40 /** 41 * Creates a new part in the given sheet with the given name. The part is not added to the sheet, to do that 42 * either call Sheet::addPart(Part*) or use Sheet::addPart(QString) to create a new part. 43 */ 44 Part(Sheet* sheet, const QString& name); 45 46 /** 47 * Destructor. 48 */ 49 ~Part() override; 50 51 /** 52 * Returns the sheet this part is part of. 53 */ 54 Sheet* sheet(); 55 56 /** 57 * Return the name of this part. 58 */ 59 QString name() const; 60 61 /** 62 * Returns the short name of this part. In typical music the long name of a part is printed before the first 63 * staff system, and the short name will be printed in front of the other staff systems. If no short name has been 64 * specified, the normal name will be returned if useFull is true, otherwise a null string will be returned. 65 */ 66 QString shortName(bool useFull = true) const; 67 68 /** 69 * Returns the number of staves in this part. 70 */ 71 int staffCount() const; 72 73 /** 74 * Returns the staff at the given index. If index < 0 or index >= staffCount, this method returns nullptr. 75 * 76 * @param index the index of the staff to return. 77 */ 78 Staff* staff(int index); 79 80 /** 81 * Adds a new staff to this part. The staff is added after all existing staves. 82 */ 83 Staff* addStaff(); 84 85 void addStaff(Staff* staff); 86 87 /** 88 * Inserts a new staff into this part. The staff is inserted before the staff with index before. 89 * 90 * @param before the index of the staff before which the new staff is inserted 91 */ 92 Staff* insertStaff(int before); 93 94 int indexOfStaff(Staff* staff); 95 96 void removeStaff(Staff* staff, bool deleteStaff=true); 97 98 /** 99 * Returns the number of voices in this part. Normally the number of voices will be at least as high as the 100 * number of staves, but this is in no way enforced. 101 */ 102 int voiceCount() const; 103 104 /** 105 * Returns the voice at the given index. 106 * 107 * @param index the index of the voice to return. 108 */ 109 Voice* voice(int index); 110 111 /** 112 * Adds a voice to this part. The created voice is returned. 113 */ 114 Voice* addVoice(); 115 116 int indexOfVoice(Voice* voice); 117 public Q_SLOTS: 118 /** 119 * Change the name of this part. 120 * 121 * @param name the new name of the part 122 */ 123 void setName(const QString& name); 124 125 /** 126 * Change the short name of this part. 127 * 128 * @param shortName the new short name of the part 129 */ 130 void setShortName(const QString& shortName); 131 Q_SIGNALS: 132 void nameChanged(const QString& name); 133 void shortNameChanged(const QString& shortName); 134 private: 135 class Private; 136 Private * const d; 137 }; 138 139 } // namespace MusicCore 140 141 #endif // MUSIC_CORE_PART_H 142