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 ABSTRACTTOOLITERATING_H
26 #define ABSTRACTTOOLITERATING_H
27 
28 #include "abstracttool.h"
29 class WaitingToolDialog;
30 class AbstractToolParameters;
31 
32 class AbstractToolIterating: public AbstractTool
33 {
34     Q_OBJECT
35 
36 public:
37     /// Constructor, with the type of element to manage (can be elementSmpl, elementInst, elementPrst, elementSf2 or a combination)
38     AbstractToolIterating(ElementType elementType, AbstractToolParameters * parameters = nullptr, AbstractToolGui * gui = nullptr);
39     AbstractToolIterating(QList<ElementType> elementTypes, AbstractToolParameters * parameters = nullptr, AbstractToolGui * gui = nullptr);
40     virtual ~AbstractToolIterating() override;
41 
42     /// Method executed before the iterating process
beforeProcess(IdList ids)43     virtual void beforeProcess(IdList ids) { Q_UNUSED(ids) }
44 
45     /// Process an element
46     virtual void process(SoundfontManager * sm, EltID id, AbstractToolParameters * parameters) = 0;
47 
48 signals:
49     void elementProcessed();
50 
51 protected:
52     /// Return true if the tool can be used on the specified ids
53     bool isCompatible(IdList ids) override;
54 
55     /// Run the tool on a list of id
56     void runInternal(SoundfontManager * sm, QWidget * parent, IdList ids, AbstractToolParameters * parameters) override;
57 
58     // Additional configurations
59     bool _openWaitDialogJustInProcess; // false by default
60     bool _async; // true by default
61 
62 private slots:
63     void onElementProcessed();
64     void onCancel();
65 
66 private:
67     QList<ElementType> _elementTypes;
68     WaitingToolDialog * _waitingDialog;
69     int _steps;
70     int _currentStep;
71     bool _canceled;
72     IdList _idsToProcess;
73     SoundfontManager * _sm;
74     AbstractToolParameters * _parameters;
75 };
76 
77 #endif // ABSTRACTTOOLITERATING_H
78