1 /*************************************************************************** 2 ** ** 3 ** Polyphone, a soundfont editor ** 4 ** Copyright (C) 2013-2020 Davy Triponney ** 5 ** ** 6 ** This program is free software: you can redistribute it and/or modify ** 7 ** it under the terms of the GNU General Public License as published by ** 8 ** the Free Software Foundation, either version 3 of the License, or ** 9 ** (at your option) any later version. ** 10 ** ** 11 ** This program is distributed in the hope that it will be useful, ** 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 14 ** GNU General Public License for more details. ** 15 ** ** 16 ** You should have received a copy of the GNU General Public License ** 17 ** along with this program. If not, see http://www.gnu.org/licenses/. ** 18 ** ** 19 **************************************************************************** 20 ** Author: Davy Triponney ** 21 ** Website/Contact: https://www.polyphone-soundfonts.com ** 22 ** Date: 01.01.2013 ** 23 ***************************************************************************/ 24 25 #ifndef PILE_SF2_H 26 #define PILE_SF2_H 27 28 #include "sound.h" 29 #include "basetypes.h" 30 #include <QMap> 31 #include <QObject> 32 class Action; 33 class ActionManager; 34 class Soundfonts; 35 class QAbstractItemModel; 36 class SoloManager; 37 38 class SoundfontManager : public QObject 39 { 40 Q_OBJECT 41 42 public: 43 static SoundfontManager * getInstance(); 44 static void kill(); 45 ~SoundfontManager(); 46 QAbstractItemModel * getModel(int indexSf2); 47 48 // Add / delete data 49 int add(EltID id); 50 void remove(EltID id, int *message = nullptr); 51 52 // Get / set properties 53 bool isSet(EltID id, AttributeType champ); 54 AttributeValue get(EltID id, AttributeType champ); 55 QString getQstr(EltID id, AttributeType champ); 56 Sound *getSound(EltID id); 57 QByteArray getData(EltID id, AttributeType champ); 58 int set(EltID id, AttributeType champ, AttributeValue value); 59 int set(EltID id, AttributeType champ, QString qStr); 60 int set(EltID id, AttributeType champ, QByteArray data); 61 void reset(EltID id, AttributeType champ); 62 void simplify(EltID id, AttributeType champ); 63 64 // Nombre de freres de id (id compris) 65 QList<int> getSiblings(EltID &id); 66 67 // Gestionnaire d'actions 68 void endEditing(QString editingSource); 69 void clearNewEditing(); // Keep the changes but don't make an undo 70 void revertNewEditing(); // Doesn't keep the changes 71 bool isUndoable(int indexSf2); 72 bool isRedoable(int indexSf2); 73 void undo(int indexSf2); 74 void redo(int indexSf2); 75 76 // Edition management 77 void markAsSaved(int indexSf2); 78 bool isEdited(int indexSf2); 79 80 // Get all attributes or modulators related to inst, instsmpl, prst, prstinst 81 void getAllAttributes(EltID id, QList<AttributeType> &listeChamps, QList<AttributeValue> &listeValeurs); 82 void getAllModulators(EltID id, QList<ModulatorData> &modulators); 83 84 // Find if an ID is valid (allowing or not browing in hidden ID, not allowed by default) 85 bool isValid(EltID &id, bool acceptHidden = false, bool justCheckParentLevel = false); 86 87 // Availability of banks / presets 88 void firstAvailablePresetBank(EltID id, int &nBank, int &nPreset); 89 int closestAvailablePreset(EltID id, quint16 wBank, quint16 wPreset); 90 bool isAvailable(EltID id, quint16 wBank, quint16 wPreset); 91 92 // Access to the solo manager solo()93 SoloManager * solo() { return _solo; } 94 95 signals: 96 // Emitted when a group of actions is finished 97 // "editingSource" can be: 98 // * command:{command name} (for instance "command:undo", "command:redo", "command:display", "command:selection") 99 // * tool:{tool kind}:{tool name} 100 // * page:{page name} 101 void editingDone(QString editingSource, QList<int> sf2Indexes); 102 103 private slots: 104 void onDropId(EltID id); 105 106 private: 107 SoundfontManager(); 108 109 /// Display the element ID 110 int display(EltID id); 111 112 /// Delete or hide the element id. Error if the element is used by another 113 int remove(EltID id, bool permanently, bool storeAction, int *message = nullptr); 114 115 /// Clear parameters 116 void supprGenAndStore(EltID id, int storeAction); 117 118 QList<int> undo(QList<Action *> actions); 119 120 static SoundfontManager * s_instance; 121 Soundfonts * _soundfonts; 122 ActionManager * _undoRedo; 123 QMutex _mutex; 124 SoloManager * _solo; 125 }; 126 127 #endif // PILE_SF2_H 128