/*! \file eventhandler.hcc * * \section generic This modules coordinates all events. Thus for example * when the mousehandler registers a 'click' we coordinate * the actions that follow that click. * * \section project Project information. * Project Graphic Equalizer\n * \author O.M. Schinagl * \date 20041110 * \version 0.1 * * \section copyright Copyright * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved * * \section history Change history * 20041110: O.M. Schinagl\n Initial version * ********************************************************************/ /******** System Includes *************/ #include #include "pal_master.hch" /******** Application Includes ********/ #include "configuration.hch" #include "audio.hch" #include "mouse_shared.hch" #include "eventhandler_shared.hch" #include "eventhandler.hch" #include "events.hch" #include "display_shared.hch" #include "display.hch" #if HAVE_DEBUG #include "debug.hch" #endif /* */ extern chan unsigned 1 maskupdate_notification; static rom unsigned 3 equalizer_mode_table[5] = {EQUALIZERMODE_CONVEX_FULL, EQUALIZERMODE_CONVEX_HALF, EQUALIZERMODE_PRECISE, EQUALIZERMODE_CONCAVE_HALF, EQUALIZERMODE_CONCAVE_FULL}; /*! \fn void eventhandler_main(audiodata_t *audiodata, * events_t *events, mousedata_t *mousedata); * \brief * * \param events_t *events pointer to struct with all events-> * \param mousedata_t *mousedata pointer to struct with mouse data. * * \return Never Returns. * \retval void */ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mousedata) { mpram { ram unsigned 4 write[768]; rom unsigned 4 read[768]; } equalizer_levels with { block = "BlockRAM"}; unsigned 10 preset_offset; unsigned 10 reference_point; unsigned 5 volume_left; unsigned 4 index_offset; unsigned 1 newmaskupdate; /* * Initialize our equalizer display pointers here, as they don't point * anywhere otherwise. */ while (TRUE) { maskupdate_notification ? newmaskupdate; /* * First we determine what mousestate we currently have. Then * we check where we are to decide what to do. */ switch (mousedata->state) { case MOUSE_STATE_ON_PRESS: /* * If we are displaying the graphic visual, * any press returns to the application. */ if (MODE_GRAPH == events->mode) { events->mode = MODE_SKIN; events->mask = 0; } else { delay; } /* */ if (BUTTON_MODE == events->mask) { if (MODE_GRAPH == events->mode) { events->mode = MODE_SKIN; } else { events->mode = MODE_GRAPH; } } else { delay; } /* * If the current mask equals the help button * we set display mode to help. */ if (BUTTON_HELP == events->mask) { /* * Change the mode to help if it's * currently not set, otherwise go back * to skin mode. */ if (MODE_HELP == events->mode) { events->mode = MODE_SKIN; } else { events->mode = MODE_HELP; print_string("going to help");print_eol(); } } else { delay; } /* * The Preset buttons span from 1 to 6 so if * the mask one of those, we'll change the * pointer to point to the current preset. */ if ((BUTTON_PRESET_1 <= events->mask) && (events->mask <= BUTTON_PRESET_6)) { /* * The active preset is determined by * the mask minus an offset. Hence * ranging our active preset from 0 to * 6. */ events->active_preset = 0 @ (events->mask -BUTTON_PRESET_1); /* * Each equalizer is 128 bands wide, * thus we need to add 128 * the preset * for each different preset. This * offset is calculated here. */ preset_offset = events->active_preset << 7; /* * We set the pointer to the active * part of the array by using the * preset offset as our index. Hence * depending on the selected preset * we point to 0, 128, 256, 384, 512 * or 640. */ audiodata->equalizer_levels_ptr = &equalizer_levels.read[preset_offset]; /* * Finally update the equalizer bars * that are drawn by the display. */ reload_equalizer(events, equalizer_levels.write, preset_offset); } else { delay; } if ((BUTTON_CONVEX_FULL <= events->mask) && (events->mask <= BUTTON_CONCAVE_FULL)) { events->equalizer_mode = (events->mask -BUTTON_CONVEX_FULL) <- 3; } else { delay; } /* * If the demo button was pressed load the * demo preset values into the presets. */ if (BUTTON_DEMO == events->mask) { load_preset(ADDRESS_PRESET_DEMO_START, &equalizer_levels.write[0]); reload_equalizer(events, equalizer_levels.write, preset_offset); } /* * If the reset button was pressed load the * reset values into the presets. */ if (BUTTON_RESET == events->mask) { load_preset(ADDRESS_PRESET_RESET_START, &equalizer_levels.write[0]); reload_equalizer(events, equalizer_levels.write, preset_offset); } /* * If the current mask equals the log button, * we flip the display_log bit. */ if (BUTTON_LOG == events->mask) { audiodata->display_log = !audiodata->display_log; } else { delay; } break; case MOUSE_STATE_DOWN: /* * If we are in the volume area we update the * volume level for both channels. */ if (AREA_VOLUME_YAXIS == events->mask) { /* * Copy the current Y cursor position * to the events struct. This we then * later use for drawing purposes. */ events->volume_position = 0 @ mousedata->y; /* * Look the relative y-coordinate up in * the volumecontrol lookup table. We * make a local copy here because the * RC200 call doesn't behave nicely * when passing anything else. */ volume_left = volumecontrol_table[((mousedata->y) -65) <- 6]; /* * We feel that volume gets softer the * closer it gets to the 0, and louder * as it approaches 0x1f. The SetVolume * RC200 call does this in an unnatural * reverse way. Therefor we fix it. */ RC200AudioOutSetVolume(!volume_left, 0x1f -volume_left, 0x1f -volume_left); } else { delay; } if ((AREA_EQUALIZER_MIN <= events->mask) && (events->mask <= AREA_EQUALIZER_MAX)) { events->locked_equalizer = TRUE; delay; reference_point = events->equalizer_display[(events->mask -5 -AREA_EQUALIZER_MIN) <- 7]; for (index_offset = 9; index_offset != 0; index_offset--) { unsigned 10 average_bar; unsigned 7 equalizer_index; unsigned 4 bar_index; if (index_offset == 5) { reference_point = events->equalizer_display[(events->mask +5 -AREA_EQUALIZER_MIN) <- 7]; } else { delay; } if (index_offset > 5) { bar_index = (index_offset -5); } else { bar_index = (5 -index_offset); } if (reference_point > mousedata->y) { average_bar = mousedata->y -((reference_point -mousedata->y) >> (5 - bar_index)); } else { average_bar = mousedata->y +((mousedata->y -reference_point) >> (5 - bar_index)); } equalizer_index = ((events->mask +5 -(0 @ index_offset) -AREA_EQUALIZER_MIN) <- 7); events->equalizer_display[equalizer_index] = average_bar; equalizer_levels.write[preset_offset +(0 @ equalizer_index)] = equalizer_table[average_bar -382]; } events->locked_equalizer = FALSE; } else { delay; } break; default: break; } } } /* --- eventhandler_main() --- */ /* * Volume Control lookuptable. * TODO: This table is now hardcoded. To ensure full skinability this table * should be dynamically loaded. */ 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};