1 /*
2  *  tracker/SampleEditorControlLastValues.h
3  *
4  *  Copyright 2009 Peter Barth
5  *
6  *  This file is part of Milkytracker.
7  *
8  *  Milkytracker is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  Milkytracker is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with Milkytracker.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef __SAMPLEEDITORCONTROLASTVALUES_H__
24 #define __SAMPLEEDITORCONTROLASTVALUES_H__
25 
26 #include "BasicTypes.h"
27 #include "Dictionary.h"
28 
29 // Last values
30 struct SampleEditorControlLastValues
31 {
32 	pp_int32 newSampleSize;
33 	pp_int32 changeSignIgnoreBits;
34 	float boostSampleVolume;
35 	float fadeSampleVolumeStart;
36 	float fadeSampleVolumeEnd;
37 	float DCOffset;
38 	pp_int32 silenceSize;
39 	float waveFormVolume;
40 	float waveFormNumPeriods;
41 
42 	bool hasEQ3BandValues;
43 	float EQ3BandValues[3];
44 
45 	bool hasEQ10BandValues;
46 	float EQ10BandValues[10];
47 
48 	pp_int32 resampleInterpolationType;
49 	bool adjustFtAndRelnote;
50 
invalidFloatValueSampleEditorControlLastValues51 	static float invalidFloatValue()
52 	{
53 		return -12345678.0f;
54 	}
55 
invalidIntValueSampleEditorControlLastValues56 	static int invalidIntValue()
57 	{
58 		return -12345678;
59 	}
60 
resetSampleEditorControlLastValues61 	void reset()
62 	{
63 		newSampleSize = invalidIntValue();
64 		changeSignIgnoreBits = invalidIntValue();
65 		boostSampleVolume = invalidFloatValue();
66 		fadeSampleVolumeStart = invalidFloatValue();
67 		fadeSampleVolumeEnd = invalidFloatValue();
68 		DCOffset = invalidFloatValue();
69 		silenceSize = invalidIntValue();
70 		waveFormVolume = invalidFloatValue();
71 		waveFormNumPeriods = invalidFloatValue();
72 		hasEQ3BandValues = hasEQ10BandValues = false;
73 		resampleInterpolationType = invalidIntValue();
74 		adjustFtAndRelnote = true;
75 	}
76 
convertToDictionarySampleEditorControlLastValues77 	PPDictionary convertToDictionary()
78 	{
79 		PPDictionary result;
80 
81 		result.store("newSampleSize", newSampleSize);
82 
83 		result.store("changeSignIgnoreBits", changeSignIgnoreBits);
84 
85 		result.store("boostSampleVolume", PPDictionary::convertFloatToIntNonLossy(boostSampleVolume));
86 
87 		result.store("fadeSampleVolumeStart", PPDictionary::convertFloatToIntNonLossy(fadeSampleVolumeStart));
88 		result.store("fadeSampleVolumeEnd", PPDictionary::convertFloatToIntNonLossy(fadeSampleVolumeEnd));
89 
90 		result.store("DCOffset", PPDictionary::convertFloatToIntNonLossy(DCOffset));
91 
92 		result.store("silenceSize", silenceSize);
93 
94 		result.store("waveFormVolume", PPDictionary::convertFloatToIntNonLossy(waveFormVolume));
95 		result.store("waveFormNumPeriods", PPDictionary::convertFloatToIntNonLossy(waveFormNumPeriods));
96 
97 		result.store("resampleInterpolationType", resampleInterpolationType);
98 
99 		result.store("adjustFtAndRelnote", adjustFtAndRelnote);
100 		return result;
101 	}
102 
restoreFromDictionarySampleEditorControlLastValues103 	void restoreFromDictionary(PPDictionary& dictionary)
104 	{
105 		PPDictionaryKey* key = dictionary.getFirstKey();
106 		while (key)
107 		{
108 			if (key->getKey().compareToNoCase("newSampleSize") == 0)
109 			{
110 				newSampleSize = key->getIntValue();
111 			}
112 			else if (key->getKey().compareToNoCase("changeSignIgnoreBits") == 0)
113 			{
114 				changeSignIgnoreBits = key->getIntValue();
115 			}
116 			else if (key->getKey().compareToNoCase("boostSampleVolume") == 0)
117 			{
118 				boostSampleVolume = PPDictionary::convertIntToFloatNonLossy(key->getIntValue());
119 			}
120 			else if (key->getKey().compareToNoCase("fadeSampleVolumeStart") == 0)
121 			{
122 				fadeSampleVolumeStart = PPDictionary::convertIntToFloatNonLossy(key->getIntValue());
123 			}
124 			else if (key->getKey().compareToNoCase("fadeSampleVolumeEnd") == 0)
125 			{
126 				fadeSampleVolumeEnd = PPDictionary::convertIntToFloatNonLossy(key->getIntValue());
127 			}
128 			else if (key->getKey().compareToNoCase("DCOffset") == 0)
129 			{
130 				DCOffset = PPDictionary::convertIntToFloatNonLossy(key->getIntValue());
131 			}
132 			else if (key->getKey().compareToNoCase("silenceSize") == 0)
133 			{
134 				silenceSize = key->getIntValue();
135 			}
136 			else if (key->getKey().compareToNoCase("waveFormVolume") == 0)
137 			{
138 				waveFormVolume = PPDictionary::convertIntToFloatNonLossy(key->getIntValue());
139 			}
140 			else if (key->getKey().compareToNoCase("waveFormNumPeriods") == 0)
141 			{
142 				waveFormNumPeriods = PPDictionary::convertIntToFloatNonLossy(key->getIntValue());
143 			}
144 			else if (key->getKey().compareToNoCase("resampleInterpolationType") == 0)
145 			{
146 				resampleInterpolationType = key->getIntValue();
147 			}
148 			else if (key->getKey().compareToNoCase("adjustFtAndRelnote") == 0)
149 			{
150 				adjustFtAndRelnote = key->getBoolValue();
151 			}
152 
153 			key = dictionary.getNextKey();
154 		}
155 	}
156 };
157 
158 #endif
159