Debian Codegraph @

BambooTracker/gui/instrument_editor/instrument_editor_manager.hpp

raw
1 /*
2 * Copyright (C) 2018-2022 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #pragma once
27
28 #include <QObject>
29 #include <QPointer>
30 #include <QHash>
31 #include <QSet>
32 #include "instrument/envelope_fm.hpp"
33 #include "bamboo_tracker_defs.hpp"
34 #include "utils.hpp"
35
36 class InstrumentEditor;
37 enum class InstrumentType;
38
39 // Hash function for QHash
40 constexpr uint qHash(const InstrumentType& type, uint seed)
41 {
42 return qHash(static_cast<int>(type), seed);
43 }
44
45 /**
46 * @brief The InstrumentEditorManager class
47 */
48 class InstrumentEditorManager : public QObject
49 {
50 Q_OBJECT
51
52 public:
53 /**
54 * @brief Constructor.
55 */
56 InstrumentEditorManager();
57
58 /**
59 * @brief Destructor.
60 */
61 ~InstrumentEditorManager();
62
63 /**
64 * @brief Update editors by changing configuration.
65 */
66 void updateByConfiguration();
67
68 /**
69 * @brief add Add instrument editor to editor list.
70 * @param index Index of instrument editor in editor list.
71 * @param editor Shared pointer of editor.
72 * @return \c true when editor addition is success.
73 */
74 bool add(int index, InstrumentEditor* editor);
75
76 /**
77 * @brief Swap editors in editor list.
78 * @param index1 1st index of editor.
79 * @param index2 2nd index of editor.
80 */
81 void swap(int index1, int index2);
82
83 /**
84 * @brief Remove editor from editor list and dispose it.
85 * If editor is opened, it will be closed.
86 * @param index Index of editor in editor list.
87 * @return \c true when editor deletion is success.
88 */
89 bool remove(int index);
90
91 /**
92 * @brief showEditor
93 * @param index Index of editor in editor list.
94 */
95 void showEditor(int index);
96
97 /**
98 * @brief Dispose all managed editors.
99 * Opened editors are closed.
100 */
101 void removeAll();
102
103 /**
104 * @brief hasShownEditor
105 * @param index Index of editor in editor list.
106 * @return \c true when editor list registers editor.
107 */
108 bool hasShownEditor(int index) const;
109
110 /**
111 * @brief getActivatedEditorIndex
112 * @return Index of editor in doalog list.
113 * When no editor is activated, returns -1.
114 */
115 int getActivatedEditorIndex() const;
116
117 public slots:
118 // Update windows title
119 void onInstrumentNameChanged(int instNum);
120
121 // Update FM parameters
122 void onInstrumentFMEnvelopeParameterChanged(int envNum, int fromInstNum);
123 void onInstrumentFMEnvelopeNumberChanged();
124 void onInstrumentFMLFOParameterChanged(int lfoNum, int fromInstNum);
125 void onInstrumentFMLFONumberChanged();
126 void onInstrumentFMOperatorSequenceParameterChanged(FMEnvelopeParameter param, int opSeqNum, int fromInstNum);
127 void onInstrumentFMOperatorSequenceNumberChanged();
128 void onInstrumentFMArpeggioParameterChanged(int arpNum, int fromInstNum);
129 void onInstrumentFMArpeggioNumberChanged();
130 void onInstrumentFMPitchParameterChanged(int ptNum, int fromInstNum);
131 void onInstrumentFMPitchNumberChanged();
132
133 // Update SSG parameters
134 void onInstrumentSSGWaveformParameterChanged(int wfNum, int fromInstNum);
135 void onInstrumentSSGWaveformNumberChanged();
136 void onInstrumentSSGToneNoiseParameterChanged(int tnNum, int fromInstNum);
137 void onInstrumentSSGToneNoiseNumberChanged();
138 void onInstrumentSSGEnvelopeParameterChanged(int envNum, int fromInstNum);
139 void onInstrumentSSGEnvelopeNumberChanged();
140 void onInstrumentSSGArpeggioParameterChanged(int arpNum, int fromInstNum);
141 void onInstrumentSSGArpeggioNumberChanged();
142 void onInstrumentSSGPitchParameterChanged(int ptNum, int fromInstNum);
143 void onInstrumentSSGPitchNumberChanged();
144
145 // Update ADPCM/Drumkit parameters
146 void onInstrumentADPCMSampleParameterChanged(int sampNum, int fromInstNum);
147 void onInstrumentADPCMSampleNumberChanged();
148 void onInstrumentADPCMSampleMemoryUpdated();
149 void onInstrumentADPCMEnvelopeParameterChanged(int envNum, int fromInstNum);
150 void onInstrumentADPCMEnvelopeNumberChanged();
151 void onInstrumentADPCMArpeggioParameterChanged(int arpNum, int fromInstNum);
152 void onInstrumentADPCMArpeggioNumberChanged();
153 void onInstrumentADPCMPitchParameterChanged(int ptNum, int fromInstNum);
154 void onInstrumentADPCMPitchNumberChanged();
155
156 private:
157 // Size of editor list
158 enum { MAX_NUM_EDITOR = 128 };
159 // Editor list
160 QPointer<InstrumentEditor> editors_[MAX_NUM_EDITOR];
161 // Map of instrument type and editor index list
162 QHash<InstrumentType, QSet<int>> typeIndices_;
163
164 // Assert that given index is valid for editor list.
165 static constexpr bool assertIndex(int index) { return utils::isInRange<int>(index, 0, MAX_NUM_EDITOR); }
166
167 // Get indices of editor which is neccessary to update parameters.
168 inline QSet<int> getIndicesForParameterUpdating(InstrumentType type, int skippedIdx = -1)
169 {
170 auto idcs = typeIndices_[type];
171 if (assertIndex(skippedIdx)) idcs.remove(skippedIdx);
172 return idcs;
173 }
174 };