Module: Yast::SoundVolumeRoutinesInclude
- Defined in:
- ../../src/include/sound/volume_routines.rb
Instance Method Summary (collapse)
- - (Object) GlobExists(glob)
- - (Object) initialize_sound_volume_routines(include_target)
-
- (String) PlayTest(card_id)
plays test sound to card #card_id.
-
- (Boolean) setVolume(group, cardid, value)
sets volume in percents (0..100) for given card and card_id.
-
- (void) sound_start_tmp(restore)
sound_start_tmp starts alsa using temporary modules.conf.
-
- (void) sound_stop
removes all sound modules from kernel.
-
- (Boolean) stop_programs
stops all programs using sound devices.
-
- (Boolean) storeVolume(card_id)
stores the volume to file.
Instance Method Details
- (Object) GlobExists(glob)
223 224 225 226 227 228 229 230 231 232 233 |
# File '../../src/include/sound/volume_routines.rb', line 223 def GlobExists(glob) out = Convert.to_map( SCR.Execute( path(".target.bash_output"), Builtins.sformat("echo -n %1", glob) ) ) Builtins.y2debug("output: %1", out) Ops.get_string(out, "stdout", "") != glob end |
- (Object) initialize_sound_volume_routines(include_target)
19 20 21 22 23 24 25 26 27 |
# File '../../src/include/sound/volume_routines.rb', line 19 def initialize_sound_volume_routines(include_target) Yast.import "Arch" Yast.import "Sound" Yast.import "Directory" Yast.import "Mode" Yast.import "Popup" textdomain "sound" end |
- (String) PlayTest(card_id)
plays test sound to card #card_id
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File '../../src/include/sound/volume_routines.rb', line 112 def PlayTest(card_id) fname = "/usr/share/sounds/alsa/test.wav" fname = "/usr/share/sounds/test.mp3" if !Sound.use_alsa if SCR.Read(path(".target.size"), fname) == -1 # popup message: test audio file was not found return Builtins.sformat( _("Cannot find file:\n%1\n(test audio file)"), fname ) end command = !Sound.use_alsa ? Builtins.sformat("/usr/bin/mpg123 -a /dev/dsp%1 %2", card_id, fname) : # unset ALSA_CONFIG_PATH (bnc#440981) Builtins.sformat( "ALSA_CONFIG_PATH= /usr/bin/aplay -q -N -D default:%1 %2 > /dev/null 2>&1", card_id, fname ) Builtins.y2milestone("Executing: %1", command) SCR.Execute(path(".target.bash_background"), command) "" end |
- (Boolean) setVolume(group, cardid, value)
sets volume in percents (0..100) for given card and card_id
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File '../../src/include/sound/volume_routines.rb', line 34 def setVolume(group, cardid, value) Builtins.y2debug( "setVolume(group: %1, cardid: %2, value: %3", group, cardid, value ) if !Sound.use_alsa if Arch.sparc cmd = Builtins.sformat( "/usr/bin/aumix -d /dev/mixer%1 -w %2", cardid, value ) SCR.Execute(path(".target.bash"), cmd, {}) else p = Builtins.sformat(".audio.oss.cards.%1.channels.%2", cardid, group) SCR.Write(Builtins.topath(p), value) end return true end # rest is for ALSA # In Mode::autoinst(), we need to update volume_settings from # UpdateCardsToTargetSystem functions; volume will be saved later # in set_vol_settings (). if !Mode.config && !Mode.autoinst p = Builtins.sformat( ".audio.alsa.cards.%1.channels.%2.volume", cardid, group ) return SCR.Write(Builtins.topath(p), value) else tmp = Ops.get(Sound.volume_settings, cardid, []) found = false updated_channels = [] Builtins.foreach(tmp) do |ch| new_ch = deep_copy(ch) if Ops.get_string(new_ch, 0, "") == group Ops.set(new_ch, 1, value) found = true end updated_channels = Builtins.add(updated_channels, new_ch) end if found # the channel has been found, use the updates list tmp = deep_copy(updated_channels) else # the channel has not been found, add it to the list tmp = Builtins.add(tmp, [group, value, false]) end Ops.set(Sound.volume_settings, cardid, tmp) return true end end |
- (void) sound_start_tmp(restore)
This method returns an undefined value.
sound_start_tmp starts alsa using temporary modules.conf
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File '../../src/include/sound/volume_routines.rb', line 143 def sound_start_tmp(restore) ret = true # get the list of commands needed for start cmds = Sound.CreateModprobeCommands Builtins.y2milestone("modprobe commands: %1", cmds) snd = Builtins.sformat( "/sbin/modprobe snd cards_limit=%1 major=116", Builtins.size(Sound.modules_conf) ) if !Sound.use_alsa snd = Builtins.sformat( "/sbin/modprobe snd snd_cards_limit=%1 snd_major=116", Builtins.size(Sound.modules_conf) ) #FIXME parameter names for OSS? end # start 'snd' module first cmds = Builtins.flatten([[snd], cmds]) Builtins.maplist( Convert.convert(cmds, :from => "list", :to => "list <string>") ) do |cmd| res = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd, {})) if Ops.get_string(res, "stderr", "") != "" Builtins.y2error( Ops.add( "/sbin/modprobe error output: \n", Ops.get_string(res, "stderr", "") ) ) ret = false end end ret end |
- (void) sound_stop
This method returns an undefined value.
removes all sound modules from kernel
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File '../../src/include/sound/volume_routines.rb', line 185 def sound_stop if Sound.use_alsa cmd = Ops.add(Directory.bindir, "/alsadrivers unload") Builtins.y2milestone("Executing: %1", cmd) SCR.Execute(path(".target.bash"), cmd) aoa_used = false Builtins.foreach(Sound.modules_conf) do |card| aoa_used = true if Ops.get_string(card, "module", "") == "snd-aoa" end if aoa_used # unload the extra module Builtins.y2milestone("Unloading snd-aoa-i2sbus driver") SCR.Execute(path(".target.bash"), "/sbin/rmmod snd-aoa-i2sbus") SCR.Execute(path(".target.bash"), "/sbin/rmmod snd-aoa-fabric-layout") end else mods = SCR.Dir(path(".modinfo.kernel.sound.oss")) mods = Builtins.add(mods, "emu10k1") mods = Builtins.add(mods, "cs4281") modules = Convert.to_map(SCR.Read(path(".proc.modules"))) Builtins.foreach( Convert.convert(mods, :from => "list", :to => "list <string>") ) do |mod| if Builtins.haskey(modules, mod) SCR.Execute( path(".target.bash"), Builtins.sformat("/sbin/rmmod -r %1", mod) ) end end end nil end |
- (Boolean) stop_programs
stops all programs using sound devices
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File '../../src/include/sound/volume_routines.rb', line 237 def stop_programs return true if Mode.config || Mode.autoinst # list of files to check, * must be present! audio_files = [ "/dev/dsp*", "/dev/audio*", "/dev/mixer*", "/dev/midi*", "/dev/mixer*" ] audio_files = Builtins.filter(audio_files) { |file| GlobExists(file) } Builtins.y2milestone("Checking audio files: %1", audio_files) if Builtins.size(audio_files) == 0 Builtins.y2milestone("No audio device file found, skipping fuser call") return true end = Builtins.mergestring(audio_files, " ") Builtins.y2milestone("fuser options: %1", ) fuser = Convert.to_integer( SCR.Execute( path(".target.bash"), Ops.add("/bin/fuser ", ), {} ) ) if fuser == 0 msg = Ops.get_string(Sound.STRINGS, "WhichDialogMsg", "") terminate = Sound.use_ui ? Popup.YesNo(msg) : true if terminate SCR.Execute( path(".target.bash"), Ops.add("/bin/fuser -k ", ), {} ) else return false end end true end |
- (Boolean) storeVolume(card_id)
stores the volume to file. stored volume will be restored after reboot (ALSA only)
101 102 103 104 105 106 |
# File '../../src/include/sound/volume_routines.rb', line 101 def storeVolume(card_id) SCR.Execute(path(".audio.alsa.store"), 0, 0) if card_id == -1 p = Builtins.sformat(".audio.alsa.cards.%1.store", card_id) Convert.to_boolean(SCR.Execute(Builtins.topath(p), 0, 0)) end |