indexing description: "[ Implements a sound visualizer. Use this class to enable the visualizer. Note: This visualizer may boost your CPU. Do not use it when having a lot of other things (like effects or drawing). ]" date: "$Date$" revision: "$Revision$" class MIXER_VISUALIZER inherit MIXER_CONSTANTS export {NONE} all end EM_BUTTON redefine draw_body, next_frame end EM_EFFECT export {NONE} all end create make_positioned feature {NONE} -- Initialization make_positioned (an_x: like x; a_y: like y) is -- Initialize visualizer. do make_from_text (" ") set_position (an_x, a_y) set_dimension (170, 133) set_delegate (create {EM_BASIC_PANEL_DELEGATE}) set_border (create {EM_NO_BORDER}) active := False set_background (create {EM_BITMAP_BACKGROUND}.make_from_file (image_filename)) create buffer.make (0) do_set_change := False clicked_event.subscribe (agent toggle_active) ensure positon_set: x = an_x and y = a_y dimension_set: inner_height = 133 and inner_width = 170 text_set: text.is_equal (" ") not_active: active = False end feature -- Drawing next_frame is -- Draw next frame. do if do_set_change then set_changed do_set_change := False end end draw_body is -- Draw body. local i: INTEGER j: INTEGER x1: INTEGER y1: INTEGER h1: INTEGER h2: INTEGER do if active then from i := 0 j := buffer.count // width x1 := 0 y1 := 0 h1 := height // 2 until i >= buffer.count loop if j = 0 then h2 := h1 + 2 * y1 // height if h2 >= height then h2 := height - 1 end surface.put_line_segment (x1, h1, x1, h2, create {EM_COLOR}.make_with_rgb (190, 236, 187)) h2 := h1 - 2 * y1 // height if h2 < 0 then h2 := 0 end surface.put_line_segment (x1, h1, x1, h2, create {EM_COLOR}.make_with_rgb (190, 236, 187)) j := buffer.count // width y1 := 0 x1 := x1 + 1 end y1 := y1 + buffer.read_integer_8 (i) j := j - 1 i := i + 1 end else Precursor end end feature {NONE} -- Internal buffer buffer: MANAGED_POINTER -- Managed Pointer do_set_change: BOOLEAN -- Set change? feature -- Events on_effect_function (a_channel: INTEGER; a_stream: POINTER; a_length: INTEGER; a_userdata: POINTER) is -- Function called on effect. do create buffer.make_from_pointer (a_stream, a_length) do_set_change := True end on_effect_done (a_channel: INTEGER; a_userdata: POINTER) is -- Function called on effect done. do end feature -- Access active: BOOLEAN -- Is current active-status "active"? image_filename: STRING is -- Name of the image file do create Result.make_from_string (image_directory + "/visualizer.png") end feature -- Implementation toggle_active is -- Switch the active status. do if active then audio_subsystem.mixer.channels.unregister_postmix_effect (current) set_background (create {EM_BITMAP_BACKGROUND}.make_from_file (image_filename)) else set_background (Void) set_transparent audio_subsystem.mixer.channels.register_postmix_effect (current, default_pointer) end active := not active end end