indexing description: "[ Implements the master part in the mixer. Use this class to create the master. Note: The master need to be active, that you can play any sound or music on a channel. All the commands you give to the master get executed on all active channels. ]" date: "$Date$" revision: "$Revision$" class MIXER_MASTER inherit MIXER_CONSTANTS export {NONE} all end EM_SHARED_AUDIO_FACTORY export {NONE} all end EM_AUDIO_CONSTANTS export {NONE} all end EM_PANEL create make feature {NONE} -- Initialization make is -- Initialize `Current'. do make_void_surface create active.make_with_image_positioned ("active.png", 18, 66) active.clicked_event.subscribe (agent active_button_clicked) add_widget (active) make_settings make_playback make_effects make_panning make_volume end make_settings is -- Create save and load button. do create save.make_with_image_positioned (Void, 18, 127) save.clicked_event.subscribe (agent save_button_clicked) add_widget (save) create load.make_with_image_positioned (Void, 18, 154) load.clicked_event.subscribe (agent load_button_clicked) add_widget (load) end make_playback is -- Create the playback area in the channels. do -- Create play button create play.make_with_image_positioned (Void, 18, 218) play.clicked_event.subscribe (agent play_button_clicked) add_widget (play) -- Create stop button create stop.make_with_image_positioned (Void, 57, 218) stop.clicked_event.subscribe (agent stop_button_clicked) add_widget (stop) -- Create mute button create mute.make_with_image_positioned ("mute.png", 18, 245) mute.clicked_event.subscribe (agent mute_button_clicked) add_widget (mute) -- Create reverse button create reverse.make_with_image_positioned ("reverse.png", 57, 245) reverse.clicked_event.subscribe (agent reverse_button_clicked) add_widget (reverse) -- Create fade button create fade.make_with_image_positioned ("fade.png", 18, 272) fade.clicked_event.subscribe (agent fade_button_clicked) add_widget (fade) -- Create fade_value textbox create fade_value.make_with_text_positioned ("", 57, 272) fade_value.key_down_event.subscribe (agent fade_value_changed) add_widget (fade_value) create old_fade_value.make_empty end make_effects is -- Create effect buttons. do -- Create echo button create echo.make_with_image_positioned ("echo.png", 18, 335) echo.clicked_event.subscribe (agent echo_button_clicked) add_widget (echo) -- Create phasing button create phasing.make_with_image_positioned ("phasing.png", 18, 361) phasing.clicked_event.subscribe (agent phasing_button_clicked) add_widget (phasing) end make_panning is -- Create the panning slider of master. do create panning.make_positioned (16, 424) panning.position_changed_event.subscribe (agent panning_changed) add_widget (panning) panning.disable end make_volume is -- Create the volume slider of master. do create volume.make_positioned (18, 500) volume.position_changed_event.subscribe (agent volume_changed) add_widget (volume) volume.disable end feature -- Access echo: MIXER_BUTTON_LARGE -- Echo button phasing: MIXER_BUTTON_LARGE -- Phasing button save: MIXER_BUTTON_LARGE -- Save button load: MIXER_BUTTON_LARGE -- Load button stop: MIXER_BUTTON_MEDIUM -- Stop button play: MIXER_BUTTON_MEDIUM -- Play button mute: MIXER_BUTTON_MEDIUM -- Mute button reverse: MIXER_BUTTON_MEDIUM -- Reverse button fade: MIXER_BUTTON_MEDIUM -- Fade button fade_value: MIXER_TEXTBOX -- Fade value textbox panning: MIXER_SLIDER_PANNING -- Panning slider volume: MIXER_SLIDER_VOLUME -- Volume slider active: MIXER_BUTTON_LARGE -- Active button music_channel: MIXER_MUSIC_CHANNEL -- Access to music channel channels: ARRAY [MIXER_CHANNEL] -- Access to channels preset: MIXER_PRESET -- Storage place for 'save' feature -- Setters set_music_channel (a_music_channel: like music_channel) is -- Set music channel for the master. require a_music_channel_not_void: a_music_channel /= void do music_channel := a_music_channel end set_channels (some_channels: like channels) is -- Set channels for the master. require some_channels_not_void: some_channels /= Void do channels := some_channels end feature -- Event active_button_clicked is -- Event for active button. -- With a non-active master you can't change anything or play anything on a channel. local i: INTEGER do active.toggle_active if active.active then if music_channel.track /= Void then music_channel.track.set_volume (music_channel.volume.current_volume) end from i := 1 until i > 6 loop if channels.item (i).channel /= Void then channels.item (i).channel.set_volume (volume.current_volume) end i := i + 1 end fade_value.set_text ("1000") panning.enable volume.enable create old_fade_value.make_from_string (fade_value.text) else from i := 1 until i > 6 loop if channels.item (i).channel /= Void then channels.item (i).channel.set_volume (0) end i := i + 1 end if music_channel.track /= Void then music_channel.track.set_volume (0) end fade_value.set_text ("") if mute.active then mute.toggle_active end if reverse.active then reverse.toggle_active end if fade.active then fade.toggle_active end if echo.active then echo.toggle_active end if phasing.active then phasing.toggle_active end volume.set_current_value (Em_max_volume) panning.set_current_value (0) panning.disable volume.disable from i := 1 until i > 6 loop if channels.item (i).channel /= Void then channels.item (i).channel.set_volume (0) end i := i + 1 end fade_value.set_text ("") end ensure active_changed: active.active = not old active.active end save_button_clicked is -- Event for save button. -- Save current settings on all channels and on the master. do if active.active then create preset.make_with_save (current) end end load_button_clicked is -- Event for load button. -- Load last saved settings of all the channels and off the master. do if active.active then if preset /= Void then preset.load end end end play_button_clicked is -- Event for the play button. -- Plays on all active channels or pause/resume them. local i: INTEGER do if active.active and music_channel.track /= Void then if music_channel.active.active then if music_channel.track.is_playing and then not music_channel.track.is_paused and then music_channel.playing_id = music_channel.listbox.selected_index then music_channel.track.pause else if music_channel.playing_id = music_channel.listbox.selected_index then music_channel.track.resume else if music_channel.listbox.selected_index = 0 then music_channel.listbox.set_selected_index (1) end audio_factory.create_music_from_file (music_directory + "/" + music_channel.listbox.selected_element) music_channel.set_track (audio_factory.last_music) music_channel.track.set_volume ((music_channel.volume.current_volume * (volume.current_volume / Em_max_volume)).rounded) if fade.active then music_channel.listbox.redraw music_channel.track.fade_in (-1, fade_value.text.to_integer) else music_channel.track.play (1) end music_channel.set_playing_id (music_channel.listbox.selected_index) end end end from i := 1 until i > 6 loop if (is_playing and channels.item (i).channel.is_playing and not channels.item (i).channel.is_paused) or (not is_playing and (not channels.item (i).channel.is_playing or channels.item (i).channel.is_paused)) then if channels.item (i).active.active then if channels.item (i).channel.is_playing and not channels.item (i).channel.is_paused then channels.item (i).channel.pause else if channels.item (i).channel.is_paused then channels.item (i).channel.resume else if channels.item (i).combobox.selected_element /= Void then audio_factory.create_sound_from_file (sound_directory + "/" + channels.item (i).combobox.selected_element) channels.item (i).set_track (audio_factory.last_sound) channels.item (i).track.set_volume (channels.item (i).volume.current_volume) channels.item (i).channel.set_volume (volume.current_volume) if fade.active then channels.item (i).channel.fade_in_timed (channels.item (i).track, -1, fade_value.text.to_integer, -1) else channels.item (i).channel.play (channels.item (i).track, -1) end end end end end end i := i + 1 end from until not music_channel.track.is_fading_in and then not channels.item (1).channel.is_fading_in and then not channels.item (2).channel.is_fading_in and then not channels.item (3).channel.is_fading_in and then not channels.item (4).channel.is_fading_in and then not channels.item (5).channel.is_fading_in and then not channels.item (6).channel.is_fading_in loop end is_playing := not is_playing end end stop_button_clicked is -- Event for stop button. -- Stops all active playing channels. local i: INTEGER do if music_channel.active.active then if music_channel.track /= Void and then music_channel.track.is_playing then music_channel.set_stop_pressed (True) if fade.active then music_channel.track.fade_out (fade_value.text.to_integer) else music_channel.track.stop end end music_channel.set_playing_id (-1) end from i := 1 until i > 6 loop if channels.item (i).active.active then if channels.item (i).channel.is_playing then if fade.active then channels.item (i).channel.fade_out (fade_value.text.to_integer) else channels.item (i).channel.stop end end end i := i + 1 end from until not music_channel.track.is_fading_out and then not channels.item (1).channel.is_fading_out and then not channels.item (2).channel.is_fading_out and then not channels.item (3).channel.is_fading_out and then not channels.item (4).channel.is_fading_out and then not channels.item (5).channel.is_fading_out and then not channels.item (6).channel.is_fading_out loop end is_playing := False end mute_button_clicked is -- Event for mute button. -- Mute or unmute all active channels. local i: INTEGER do if active.active then mute.toggle_active if mute.active then if music_channel.track /= Void then music_channel.track.set_volume (0) end from i := 1 until i > 6 loop channels.item (i).channel.set_volume (0) i := i + 1 end else if music_channel.track /= Void and then not music_channel.mute.active then music_channel.track.set_volume (music_channel.volume.current_volume) end from i := 1 until i > 6 loop channels.item (i).channel.set_volume (volume.current_volume) i := i + 1 end end end end reverse_button_clicked is -- Event for reverse button. -- Reverse on all active channels. local i: INTEGER do if active.active then reverse.toggle_active if reverse.active then from i := 1 until i > 6 loop if not channels.item (i).reverse.active then channels.item (i).channel.toggle_reverse_stereo end i := i + 1 end else from i := 1 until i > 6 loop if not channels.item (i).reverse.active then channels.item (i).channel.toggle_reverse_stereo end i := i + 1 end end end end fade_button_clicked is -- Event for fade button. -- If fade is activatet, the fade effect is used in play and stop with current fade_value. do if active.active then fade.toggle_active end end fade_value_changed (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Event for fade value changed. -- Sets the value for the fade effect. do if active.active and then fade_value.text.is_integer then create old_fade_value.make_from_string (fade_value.text) elseif fade_value.text.is_empty then fade_value.set_text ("0") else fade_value.set_text (create {STRING}.make_from_string (old_fade_value)) end end echo_button_clicked is -- Event for the echo button. -- If echo is active, an echo effect will register to all active channels. do if active.active then echo.toggle_active if echo.active then audio_subsystem.mixer.channels.register_postmix_effect (channels.item (1).echo_effect, default_pointer) else audio_subsystem.mixer.channels.unregister_postmix_effect (channels.item (1).echo_effect) end end end phasing_button_clicked is -- Event for phasing button. -- If phasing is active, a phasing effect will register to all active channels. do if active.active then phasing.toggle_active if phasing.active then audio_subsystem.mixer.channels.register_postmix_effect (channels.item (1).phasing_effect, default_pointer) else audio_subsystem.mixer.channels.unregister_postmix_effect (channels.item (1).phasing_effect) end end end panning_changed (a_panning: INTEGER) is -- Event if panning's changed. -- Updates the panning slider and the panning value. -- `a_panning': is the current panning value given from the subscribe event. require a_panning_is_valid: a_panning <= 255 and a_panning >= -255 local i: INTEGER do panning.update_lights if active.active then from i := 1 until i > 6 loop channels.item (i).panning_changed (channels.item (i).panning.current_value) i := i + 1 end end end volume_changed (a_volume: INTEGER) is -- Event if volume's changed. -- Updates the volume slider and the volume value. -- `a_volume': is the current volume value given by the subscribe event. require a_volume_is_valid: a_volume <= 255 and a_volume >= 0 local i: INTEGER do volume.update_lights if active.active then if music_channel.track /= Void then music_channel.track.set_volume ((music_channel.volume.current_volume * (volume.current_volume / Em_max_volume)).rounded) end from i := 1 until i > 6 loop if channels.item (i).channel /= Void then channels.item (i).channel.set_volume (volume.current_volume) end i := i + 1 end end end feature {NONE} -- Internal variables old_fade_value: STRING -- Old fade value is_playing: BOOLEAN -- Is master playing? end