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 #include "toolremovemods.h"
26 #include "soundfontmanager.h"
27
ToolRemoveMods()28 ToolRemoveMods::ToolRemoveMods() :
29 AbstractToolIterating(
30 QList<ElementType>() << elementInst << elementPrst << elementSf2, nullptr, nullptr)
31 {
32
33 }
34
beforeProcess(IdList ids)35 void ToolRemoveMods::beforeProcess(IdList ids)
36 {
37 _deletionType = DeletionGlobal;
38 if (!ids.empty())
39 {
40 switch (ids[0].typeElement)
41 {
42 case elementInst: case elementInstSmpl:
43 _deletionType = DeletionForInstrument;
44 break;
45 case elementPrst: case elementPrstInst:
46 _deletionType = DeletionForPreset;
47 break;
48 default:
49 break;
50 }
51 }
52 _count = 0;
53 }
54
process(SoundfontManager * sm,EltID id,AbstractToolParameters * parameters)55 void ToolRemoveMods::process(SoundfontManager * sm, EltID id, AbstractToolParameters *parameters)
56 {
57 Q_UNUSED(parameters)
58
59 switch (_deletionType)
60 {
61 case DeletionGlobal: {
62 id.typeElement = elementInst;
63 EltID idInst(elementInst, id.indexSf2);
64 foreach (int i, sm->getSiblings(idInst))
65 clearModInst(sm, EltID(elementInst, id.indexSf2, i));
66 EltID idPrst(elementPrst, id.indexSf2);
67 foreach (int i, sm->getSiblings(idPrst))
68 clearModPrst(sm, EltID(elementPrst, id.indexSf2, i));
69 } break;
70 case DeletionForInstrument:
71 id.typeElement = elementInst;
72 clearModInst(sm, id);
73 break;
74 case DeletionForPreset:
75 id.typeElement = elementPrst;
76 clearModPrst(sm, id);
77 break;
78 }
79 }
80
clearModInst(SoundfontManager * sm,EltID idInst)81 void ToolRemoveMods::clearModInst(SoundfontManager *sm, EltID idInst)
82 {
83 // Mods in the global division
84 clearMod(sm, EltID(elementInstMod, idInst.indexSf2, idInst.indexElt));
85
86 // Mods in each division linked to an element
87 EltID idInstSmpl(elementInstSmpl, idInst.indexSf2, idInst.indexElt);
88 foreach (int i, sm->getSiblings(idInstSmpl))
89 clearMod(sm, EltID(elementInstSmplMod, idInst.indexSf2, idInst.indexElt, i));
90 }
91
clearModPrst(SoundfontManager * sm,EltID idPrst)92 void ToolRemoveMods::clearModPrst(SoundfontManager *sm, EltID idPrst)
93 {
94 // Mods in the global division
95 clearMod(sm, EltID(elementPrstMod, idPrst.indexSf2, idPrst.indexElt));
96
97 // Mods in each division linked to an element
98 EltID idPrstInst(elementPrstInst, idPrst.indexSf2, idPrst.indexElt);
99 foreach (int i, sm->getSiblings(idPrstInst))
100 clearMod(sm, EltID(elementPrstInstMod, idPrst.indexSf2, idPrst.indexElt, i));
101 }
102
clearMod(SoundfontManager * sm,EltID idMod)103 void ToolRemoveMods::clearMod(SoundfontManager * sm, EltID idMod)
104 {
105 foreach (int i, sm->getSiblings(idMod))
106 {
107 idMod.indexMod = i;
108 sm->remove(idMod);
109 _count++;
110 }
111 }
112
getConfirmation()113 QString ToolRemoveMods::getConfirmation()
114 {
115 if (_count == 0)
116 return "";
117 else
118 return tr("%n modulator(s) has(have) been deleted.", "", _count);
119 }
120
getWarning()121 QString ToolRemoveMods::getWarning()
122 {
123 if (_count == 0)
124 return tr("The selection contains no modulators.");
125 return "";
126 }
127