Main Page | Data Structures | Directories | File List | Data Fields | Globals

eventhandler.hcc

Go to the documentation of this file.
00001 
00021 /******** System Includes *************/
00022 #include <stdlib.hch>
00023 
00024 #include "pal_master.hch"
00025 
00026 /******** Application Includes ********/
00027 #include "configuration.hch"
00028 #include "audio.hch"
00029 #include "mouse_shared.hch"
00030 #include "eventhandler_shared.hch"
00031 #include "eventhandler.hch"
00032 #include "events.hch"
00033 #include "display_shared.hch"
00034 #include "display.hch"
00035 
00036 #if HAVE_DEBUG
00037         #include "debug.hch"
00038 #endif
00039 
00040 
00041 
00042 /*
00043  */
00044 extern chan unsigned 1 maskupdate_notification;
00045 
00046 
00047 
00059 void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mousedata) {
00060         mpram {
00061                 ram unsigned 4 write[768];      
00062                 rom unsigned 4 read[768];       
00063         } equalizer_levels with { block = "BlockRAM"};
00064 
00065         unsigned 10 preset_offset;
00066         unsigned 10 reference_point, reference_point_right;
00067         unsigned 5 volume_left;
00068         unsigned 4 index_offset, index_end;
00069         unsigned 4 equalizer_mode_local;
00070         unsigned 1 newmaskupdate;
00071 
00072         load_preset(LOAD_PRESET_RESET, equalizer_levels.write);
00073         reload_equalizer(events, &equalizer_levels.write[preset_offset]);
00074 
00075         while (TRUE) {
00076                 maskupdate_notification ? newmaskupdate;
00077 
00078                 /*
00079                  * First we determine what mousestate we currently have. Then
00080                  * we check where we are to decide what to do.
00081                  */
00082                 switch (mousedata->state) {
00083                         case MOUSE_STATE_ON_PRESS:
00084                                 /*
00085                                  * If we are displaying the graphic visual,
00086                                  * any press returns to the application.
00087                                  */
00088                                 if (MODE_GRAPH == events->mode) {
00089                                         events->mode = MODE_SKIN;
00090                                         events->mask = 0;
00091                                 } else {
00092                                         delay;
00093                                 }
00094 
00095                                 /*
00096                                  */
00097                                 if (BUTTON_MODE == events->mask) {
00098                                         if (MODE_GRAPH == events->mode) {
00099                                                 events->mode = MODE_SKIN;
00100                                         } else {
00101                                                 events->mode = MODE_GRAPH;
00102                                         }
00103                                 } else {
00104                                         delay;
00105                                 }
00106 
00107                                 /*
00108                                  * If the current mask equals the help button
00109                                  * we set display mode to help.
00110                                  */
00111                                 if (BUTTON_HELP == events->mask) {
00112                                         /*
00113                                          * Change the mode to help if it's
00114                                          * currently not set, otherwise go back
00115                                          * to skin mode.
00116                                          */
00117                                         if (MODE_HELP == events->mode) {
00118                                                 events->mode = MODE_SKIN;
00119                                         } else {
00120                                                 events->mode = MODE_HELP;
00121                                         }
00122                                 } else {
00123                                         delay;
00124                                 }
00125 
00126                                 /*
00127                                  * The Preset buttons span from 1 to 6 so if
00128                                  * the mask one of those, we'll change the
00129                                  * pointer to point to the current preset.
00130                                  */
00131                                 if ((BUTTON_PRESET_1 <= events->mask) && (events->mask <= BUTTON_PRESET_6)) {
00132                                         /*
00133                                          * The active preset is determined by
00134                                          * the mask minus an offset. Hence
00135                                          * ranging our active preset from 0 to
00136                                          * 6.
00137                                          */
00138                                         events->active_preset = 0 @ (events->mask -BUTTON_PRESET_1);
00139                                         /*
00140                                          * Each equalizer is 128 bands wide,
00141                                          * thus we need to add 128 * the preset
00142                                          * for each different preset. This
00143                                          * offset is calculated here.
00144                                          */
00145                                         preset_offset = events->active_preset << 7;
00146                                         /*
00147                                          * We set the pointer to the active
00148                                          * part of the array by using the
00149                                          * preset offset as our index. Hence
00150                                          * depending on the selected preset
00151                                          * we point to 0, 128, 256, 384, 512
00152                                          * or 640.
00153                                          */
00154                                         audiodata->equalizer_levels_ptr = &equalizer_levels.read[preset_offset];
00155                                         /*
00156                                          * Finally update the equalizer bars
00157                                          * that are drawn by the display.
00158                                          */
00159                                         reload_equalizer(events, &equalizer_levels.write[preset_offset]);
00160                                 } else {
00161                                         delay;
00162                                 }
00163 
00164                                 if ((BUTTON_PRECISE <= events->mask) && (events->mask <= BUTTON_CONVEX_FULL)) {
00165                                         events->equalizer_mode = (events->mask -BUTTON_PRECISE) <-4;
00166                                 } else {
00167                                         delay;
00168                                 }
00169 
00170                                 /*
00171                                  * If the demo button was pressed load the
00172                                  * demo preset values into the presets.
00173                                  */
00174                                 if (BUTTON_DEMO == events->mask) {
00175                                         load_preset(LOAD_PRESET_DEMO, equalizer_levels.write);
00176                                         reload_equalizer(events, &equalizer_levels.write[preset_offset]);
00177                                 }
00178 
00179                                 /*
00180                                  * If the reset button was pressed load the
00181                                  * reset values into the presets.
00182                                  */
00183                                 if (BUTTON_RESET == events->mask) {
00184                                         load_preset(LOAD_PRESET_RESET, equalizer_levels.write);
00185                                         reload_equalizer(events, &equalizer_levels.write[preset_offset]);
00186                                 }
00187 
00188                                 /*
00189                                  * If the current mask equals the log button,
00190                                  * we flip the display_log bit.
00191                                  */
00192                                 if (BUTTON_LOG == events->mask) {
00193                                         audiodata->display_log = !audiodata->display_log;
00194                                 } else {
00195                                         delay;
00196                                 }
00197 
00198                                 break;
00199 
00200                         case MOUSE_STATE_DOWN:
00201                                 /*
00202                                  * If we are in the volume area we update the
00203                                  * volume level for both channels.
00204                                  */
00205                                 if (AREA_VOLUME_YAXIS == events->mask) {
00206                                         /*
00207                                          * Copy the current Y cursor position
00208                                          * to the events struct. This we then
00209                                          * later use for drawing purposes.
00210                                          */
00211                                         events->volume_position = 0 @ mousedata->y;
00212                                         /*
00213                                          * Look the relative y-coordinate up in
00214                                          * the volumecontrol lookup table. We
00215                                          * make a local copy here because the
00216                                          * RC200 call doesn't behave nicely
00217                                          * when passing anything else.
00218                                          */
00219                                         volume_left = volumecontrol_table[((mousedata->y) -65) <- 6];
00220                                         /*
00221                                          * We feel that volume gets softer the
00222                                          * closer it gets to the 0, and louder
00223                                          * as it approaches 0x1f. The SetVolume
00224                                          * RC200 call does this in an unnatural
00225                                          * reverse way. Therefor we fix it.
00226                                          */
00227                                         RC200AudioOutSetVolume(!volume_left, 0x1f -volume_left, 0x1f -volume_left);
00228                                 } else {
00229                                         delay;
00230                                 }
00231 
00232                                 if ((AREA_EQUALIZER_MIN <= events->mask) && (events->mask <= AREA_EQUALIZER_MAX)) {
00233 
00234                                         if (EQUALIZERMODE_PRECISE == events->equalizer_mode) {
00235                                                 events->locked_display = TRUE;
00236                                                 equalizer_levels.write[preset_offset +(0 @ events->mask) -AREA_EQUALIZER_MIN] = equalizer_table[mousedata->y -382];
00237                                                 events->equalizer_display[(events->mask -AREA_EQUALIZER_MIN) <- 7] = mousedata->y;
00238                                                 events->locked_display = FALSE;
00239                                         } else {
00240                                                 
00241                                                 equalizer_mode_local = events->equalizer_mode +1;
00242 
00243                                                 events->locked_display = TRUE;
00244                                                 index_offset = ((equalizer_mode_local << 1)); /* delay; */
00245 
00246                                                 if (events->mask < (AREA_EQUALIZER_MIN +(0 @ equalizer_mode_local))) {
00247                                                         reference_point = events->equalizer_display[AREA_EQUALIZER_MIN -AREA_EQUALIZER_MIN];
00248                                                         index_offset -= (((0 @ equalizer_mode_local) -(events->mask -AREA_EQUALIZER_MIN)) <- 4);
00249                                                 } else {
00250                                                         reference_point = events->equalizer_display[(events->mask - (0 @ equalizer_mode_local) -AREA_EQUALIZER_MIN) <- 7];
00251                                                         index_offset -= 1;
00252                                                 }
00253 
00254                                                 if (events->mask > (AREA_EQUALIZER_MAX -(0 @ equalizer_mode_local))) {
00255                                                         reference_point_right = events->equalizer_display[AREA_EQUALIZER_MAX -AREA_EQUALIZER_MIN];
00256                                                         index_end = (((0 @ equalizer_mode_local) -(AREA_EQUALIZER_MAX -events->mask)) <- 4) -1;
00257                                                 } else {
00258                                                         reference_point_right = events->equalizer_display[(events->mask + (0 @ equalizer_mode_local) -AREA_EQUALIZER_MIN) <- 7];
00259                                                         index_end = 0;
00260                                                 }
00261                                                 events->locked_display = FALSE;
00262 
00263                                                 for (; index_offset != index_end; index_offset--) {
00264                                                         unsigned 10 average_bar;
00265                                                         unsigned 7 equalizer_index;
00266                                                         unsigned 4 bar_index;
00267                                                         
00268                                                         if (index_offset == equalizer_mode_local) {
00269                                                                 reference_point = reference_point_right;
00270                                                         } else {
00271                                                                 delay;
00272                                                         }
00273 
00274                                                         if (index_offset > equalizer_mode_local) 
00275                                                         {
00276                                                                 bar_index = (index_offset -equalizer_mode_local);                       
00277                                                                 equalizer_index = ((events->mask -(0 @ bar_index) -AREA_EQUALIZER_MIN) <- 7);
00278                                                         } else 
00279                                                         {
00280                                                                 bar_index = (equalizer_mode_local -index_offset);
00281                                                                 equalizer_index = ((events->mask +(0 @ bar_index) -AREA_EQUALIZER_MIN) <- 7);   
00282                                                         }
00283 
00284                                                         if (reference_point > mousedata->y) {
00285                                                                 average_bar = mousedata->y +((reference_point -mousedata->y) >> (equalizer_mode_local -bar_index));
00286                                                         } else {
00287                                                                 average_bar = mousedata->y -((mousedata->y -reference_point) >> (equalizer_mode_local -bar_index));
00288                                                         }
00289                                                                                                         
00290                                                         events->locked_display = TRUE;
00291                                                         equalizer_levels.write[preset_offset +(0 @ equalizer_index)] = equalizer_table[average_bar -382];
00292                                                         events->equalizer_display[equalizer_index] = average_bar;
00293                                                         events->locked_display = FALSE;                                         
00294                                                 }
00295                                         }
00296                                 } else {
00297                                         delay;
00298                                 }
00299 
00300                                 break;
00301 
00302                         default:
00303                                 break;
00304                 }
00305         }
00306 } /* --- eventhandler_main() --- */
00307 
00308 
00309 
00310 /*
00311  * Volume Control lookuptable.
00312  * TODO: This table is now hardcoded. To ensure full skinability this table
00313  * should be dynamically loaded.
00314  */
00315 rom unsigned 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};

Generated on Thu Dec 9 14:37:06 2004 for Graphic Equalizer 2 by  doxygen 1.3.9.1