summaryrefslogtreecommitdiffstats
path: root/noatun/library/noatun/equalizer.h
blob: a654fd139feacd418151835a2d49936916843a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef NOATUN_EQUALIZER_H
#define NOATUN_EQUALIZER_H

#include <tqptrlist.h>
#include <tqobject.h>
#include <kurl.h>
#include <noatun/vequalizer.h>

class Engine;
class Equalizer;

/**
 * a preset stores the state of the equalizer
 *
 * @short EQ Preset
 * @author Charles Samuels
 * @version 2.3
 **/
class Preset
{
friend class Equalizer;

	Preset(const TQString &file);
	Preset();
	Preset(VPreset p);

public:
	TQString name() const;
	bool setName(const TQString &name);
	bool save() const;
	bool load();

	void remove();

	TQString file() const;

	VPreset &vpreset() const;
private:
	TQString mFile;
};

/**
 * This represents a single band in Noatuns %Equalizer
 *
 * @short EQ Band
 * @author Charles Samuels
 * @version 2.3
 **/
class Band
{
friend class Equalizer;
friend class TQPtrList<Band>;

private:
	Band();
	Band(int start, int end);
	Band(int band);
	virtual ~Band();
public:
	/**
	 * the intensity of the change.
	 * it's logarithmic.  0 is no change
	 * negative numbers are loss in intensity
	 * positive numbers are a gain
	 * And +-100 is the most you'd need to go
	 **/
	int level();
	void setLevel(int l);

	int start() const;
	int end() const;

	/**
	 * the middle between start and end
	 **/
	int center() const;

	TQString formatStart(bool withHz=true) const;
	TQString formatEnd(bool withHz=true) const;
	/**
	 * return the format for center()
	 **/
	TQString format(bool withHz=true) const;

private:
	int mOffset;
	int mNum, mEnd;
};


/**
 * @deprecated
 *
 * this API is deprecated!!!  Do not use it!
 * it acts as a wrapper around the new VEqualizer API
 * This only exists to keep compatibility in both
 * source and binary forms.  It will go away in the future.
 * @short old Equalizer
 * @author Charles Samuels
 * @version 2.3
 **/
class Equalizer : public TQObject
{
friend class Band;
friend class Preset;
friend class Engine;

Q_OBJECT
  
public:
	Equalizer();
	~Equalizer();

	const TQPtrList<Band> &bands() const;
	Band *band(int num) const;
	int bandCount() const;

	int preamp() const;
	bool isEnabled() const;

	void init();

public slots:
	/**
	 * set the preamplification
	 * it's logarithmic.  0 is no change
	 * negative numbers are loss in intensity
	 * positive numbers are a gain
	 * And +-100 is the most you'd need to go
	 **/
	void setPreamp(int p);
	void enable();
	void disable();
	void setEnabled(bool e);


public:
// saving eq stuff
	/**
	 * save the current levels
	 * all noatun equalizer files have the "*.noatunequalizer"
	 * pattern.  Nevertheless, the file can be identified
	 * by magic, so it's not required
	 **/
	bool save(const KURL &file, const TQString &friendly) const;

	/**
	 * restore the EQ settings from this file
	 **/
	bool load(const KURL &file);

	/**
	 * convert the current EQ settings to string form,
	 * suitable for storage, the given string is the title
	 *
	 * @see fromString
	 **/
	TQString toString(const TQString &name="stored") const;

	/**
	 * undo a toString, restoring the EQ
	 * to the settings in the given string,
	 * emitting the changed signals
	 **/
	bool fromString(const TQString &str);

	/**
	 * create a preset with such a name
	 * and remember that it'l return zero
	 * if the name already exists
	 *
	 * If smart is true, append a number to the end
	 * of the name, if one already exists by the given
	 **/
	Preset *createPreset(const TQString &name, bool smart=true);

	/**
	 * return all the presets
	 * remember to setAutoDelete on this
	 **/
	TQPtrList<Preset> presets() const;

	Preset *preset(const TQString &file);
	bool presetExists(const TQString &name) const;

signals:
	void changed(Band *band);
	void changed();
	void enabled();
	void disabled();
	void enabled(bool e);

	void preampChanged(int p);
	void preampChanged();

	/**
	 * the preset with the given name
	 * was selected
	 **/
	void changed(Preset *);

	/**
	 * when a new preset has been created
	 **/
	void created(Preset*);

	/**
	 * when @p preset has been renamed to @p newname
	 **/
	void renamed(Preset *);

	/**
	 * the given preset has been removed
	 **/
	void removed(Preset *);

private slots:
	void created(VPreset preset);
	void selected(VPreset preset);
	void renamed(VPreset preset);
	void removed(VPreset preset);

private:
	void add(Band*);
	void remove(Band*);
	// apply the data to artsd
	void enableUpdates(bool on=true);
	void update(bool full=false);

private:
	TQPtrList<Band> mBands;
	bool mUpdates;
	int mPreamp;
};



#endif