From df7725f6ceb989a56ef4197d433bc80806f839dd Mon Sep 17 00:00:00 2001 From: Oliver Schinagl Date: Tue, 11 Jan 2005 14:24:30 +0000 Subject: Added special eventhandler loop for the audio input gain events, which are not fired by the user but by the audio component --- Graphic_Equalizer/src/eventhandler.hcc | 547 +++++++++++++++++---------------- 1 file changed, 283 insertions(+), 264 deletions(-) diff --git a/Graphic_Equalizer/src/eventhandler.hcc b/Graphic_Equalizer/src/eventhandler.hcc index 44f9a52..30e1b7d 100644 --- a/Graphic_Equalizer/src/eventhandler.hcc +++ b/Graphic_Equalizer/src/eventhandler.hcc @@ -42,7 +42,7 @@ /* */ extern chan unsigned 1 maskupdate_notification; - +extern chan unsigned 1 event_notification; /*! \fn void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mousedata); @@ -68,7 +68,7 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo unsigned 4 gain_left; unsigned 4 index_offset, index_end; unsigned 4 equalizer_mode_local; - unsigned 1 newmaskupdate; + unsigned 1 newmaskupdate, eventupdate; audiodata->display_log = TRUE; @@ -78,318 +78,336 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo events->button_reset_state = FALSE; events->inputgain_position = skindata->inputgain.bottom -10; - RC200AudioInSetGain(FALSE, 4, 4); + RC200AudioInSetGain(FALSE, 8, 8); events->volume_position = skindata->volume.bottom -30; RC200AudioOutSetVolume(FALSE, 0x1f -24, 0x1f -24); load_preset(LOAD_PRESET_RESET, equalizer_levels.write); reload_equalizer(events, &equalizer_levels.write[preset_offset]); - while (TRUE) { + par { + while (TRUE) { + event_notification ? eventupdate; + + if (audiodata->saturated) { + events->saturated = TRUE; + gain_left--; + events->inputgain_position = inputgain_table_inv[gain_left]; + RC200AudioInSetGain(FALSE, gain_left, gain_left); + } + } + 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 (IMAGE_GRAPH == events->image) { - events->image = IMAGE_SKIN; - events->mask = 0; - } else { - delay; - } - - /* - */ - if (BUTTON_MODE == events->mask) { + 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 (IMAGE_GRAPH == events->image) { events->image = IMAGE_SKIN; + events->mask = 0; } else { - events->image = IMAGE_GRAPH; + delay; } - } else { - delay; - } - - /* - * If the current mask equals the help button - * we set display mode to help. - */ - if ((IMAGE_ABOUT != events->image) && (BUTTON_HELP == events->mask)) { + /* - * Change the mode to help if it's - * currently not set, otherwise go back - * to skin mode. */ - if (IMAGE_HELP == events->image) { - events->image = IMAGE_SKIN; + if (BUTTON_MODE == events->mask) { + if (IMAGE_GRAPH == events->image) { + events->image = IMAGE_SKIN; + } else { + events->image = IMAGE_GRAPH; + } } else { - events->image = IMAGE_HELP; + delay; } - } else { - delay; - } - if ((IMAGE_HELP != events->image) && (BUTTON_ABOUT == events->mask)) { /* - * Change the mode to about if it's - * currently not set, otherwise go back - * to skin mode. + * If the current mask equals the help button + * we set display mode to help. */ - if (IMAGE_ABOUT == events->image) { + if ((IMAGE_ABOUT != events->image) && (BUTTON_HELP == events->mask)) { + /* + * Change the mode to help if it's + * currently not set, otherwise go back + * to skin mode. + */ + if (IMAGE_HELP == events->image) { + events->image = IMAGE_SKIN; + } else { + events->image = IMAGE_HELP; + } + } else { + delay; + } + + if ((IMAGE_HELP != events->image) && (BUTTON_ABOUT == events->mask)) { + /* + * Change the mode to about if it's + * currently not set, otherwise go back + * to skin mode. + */ + if (IMAGE_ABOUT == events->image) { + events->image = IMAGE_SKIN; + } else { + events->image_about = IMAGE_ABOUT_TOP_TASS; + events->image = IMAGE_ABOUT; + } + } else { + delay; + } + + if (BUTTON_EXIT_TO_SKIN == events->mask) { + /* + */ events->image = IMAGE_SKIN; } else { - events->image_about = IMAGE_ABOUT_TOP_TASS; - events->image = IMAGE_ABOUT; + delay; } - } else { - delay; - } - if (BUTTON_EXIT_TO_SKIN == events->mask) { - /* - */ - events->image = IMAGE_SKIN; - } else { - delay; - } - - /* - */ - if ((BUTTON_URL_FONTYS <= events->mask) && (events->mask <= BUTTON_URL_DETAILS)) { - events->image_about = (events->mask -BUTTON_URL_FONTYS) <- 5; -#if HAVE_DEBUG - print_string(" image: ");print_hex_value(0@events->image_about);print_eol(); -#endif - } 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_PRECISE <= events->mask) && (events->mask <= BUTTON_CONVEX_FULL)) { - events->equalizer_mode = (events->mask -BUTTON_PRECISE) <-4; - } else { - delay; - } - - /* - * If the demo button was pressed load the - * demo preset values into the presets. - */ - if (BUTTON_DEMO == events->mask) { - load_preset(LOAD_PRESET_DEMO, equalizer_levels.write); - 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(LOAD_PRESET_RESET, equalizer_levels.write); - 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; - } - - if (BUTTON_DEMO == events->mask) { - events->button_demo_state = TRUE; - } - if (BUTTON_RESET == events->mask) { - events->button_reset_state = TRUE; - } - - 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; + if ((BUTTON_URL_FONTYS <= events->mask) && (events->mask <= BUTTON_URL_DETAILS)) { + events->image_about = (events->mask -BUTTON_URL_FONTYS) <- 5; + #if HAVE_DEBUG + print_string(" image: ");print_hex_value(0@events->image_about);print_eol(); + #endif + } else { + delay; + } + /* - * 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. + * 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. */ - volume_left = volumecontrol_table[((mousedata->y) -skindata->volume.top) <- 6]; + 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_PRECISE <= events->mask) && (events->mask <= BUTTON_CONVEX_FULL)) { + events->equalizer_mode = (events->mask -BUTTON_PRECISE) <-4; + } else { + delay; + } + /* - * 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. + * If the demo button was pressed load the + * demo preset values into the presets. */ - RC200AudioOutSetVolume(!volume_left, 0x1f -volume_left, 0x1f -volume_left); - } else { - delay; - } + if (BUTTON_DEMO == events->mask) { + load_preset(LOAD_PRESET_DEMO, equalizer_levels.write); + reload_equalizer(events, &equalizer_levels.write[preset_offset]); + } - if (AREA_INPUTGAIN_YAXIS == events->mask) { /* - * Copy the current Y cursor position - * to the events struct. This we then - * later use for drawing purposes. + * If the reset button was pressed load the + * reset values into the presets. */ - events->inputgain_position = 0 @ mousedata->y; + if (BUTTON_RESET == events->mask) { + load_preset(LOAD_PRESET_RESET, equalizer_levels.write); + reload_equalizer(events, &equalizer_levels.write[preset_offset]); + } + /* - * Look the relative y-coordinate up in - * the inputgain lookup table. We - * make a local copy here because the - * RC200 call doesn't behave nicely - * when passing anything else. + * If the current mask equals the log button, + * we flip the display_log bit. */ - gain_left = inputgain_table[((mousedata->y) -skindata->inputgain.top) <- 6]; + if (BUTTON_LOG == events->mask) { + audiodata->display_log = !audiodata->display_log; + } else { + delay; + } + + if (BUTTON_DEMO == events->mask) { + events->button_demo_state = TRUE; + } + if (BUTTON_RESET == events->mask) { + events->button_reset_state = TRUE; + } + + break; + + case MOUSE_STATE_DOWN: + /* - * 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. + * If we are in the volume area we update the + * volume level for both channels. */ - RC200AudioInSetGain(!gain_left, gain_left, gain_left); - } else { - delay; - } - - if ((AREA_EQUALIZER_MIN <= events->mask) && (events->mask <= AREA_EQUALIZER_MAX)) { - - if (EQUALIZERMODE_PRECISE == events->equalizer_mode) { - events->locked_display = TRUE; - equalizer_levels.write[preset_offset +(0 @ events->mask) -AREA_EQUALIZER_MIN] = equalizer_table[mousedata->y -382]; - events->equalizer_display[(events->mask -AREA_EQUALIZER_MIN) <- 7] = mousedata->y; - events->locked_display = FALSE; + 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) -skindata->volume.top) <- 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 { - - equalizer_mode_local = events->equalizer_mode +1; + delay; + } - events->locked_display = TRUE; - index_offset = ((equalizer_mode_local << 1)); /* delay; */ + if (AREA_INPUTGAIN_YAXIS == events->mask) { + /* + * We manually update the + * inputgain so we change + * the color of the slider. + */ + events->saturated = FALSE; + /* + * Copy the current Y cursor position + * to the events struct. This we then + * later use for drawing purposes. + */ + events->inputgain_position = 0 @ mousedata->y; + /* + * Look the relative y-coordinate up in + * the inputgain lookup table. We + * make a local copy here because the + * RC200 call doesn't behave nicely + * when passing anything else. + */ + gain_left = inputgain_table[((mousedata->y) -skindata->inputgain.top) <- 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. + */ + RC200AudioInSetGain(!gain_left, gain_left, gain_left); + } else { + delay; + } - if (events->mask < (AREA_EQUALIZER_MIN +(0 @ equalizer_mode_local))) { - reference_point = events->equalizer_display[AREA_EQUALIZER_MIN -AREA_EQUALIZER_MIN]; - index_offset -= (((0 @ equalizer_mode_local) -(events->mask -AREA_EQUALIZER_MIN)) <- 4); - } else { - reference_point = events->equalizer_display[(events->mask - (0 @ equalizer_mode_local) -AREA_EQUALIZER_MIN) <- 7]; - index_offset -= 1; - } + if ((AREA_EQUALIZER_MIN <= events->mask) && (events->mask <= AREA_EQUALIZER_MAX)) { - if (events->mask > (AREA_EQUALIZER_MAX -(0 @ equalizer_mode_local))) { - reference_point_right = events->equalizer_display[AREA_EQUALIZER_MAX -AREA_EQUALIZER_MIN]; - index_end = (((0 @ equalizer_mode_local) -(AREA_EQUALIZER_MAX -events->mask)) <- 4) -1; + if (EQUALIZERMODE_PRECISE == events->equalizer_mode) { + events->locked_display = TRUE; + equalizer_levels.write[preset_offset +(0 @ events->mask) -AREA_EQUALIZER_MIN] = equalizer_table[mousedata->y -382]; + events->equalizer_display[(events->mask -AREA_EQUALIZER_MIN) <- 7] = mousedata->y; + events->locked_display = FALSE; } else { - reference_point_right = events->equalizer_display[(events->mask + (0 @ equalizer_mode_local) -AREA_EQUALIZER_MIN) <- 7]; - index_end = 0; - } - events->locked_display = FALSE; + + equalizer_mode_local = events->equalizer_mode +1; - for (; index_offset != index_end; index_offset--) { - unsigned 10 average_bar; - unsigned 7 equalizer_index; - unsigned 4 bar_index; - - if (index_offset == equalizer_mode_local) { - reference_point = reference_point_right; - } else { - delay; - } + events->locked_display = TRUE; + index_offset = ((equalizer_mode_local << 1)); /* delay; */ - if (index_offset > equalizer_mode_local) - { - bar_index = (index_offset -equalizer_mode_local); - equalizer_index = ((events->mask -(0 @ bar_index) -AREA_EQUALIZER_MIN) <- 7); - } else - { - bar_index = (equalizer_mode_local -index_offset); - equalizer_index = ((events->mask +(0 @ bar_index) -AREA_EQUALIZER_MIN) <- 7); + if (events->mask < (AREA_EQUALIZER_MIN +(0 @ equalizer_mode_local))) { + reference_point = events->equalizer_display[AREA_EQUALIZER_MIN -AREA_EQUALIZER_MIN]; + index_offset -= (((0 @ equalizer_mode_local) -(events->mask -AREA_EQUALIZER_MIN)) <- 4); + } else { + reference_point = events->equalizer_display[(events->mask - (0 @ equalizer_mode_local) -AREA_EQUALIZER_MIN) <- 7]; + index_offset -= 1; } - if (reference_point > mousedata->y) { - average_bar = mousedata->y +((reference_point -mousedata->y) >> (equalizer_mode_local -bar_index)); + if (events->mask > (AREA_EQUALIZER_MAX -(0 @ equalizer_mode_local))) { + reference_point_right = events->equalizer_display[AREA_EQUALIZER_MAX -AREA_EQUALIZER_MIN]; + index_end = (((0 @ equalizer_mode_local) -(AREA_EQUALIZER_MAX -events->mask)) <- 4) -1; } else { - average_bar = mousedata->y -((mousedata->y -reference_point) >> (equalizer_mode_local -bar_index)); + reference_point_right = events->equalizer_display[(events->mask + (0 @ equalizer_mode_local) -AREA_EQUALIZER_MIN) <- 7]; + index_end = 0; } + events->locked_display = FALSE; + + for (; index_offset != index_end; index_offset--) { + unsigned 10 average_bar; + unsigned 7 equalizer_index; + unsigned 4 bar_index; + + if (index_offset == equalizer_mode_local) { + reference_point = reference_point_right; + } else { + delay; + } + + if (index_offset > equalizer_mode_local) + { + bar_index = (index_offset -equalizer_mode_local); + equalizer_index = ((events->mask -(0 @ bar_index) -AREA_EQUALIZER_MIN) <- 7); + } else + { + bar_index = (equalizer_mode_local -index_offset); + equalizer_index = ((events->mask +(0 @ bar_index) -AREA_EQUALIZER_MIN) <- 7); + } + + if (reference_point > mousedata->y) { + average_bar = mousedata->y +((reference_point -mousedata->y) >> (equalizer_mode_local -bar_index)); + } else { + average_bar = mousedata->y -((mousedata->y -reference_point) >> (equalizer_mode_local -bar_index)); + } - events->locked_display = TRUE; - equalizer_levels.write[preset_offset +(0 @ equalizer_index)] = equalizer_table[average_bar -382]; - events->equalizer_display[equalizer_index] = average_bar; - events->locked_display = FALSE; + events->locked_display = TRUE; + equalizer_levels.write[preset_offset +(0 @ equalizer_index)] = equalizer_table[average_bar -382]; + events->equalizer_display[equalizer_index] = average_bar; + events->locked_display = FALSE; + } } + } else { + delay; } - } else { - delay; - } - break; + break; - case MOUSE_STATE_ON_RELEASE: - events->button_demo_state = FALSE; - events->button_reset_state = FALSE; - break; + case MOUSE_STATE_ON_RELEASE: + events->button_demo_state = FALSE; + events->button_reset_state = FALSE; + break; - default: - break; + default: + break; + } } } } /* --- eventhandler_main() --- */ @@ -401,6 +419,7 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo * 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}; +ram 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}; -rom unsigned 4 inputgain_table[46] = {15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0}; +ram unsigned 4 inputgain_table[46] = {15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0}; +ram unsigned 10 inputgain_table_inv[16] = {111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 72, 69, 66}; -- cgit v0.12