summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/doc/html/eventhandler_8hcc-source.html
blob: 24170bfeca3b8c6e658644bddb00740e508f9618 (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Graphic Equalizer: C:/Project  Marcel &amp; Oliver/Graphic_Equalizer/src/eventhandler.hcc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">Globals</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">C:</a>&nbsp;/&nbsp;<a class="el" href="dir_000001.html">Project  Marcel &amp; Oliver</a>&nbsp;/&nbsp;<a class="el" href="dir_000002.html">Graphic_Equalizer</a>&nbsp;/&nbsp;<a class="el" href="dir_000004.html">src</a></div>
<h1>eventhandler.hcc</h1><a href="eventhandler_8hcc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 
00021 <span class="comment">/******** System Includes *************/</span>
00022 <span class="preprocessor">#include &lt;stdlib.hch&gt;</span>
00023 
00024 <span class="preprocessor">#include "pal_master.hch"</span>
00025 
00026 <span class="comment">/******** Application Includes ********/</span>
00027 <span class="preprocessor">#include "<a class="code" href="configuration_8hch.html">configuration.hch</a>"</span>
00028 <span class="preprocessor">#include "<a class="code" href="audio_8hch.html">audio.hch</a>"</span>
00029 <span class="preprocessor">#include "<a class="code" href="mouse__shared_8hch.html">mouse_shared.hch</a>"</span>
00030 <span class="preprocessor">#include "<a class="code" href="eventhandler__shared_8hch.html">eventhandler_shared.hch</a>"</span>
00031 <span class="preprocessor">#include "<a class="code" href="eventhandler_8hch.html">eventhandler.hch</a>"</span>
00032 <span class="preprocessor">#include "<a class="code" href="events_8hch.html">events.hch</a>"</span>
00033 <span class="preprocessor">#include "<a class="code" href="display__shared_8hch.html">display_shared.hch</a>"</span>
00034 <span class="preprocessor">#include "<a class="code" href="display_8hch.html">display.hch</a>"</span>
00035 
00036 <span class="preprocessor">#if HAVE_DEBUG</span>
00037 <span class="preprocessor"></span><span class="preprocessor">        #include "debug.hch"</span>
00038 <span class="preprocessor">#endif</span>
00039 <span class="preprocessor"></span>
00040 
00041 
00042 <span class="comment">/*</span>
00043 <span class="comment"> */</span>
00044 <span class="keyword">extern</span> chan <span class="keywordtype">unsigned</span> 1 maskupdate_notification;
00045 
00046 
00047 
00048 <span class="keyword">static</span> rom <span class="keywordtype">unsigned</span> 3 equalizer_mode_table[5] = {EQUALIZERMODE_CONVEX_FULL, EQUALIZERMODE_CONVEX_HALF, EQUALIZERMODE_PRECISE, EQUALIZERMODE_CONCAVE_HALF, EQUALIZERMODE_CONCAVE_FULL};
00049 
00050 
00051 
<a name="l00063"></a><a class="code" href="eventhandler_8hcc.html#a3">00063</a> <span class="keywordtype">void</span> <a class="code" href="eventhandler_8hcc.html#a3">eventhandler_main</a>(audiodata_t *audiodata, events_t *events, mousedata_t *mousedata) {
00064         mpram {
00065                 ram <span class="keywordtype">unsigned</span> 4 write[768];      
00066                 rom <span class="keywordtype">unsigned</span> 4 read[768];       
00067         } equalizer_levels with { block = <span class="stringliteral">"BlockRAM"</span>};
00068 
00069         <span class="keywordtype">unsigned</span> 10 preset_offset;
00070         <span class="keywordtype">unsigned</span> 10 reference_point;
00071         <span class="keywordtype">unsigned</span> 5 volume_left;
00072         <span class="keywordtype">unsigned</span> 4 index_offset;
00073         <span class="keywordtype">unsigned</span> 1 newmaskupdate;
00074 
00075         <span class="comment">/*</span>
00076 <span class="comment">         * Initialize our equalizer display pointers here, as they don't point</span>
00077 <span class="comment">         * anywhere otherwise.</span>
00078 <span class="comment">         */</span>
00079 
00080         <span class="keywordflow">while</span> (TRUE) {
00081                 maskupdate_notification ? newmaskupdate;
00082 
00083                 <span class="comment">/*</span>
00084 <span class="comment">                 * First we determine what mousestate we currently have. Then</span>
00085 <span class="comment">                 * we check where we are to decide what to do.</span>
00086 <span class="comment">                 */</span>
00087                 <span class="keywordflow">switch</span> (mousedata-&gt;state) {
00088                         <span class="keywordflow">case</span> MOUSE_STATE_ON_PRESS:
00089                                 <span class="comment">/*</span>
00090 <span class="comment">                                 * If we are displaying the graphic visual,</span>
00091 <span class="comment">                                 * any press returns to the application.</span>
00092 <span class="comment">                                 */</span>
00093                                 <span class="keywordflow">if</span> (MODE_GRAPH == events-&gt;mode) {
00094                                         events-&gt;mode = MODE_SKIN;
00095                                         events-&gt;mask = 0;
00096                                 } <span class="keywordflow">else</span> {
00097                                         delay;
00098                                 }
00099 
00100                                 <span class="comment">/*</span>
00101 <span class="comment">                                 */</span>
00102                                 <span class="keywordflow">if</span> (BUTTON_MODE == events-&gt;mask) {
00103                                         <span class="keywordflow">if</span> (MODE_GRAPH == events-&gt;mode) {
00104                                                 events-&gt;mode = MODE_SKIN;
00105                                         } <span class="keywordflow">else</span> {
00106                                                 events-&gt;mode = MODE_GRAPH;
00107                                         }
00108                                 } <span class="keywordflow">else</span> {
00109                                         delay;
00110                                 }
00111 
00112                                 <span class="comment">/*</span>
00113 <span class="comment">                                 * If the current mask equals the help button</span>
00114 <span class="comment">                                 * we set display mode to help.</span>
00115 <span class="comment">                                 */</span>
00116                                 <span class="keywordflow">if</span> (BUTTON_HELP == events-&gt;mask) {
00117                                         <span class="comment">/*</span>
00118 <span class="comment">                                         * Change the mode to help if it's</span>
00119 <span class="comment">                                         * currently not set, otherwise go back</span>
00120 <span class="comment">                                         * to skin mode.</span>
00121 <span class="comment">                                         */</span>
00122                                         <span class="keywordflow">if</span> (MODE_HELP == events-&gt;mode) {
00123                                                 events-&gt;mode = MODE_SKIN;
00124                                         } <span class="keywordflow">else</span> {
00125                                                 events-&gt;mode = MODE_HELP;
00126                                                 print_string(<span class="stringliteral">"going to help"</span>);print_eol();
00127                                         }
00128                                 } <span class="keywordflow">else</span> {
00129                                         delay;
00130                                 }
00131 
00132                                 <span class="comment">/*</span>
00133 <span class="comment">                                 * The Preset buttons span from 1 to 6 so if</span>
00134 <span class="comment">                                 * the mask one of those, we'll change the</span>
00135 <span class="comment">                                 * pointer to point to the current preset.</span>
00136 <span class="comment">                                 */</span>
00137                                 <span class="keywordflow">if</span> ((BUTTON_PRESET_1 &lt;= events-&gt;mask) &amp;&amp; (events-&gt;mask &lt;= BUTTON_PRESET_6)) {
00138                                         <span class="comment">/*</span>
00139 <span class="comment">                                         * The active preset is determined by</span>
00140 <span class="comment">                                         * the mask minus an offset. Hence</span>
00141 <span class="comment">                                         * ranging our active preset from 0 to</span>
00142 <span class="comment">                                         * 6.</span>
00143 <span class="comment">                                         */</span>
00144                                         events-&gt;active_preset = 0 @ (events-&gt;mask -BUTTON_PRESET_1);
00145                                         <span class="comment">/*</span>
00146 <span class="comment">                                         * Each equalizer is 128 bands wide,</span>
00147 <span class="comment">                                         * thus we need to add 128 * the preset</span>
00148 <span class="comment">                                         * for each different preset. This</span>
00149 <span class="comment">                                         * offset is calculated here.</span>
00150 <span class="comment">                                         */</span>
00151                                         preset_offset = events-&gt;active_preset &lt;&lt; 7;
00152                                         <span class="comment">/*</span>
00153 <span class="comment">                                         * We set the pointer to the active</span>
00154 <span class="comment">                                         * part of the array by using the</span>
00155 <span class="comment">                                         * preset offset as our index. Hence</span>
00156 <span class="comment">                                         * depending on the selected preset</span>
00157 <span class="comment">                                         * we point to 0, 128, 256, 384, 512</span>
00158 <span class="comment">                                         * or 640.</span>
00159 <span class="comment">                                         */</span>
00160                                         audiodata-&gt;equalizer_levels_ptr = &amp;equalizer_levels.read[preset_offset];
00161                                         <span class="comment">/*</span>
00162 <span class="comment">                                         * Finally update the equalizer bars</span>
00163 <span class="comment">                                         * that are drawn by the display.</span>
00164 <span class="comment">                                         */</span>
00165                                         <a class="code" href="display_8hcc.html#a4">reload_equalizer</a>(events, equalizer_levels.write, preset_offset);
00166                                 } <span class="keywordflow">else</span> {
00167                                         delay;
00168                                 }
00169 
00170                                 <span class="keywordflow">if</span> ((BUTTON_CONVEX_FULL &lt;= events-&gt;mask) &amp;&amp; (events-&gt;mask &lt;= BUTTON_CONCAVE_FULL)) {
00171                                         events-&gt;equalizer_mode = (events-&gt;mask -BUTTON_CONVEX_FULL) &lt;- 3;
00172                                 } <span class="keywordflow">else</span> {
00173                                         delay;
00174                                 }
00175 
00176                                 <span class="comment">/*</span>
00177 <span class="comment">                                 * If the demo button was pressed load the</span>
00178 <span class="comment">                                 * demo preset values into the presets.</span>
00179 <span class="comment">                                 */</span>
00180                                 <span class="keywordflow">if</span> (BUTTON_DEMO == events-&gt;mask) {
00181                                         <a class="code" href="events_8hcc.html#a2">load_preset</a>(ADDRESS_PRESET_DEMO_START, &amp;equalizer_levels.write[0]);
00182                                         <a class="code" href="display_8hcc.html#a4">reload_equalizer</a>(events, equalizer_levels.write, preset_offset);
00183                                 }
00184 
00185                                 <span class="comment">/*</span>
00186 <span class="comment">                                 * If the reset button was pressed load the</span>
00187 <span class="comment">                                 * reset values into the presets.</span>
00188 <span class="comment">                                 */</span>
00189                                 <span class="keywordflow">if</span> (BUTTON_RESET == events-&gt;mask) {
00190                                         <a class="code" href="events_8hcc.html#a2">load_preset</a>(ADDRESS_PRESET_RESET_START, &amp;equalizer_levels.write[0]);
00191                                         <a class="code" href="display_8hcc.html#a4">reload_equalizer</a>(events, equalizer_levels.write, preset_offset);
00192                                 }
00193 
00194                                 <span class="comment">/*</span>
00195 <span class="comment">                                 * If the current mask equals the log button,</span>
00196 <span class="comment">                                 * we flip the display_log bit.</span>
00197 <span class="comment">                                 */</span>
00198                                 <span class="keywordflow">if</span> (BUTTON_LOG == events-&gt;mask) {
00199                                         audiodata-&gt;display_log = !audiodata-&gt;display_log;
00200                                 } <span class="keywordflow">else</span> {
00201                                         delay;
00202                                 }
00203 
00204                                 <span class="keywordflow">break</span>;
00205 
00206                         <span class="keywordflow">case</span> MOUSE_STATE_DOWN:
00207                                 <span class="comment">/*</span>
00208 <span class="comment">                                 * If we are in the volume area we update the</span>
00209 <span class="comment">                                 * volume level for both channels.</span>
00210 <span class="comment">                                 */</span>
00211                                 <span class="keywordflow">if</span> (AREA_VOLUME_YAXIS == events-&gt;mask) {
00212                                         <span class="comment">/*</span>
00213 <span class="comment">                                         * Copy the current Y cursor position</span>
00214 <span class="comment">                                         * to the events struct. This we then</span>
00215 <span class="comment">                                         * later use for drawing purposes.</span>
00216 <span class="comment">                                         */</span>
00217                                         events-&gt;volume_position = 0 @ mousedata-&gt;y;
00218                                         <span class="comment">/*</span>
00219 <span class="comment">                                         * Look the relative y-coordinate up in</span>
00220 <span class="comment">                                         * the volumecontrol lookup table. We</span>
00221 <span class="comment">                                         * make a local copy here because the</span>
00222 <span class="comment">                                         * RC200 call doesn't behave nicely</span>
00223 <span class="comment">                                         * when passing anything else.</span>
00224 <span class="comment">                                         */</span>
00225                                         volume_left = volumecontrol_table[((mousedata-&gt;y) -65) &lt;- 6];
00226                                         <span class="comment">/*</span>
00227 <span class="comment">                                         * We feel that volume gets softer the</span>
00228 <span class="comment">                                         * closer it gets to the 0, and louder</span>
00229 <span class="comment">                                         * as it approaches 0x1f. The SetVolume</span>
00230 <span class="comment">                                         * RC200 call does this in an unnatural</span>
00231 <span class="comment">                                         * reverse way. Therefor we fix it.</span>
00232 <span class="comment">                                         */</span>
00233                                         RC200AudioOutSetVolume(!volume_left, 0x1f -volume_left, 0x1f -volume_left);
00234                                 } <span class="keywordflow">else</span> {
00235                                         delay;
00236                                 }
00237 
00238                                 <span class="keywordflow">if</span> ((AREA_EQUALIZER_MIN &lt;= events-&gt;mask) &amp;&amp; (events-&gt;mask &lt;= AREA_EQUALIZER_MAX)) {
00239 
00240                                         events-&gt;locked_equalizer = TRUE;
00241                                         delay;
00242                                         reference_point = events-&gt;equalizer_display[(events-&gt;mask -5 -AREA_EQUALIZER_MIN) &lt;- 7];
00243                                         
00244                                         <span class="keywordflow">for</span> (index_offset = 9; index_offset != 0; index_offset--) {
00245                                                 <span class="keywordtype">unsigned</span> 10 average_bar;
00246                                                 <span class="keywordtype">unsigned</span> 7 equalizer_index;
00247                                                 <span class="keywordtype">unsigned</span> 4 bar_index;                                           
00248                                 
00249                                                 <span class="keywordflow">if</span> (index_offset == 5) {
00250                                                         reference_point = events-&gt;equalizer_display[(events-&gt;mask +5 -AREA_EQUALIZER_MIN) &lt;- 7];
00251                                                 } <span class="keywordflow">else</span> {
00252                                                         delay;
00253                                                 }
00254 
00255                                                 <span class="keywordflow">if</span> (index_offset &gt; 5) {
00256                                                         bar_index = (index_offset -5);
00257                                                 } <span class="keywordflow">else</span> {
00258                                                         bar_index = (5 -index_offset);
00259                                                 }
00260 
00261                                                 <span class="keywordflow">if</span> (reference_point &gt; mousedata-&gt;y) {
00262                                                         average_bar = mousedata-&gt;y -((reference_point -mousedata-&gt;y) &gt;&gt; (5 - bar_index));
00263                                                 } <span class="keywordflow">else</span> {
00264                                                         average_bar = mousedata-&gt;y +((mousedata-&gt;y -reference_point) &gt;&gt; (5 - bar_index));
00265                                                 }
00266 
00267                                                 equalizer_index = ((events-&gt;mask +5 -(0 @ index_offset) -AREA_EQUALIZER_MIN) &lt;- 7);
00268 
00269                                                 events-&gt;equalizer_display[equalizer_index] = average_bar;
00270                                                 equalizer_levels.write[preset_offset +(0 @ equalizer_index)] = equalizer_table[average_bar -382];
00271                                         }
00272 
00273                                         events-&gt;locked_equalizer = FALSE;
00274                                 } <span class="keywordflow">else</span> {
00275                                         delay;
00276                                 }
00277 
00278                                 <span class="keywordflow">break</span>;
00279 
00280                         <span class="keywordflow">default</span>:
00281                                 <span class="keywordflow">break</span>;
00282                 }
00283         }
00284 } <span class="comment">/* --- eventhandler_main() --- */</span>
00285 
00286 
00287 
00288 <span class="comment">/*</span>
00289 <span class="comment"> * Volume Control lookuptable.</span>
00290 <span class="comment"> * TODO: This table is now hardcoded. To ensure full skinability this table</span>
00291 <span class="comment"> * should be dynamically loaded.</span>
00292 <span class="comment"> */</span>
00293 rom <span class="keywordtype">unsigned</span> 5 volumecontrol_table[46] = {31, 31, 30, 30, 29, 29, 28, 28, 27, 27, 26, 26, 25, 25, 24,  24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0};
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Nov 29 12:04:47 2004 for Graphic Equalizer by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
</body>
</html>