1 /*
2  * Copyright (C) 2018-2020 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 <cstdint>
29 #include <cstddef>
30 #include <string>
31 #include <unordered_map>
32 #include <vector>
33 #include "enum_hash.hpp"
34 #include "misc.hpp"
35 
36 enum class JamKey : int;
37 
38 struct FMEnvelopeText
39 {
40 	std::string name;
41 	std::vector<FMEnvelopeTextType> texts;
42 };
43 
44 class Configuration
45 {
46 public:
47 	Configuration();
48 
49 	// Internal //
50 public:
51 	void setFollowMode(bool enabled);
52 	bool getFollowMode() const;
53 	void setWorkingDirectory(std::string path);
54 	std::string getWorkingDirectory() const;
55 	void setInstrumentOpenFormat(int i);
56 	int getInstrumentOpenFormat() const;
57 	void setBankOpenFormat(int i);
58 	int getBankOpenFormat() const;
59 	void setInstrumentMask(bool enabled);
60 	bool getInstrumentMask() const;
61 	void setVolumeMask(bool enabled);
62 	bool getVolumeMask() const;
63 	void setVisibleToolbar(bool visible);
64 	bool getVisibleToolbar() const;
65 	void setVisibleStatusBar(bool visible);
66 	bool getVisibleStatusBar() const;
67 	void setVisibleWaveView(bool visible);
68 	bool getVisibleWaveView() const;
69 	enum PasteMode { CURSOR = 0, SELECTION, FILL };
70 	void setPasteMode(PasteMode mode);
71 	PasteMode getPasteMode() const;
72 private:
73 	bool followMode_;
74 	std::string workDir_;
75 	int instOpenFormat_, bankOpenFormat_;
76 	bool instMask_, volMask_;
77 	bool visibleToolbar_, visibleStatusBar_, visibleWaveView_;
78 	PasteMode pasteMode_;
79 
80 	// Mainwindow state
81 public:
82 	void setMainWindowWidth(int w);
83 	int getMainWindowWidth() const;
84 	void setMainWindowHeight(int h);
85 	int getMainWindowHeight() const;
86 	void setMainWindowMaximized(bool isMax);
87 	bool getMainWindowMaximized() const;
88 	void setMainWindowX(int x);
89 	int getMainWindowX() const;
90 	void setMainWindowY(int y);
91 	int getMainWindowY() const;
92 	void setMainWindowVerticalSplit(int y);
93 	int getMainWindowVerticalSplit() const;
94 private:
95 	int mainW_, mainH_;
96 	bool mainMax_;
97 	int mainX_, mainY_;
98 	int mainVSplit_;
99 
100 	// Instrument editor state
101 public:
102 	void setInstrumentFMWindowWidth(int w);
103 	int getInstrumentFMWindowWidth() const;
104 	void setInstrumentFMWindowHeight(int h);
105 	int getInstrumentFMWindowHeight() const;
106 	void setInstrumentSSGWindowWidth(int w);
107 	int getInstrumentSSGWindowWidth() const;
108 	void setInstrumentSSGWindowHeight(int h);
109 	int getInstrumentSSGWindowHeight() const;
110 	void setInstrumentADPCMWindowWidth(int w);
111 	int getInstrumentADPCMWindowWidth() const;
112 	void setInstrumentADPCMWindowHeight(int h);
113 	int getInstrumentADPCMWindowHeight() const;
114 	void setInstrumentDrumkitWindowWidth(int w);
115 	int getInstrumentDrumkitWindowWidth() const;
116 	void setInstrumentDrumkitWindowHeight(int h);
117 	int getInstrumentDrumkitWindowHeight() const;
118 private:
119 	int instFMW_, instFMH_;
120 	int instSSGW_, instSSGH_;
121 	int instADPCMW_, instADPCMH_;
122 	int instKitW_, instKitH_;
123 
124 	// Toolbar state
125 public:
126 	class ToolbarConfiguration
127 	{
128 	public:
129 		enum ToolbarPosition : int { TOP_POS = 0, BOTTOM_POS, LEFT_POS, RIGHT_POS, FLOAT_POS };
130 		void setPosition(ToolbarPosition pos);
131 		ToolbarPosition getPosition() const;
132 		void setNumber(int n);
133 		int getNumber() const;
134 		void setBreakBefore(bool enabled);
135 		bool hasBreakBefore() const;
136 		void setX(int x);
137 		int getX() const;
138 		void setY(int y);
139 		int getY() const;
140 	private:
141 		ToolbarPosition pos_;
142 		int num_;
143 		bool hasBreakBefore_;
144 		int x_, y_;
145 	};
146 	ToolbarConfiguration& getMainToolbarConfiguration();
147 	ToolbarConfiguration& getSubToolbarConfiguration();
148 private:
149 	ToolbarConfiguration mainTb_, subTb_;
150 
151 	// General //
152 	// General settings
153 public:
154 	void setWarpCursor(bool enabled);
155 	bool getWarpCursor() const;
156 	void setWarpAcrossOrders(bool enabled);
157 	bool getWarpAcrossOrders() const;
158 	void setShowRowNumberInHex(bool enabled);
159 	bool getShowRowNumberInHex() const;
160 	void setShowPreviousNextOrders(bool enabled);
161 	bool getShowPreviousNextOrders() const;
162 	void setBackupModules(bool enabled);
163 	bool getBackupModules() const;
164 	void setDontSelectOnDoubleClick(bool enabled);
165 	bool getDontSelectOnDoubleClick() const;
166 	void setReverseFMVolumeOrder(bool enabled);
167 	bool getReverseFMVolumeOrder() const;
168 	void setMoveCursorToRight(bool enabled);
169 	bool getMoveCursorToRight() const;
170 	void setRetrieveChannelState(bool enabled);
171 	bool getRetrieveChannelState() const;
172 	void setEnableTranslation(bool enabled);
173 	bool getEnableTranslation() const;
174 	void setShowFMDetuneAsSigned(bool enabled);
175 	bool getShowFMDetuneAsSigned() const;
176 	void setFill00ToEffectValue(bool enabled);
177 	bool getFill00ToEffectValue() const;
178 	void setMoveCursorByHorizontalScroll(bool enabled);
179 	bool getMoveCursorByHorizontalScroll() const;
180 	void setOverwriteUnusedUneditedPropety(bool enabled);
181 	bool getOverwriteUnusedUneditedPropety() const;
182 	void setWriteOnlyUsedSamples(bool enabled);
183 	bool getWriteOnlyUsedSamples() const;
184 	void setReflectInstrumentNumberChange(bool enabled);
185 	bool getReflectInstrumentNumberChange() const;
186 	void setFixJammingVolume(bool enabled);
187 	bool getFixJammingVolume() const;
188 	void setMuteHiddenTracks(bool enabled);
189 	bool getMuteHiddenTracks() const;
190 	void setRestoreTrackVisibility(bool enabled);
191 	bool getRestoreTrackVisibility() const;
192 private:
193 	bool warpCursor_, warpAcrossOrders_, showRowNumHex_, showPrevNextOrders_, backupModules_;
194 	bool dontSelectOnDoubleClick_, reverseFMVolumeOrder_, moveCursorToRight_, retrieveChannelState_;
195 	bool enableTranslation_, showFMDetuneSigned_, fill00ToEffectValue_, moveCursorHScroll_;
196 	bool overwriteUnusedUnedited_, writeOnlyUsedSamples_, reflectInstNumChange_, fixJamVol_;
197 	bool muteHiddenTracks_, restoreTrackVis_;
198 
199 	// Edit settings
200 public:
201 	void setPageJumpLength(size_t length);
202 	size_t getPageJumpLength() const;
203 	void setEditableStep(size_t step);
204 	size_t getEditableStep() const;
205 	void setKeyRepetition(bool enabled);
206 	bool getKeyRepetition() const;
207 private:
208 	size_t pageJumpLength_, editableStep_;
209 	bool keyRepetision_;
210 
211 	// Wave view
212 public:
213 	void setWaveViewFrameRate(int rate);
214 	int getWaveViewFrameRate() const;
215 private:
216 	int waveViewFps_;
217 
218 	// Keys
219 public:
220 	enum ShortcutAction : int
221 	{
222 		KeyOff, OctaveUp, OctaveDown, EchoBuffer, PlayAndStop, Play, PlayFromStart, PlayPattern,
223 		PlayFromCursor, PlayFromMarker, PlayStep, Stop, FocusOnPattern, FocusOnOrder, FocusOnInstrument,
224 		ToggleEditJam, SetMarker, PasteMix, PasteOverwrite, PasteInsert, SelectAll, Deselect, SelectRow, SelectColumn,
225 		SelectPattern, SelectOrder, GoToStep, ToggleTrack, SoloTrack, Interpolate, Reverse, GoToPrevOrder,
226 		GoToNextOrder, ToggleBookmark, PrevBookmark, NextBookmark, DecreaseNote, IncreaseNote,
227 		DecreaseOctave, IncreaseOctave, PrevInstrument, NextInstrument, MaskInstrument, MaskVolume,
228 		EditInstrument, FollowMode, DuplicateOrder, ClonePatterns, CloneOrder, ReplaceInstrument,
229 		ExpandPattern, ShrinkPattern, FineDecreaseValues, FineIncreaseValues, CoarseDecreaseValues,
230 		CoarseIncreaseValuse, ExpandEffect, ShrinkEffect, PrevHighlighted, NextHighlighted,
231 		IncreasePatternSize, DecreasePatternSize, IncreaseEditStep, DecreaseEditStep, DisplayEffectList,
232 		PreviousSong, NextSong, JamVolumeUp, JamVolumeDown
233 	};
234 	void setShortcuts(std::unordered_map<ShortcutAction, std::string> shortcuts);
235 	std::unordered_map<ShortcutAction, std::string> getShortcuts() const;
236 	enum KeyboardLayout : int
237 	{
238 		// at the top, so new layouts can easily be added in after it
239 		// and it's always easy to find no matter how many layouts we add
240 		Custom = 0,
241 		QWERTY,
242 		QWERTZ,
243 		AZERTY
244 	};
245 	static const std::unordered_map<std::string, JamKey> mappingQWERTY, mappingQWERTZ, mappingAZERTY;
246 	std::unordered_map<std::string, JamKey> mappingCustom;
247 	std::unordered_map<KeyboardLayout, std::unordered_map<std::string, JamKey>> mappingLayouts;
248 	void setNoteEntryLayout(KeyboardLayout layout);
249 	KeyboardLayout getNoteEntryLayout() const;
250 	void setCustomLayoutKeys(std::unordered_map<std::string, JamKey> mapping);
251 	std::unordered_map<std::string, JamKey> getCustomLayoutKeys() const;
252 
253 private:
254 	std::unordered_map<ShortcutAction, std::string> shortcuts_;
255 	KeyboardLayout noteEntryLayout_;
256 
257 	// Sound //
258 public:
259 	void setSoundAPI(std::string api);
260 	std::string getSoundAPI() const;
261 	void setSoundDevice(std::string device);
262 	std::string getSoundDevice() const;
263 	void setRealChipInterface(RealChipInterface type);
264 	RealChipInterface getRealChipInterface() const;
265 	void setEmulator(int emulator);
266 	int getEmulator() const;
267 	void setSampleRate(uint32_t rate);
268 	uint32_t getSampleRate() const;
269 	void setBufferLength(size_t length);
270 	size_t getBufferLength() const;
271 private:
272 	std::string sndAPI_, sndDevice_;
273 	RealChipInterface realChip_;
274 	int emulator_;
275 	uint32_t sampleRate_;
276 	size_t bufferLength_;
277 
278 	// Midi //
279 public:
280 	void setMidiAPI(const std::string& api);
281 	std::string getMidiAPI() const;
282 	void setMidiInputPort(const std::string& port);
283 	std::string getMidiInputPort() const;
284 private:
285 	std::string midiAPI_, midiInPort_;
286 
287 	// Mixer //
288 public:
289 	void setMixerVolumeMaster(int percentage);
290 	int getMixerVolumeMaster() const;
291 	void setMixerVolumeFM(double dB);
292 	double getMixerVolumeFM() const;
293 	void setMixerVolumeSSG(double dB);
294 	double getMixerVolumeSSG() const;
295 private:
296 	int mixerVolumeMaster_;
297 	double mixerVolumeFM_, mixerVolumeSSG_;
298 
299 	// Input //
300 public:
301 	void setFMEnvelopeTexts(std::vector<FMEnvelopeText> texts);
302 	std::vector<FMEnvelopeText> getFMEnvelopeTexts() const;
303 
304 	// Appearance //
305 public:
306 	void setPatternEditorHeaderFont(std::string font);
307 	std::string getPatternEditorHeaderFont() const;
308 	void setPatternEditorHeaderFontSize(int size);
309 	int getPatternEditorHeaderFontSize() const;
310 	void setPatternEditorRowsFont(std::string font);
311 	std::string getPatternEditorRowsFont() const;
312 	void setPatternEditorRowsFontSize(int size);
313 	int getPatternEditorRowsFontSize() const;
314 	void setOrderListHeaderFont(std::string font);
315 	std::string getOrderListHeaderFont() const;
316 	void setOrderListHeaderFontSize(int size);
317 	int getOrderListHeaderFontSize() const;
318 	void setOrderListRowsFont(std::string font);
319 	std::string getOrderListRowsFont() const;
320 	void setOrderListRowsFontSize(int size);
321 	int getOrderListRowsFontSize() const;
322 private:
323 	std::string ptnHdFont_, ptnRowFont_, odrHdFont_, odrRowFont_;
324 	int ptnHdFontSize_, ptnRowFontSize_, odrHdFontSize_, odrRowFontSize_;
325 
326 private:
327 	std::vector<FMEnvelopeText> fmEnvelopeTexts_;
328 };
329