Module: Yast::SoundMixerInclude

Defined in:
../../src/include/sound/mixer.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) initialize_sound_mixer(include_target)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File '../../src/include/sound/mixer.rb', line 20

def initialize_sound_mixer(include_target)
  Yast.import "UI"
  textdomain "sound"
  Yast.import "Wizard"
  Yast.import "Sound"
  Yast.import "Label"

  Yast.include include_target, "sound/ui.rb"
  Yast.include include_target, "sound/volume_routines.rb"

  # translation map of channel names
  @channel_trans = {
    # channel name - label for IntField widget in mixer dialog
    "Master"        => _(
      "Master"
    ),
    # channel name - label for IntField widget in mixer dialog
    "PCM"           => _(
      "PCM"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Master Mono"   => _(
      "Master Mono"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Headphone"     => _(
      "Headphone"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Line"          => _(
      "Line"
    ),
    # channel name - label for IntField widget in mixer dialog
    "CD"            => _(
      "CD"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Mic"           => _(
      "Mic"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Video"         => _(
      "Video"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Phone"         => _(
      "Phone"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Aux"           => _(
      "Aux"
    ),
    # channel name - label for IntField widget in mixer dialog
    "PC Speaker"    => _(
      "PC Speaker"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Bass"          => _(
      "Bass"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Treble"        => _(
      "Treble"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Surround"      => _(
      "Surround"
    ),
    # channel name - label for IntField widget in mixer dialog
    "LFE"           => _(
      "LFE"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Center"        => _(
      "Center"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Wave"          => _(
      "Wave"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Wave Center"   => _(
      "Wave Center"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Wave Surround" => _(
      "Wave Surround"
    ),
    # channel name - label for IntField widget in mixer dialog
    "AC97"          => _(
      "AC97"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Music"         => _(
      "Music"
    ),
    # channel name - label for IntField widget in mixer dialog
    "Front"         => _(
      "Front"
    ),
    # channel name - label for IntField widget in mixer dialog
    "iSpeaker"      => _(
      "iSpeaker"
    )
  }
end

- (Hash) mixerDialog(card_id)

shows mixer dialog for respective card

Parameters:

  • card_id (Fixnum)

    card id

Returns:

  • (Hash)

    result



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File '../../src/include/sound/mixer.rb', line 267

def mixerDialog(card_id)
  Sound.LoadDatabase(true)

  pth = Builtins.topath(
    Builtins.sformat(".audio.alsa.cards.%1.channels", card_id)
  )
  channels = []
  modname = ""
  # card name
  model = Ops.get_locale(
    Sound.modules_conf,
    [card_id, "model"],
    _("Unknown")
  )

  if Sound.use_alsa
    modname = Ops.get_string(
      Sound.modules_conf,
      [card_id, "module"],
      "snd-dummy"
    )
    channels = Convert.convert(
      Ops.get(Sound.db_modules, [modname, "mixer_elements"], SCR.Dir(pth)),
      :from => "any",
      :to   => "list <string>"
    )
  else
    channels = ["Master"]
  end

  muted = []

  pth = Builtins.topath(
    Builtins.sformat(".audio.alsa.cards.%1.name", card_id)
  )
  card_name = Sound.use_alsa ?
    Convert.to_string(SCR.Read(pth)) :
    Builtins.sformat("%1", card_id)

  # get list of muted channels
  if Sound.use_alsa
    Builtins.foreach(
      Convert.convert(channels, :from => "list", :to => "list <string>")
    ) do |channel|
      pth2 = Builtins.topath(
        Builtins.sformat(
          ".audio.alsa.cards.%1.channels.%2.mute",
          card_id,
          channel
        )
      )
      if Convert.to_boolean(SCR.Read(pth2))
        muted = Builtins.add(muted, channel)
      end
    end

    Builtins.y2debug("muted: %1", muted)

    # put 'Master', 'PCM' to list head
    if Builtins.contains(channels, "PCM")
      channels = Builtins.filter(
        Convert.convert(channels, :from => "list", :to => "list <string>")
      ) { |ch| ch != "PCM" }
      channels = Builtins.prepend(channels, "PCM")
    end

    master_channel = Ops.get_string(
      Sound.db_modules,
      [modname, "main_volume"],
      "Master"
    )

    if modname != "" && Builtins.contains(channels, master_channel)
      channels = Builtins.filter(
        Convert.convert(channels, :from => "list", :to => "list <string>")
      ) { |ch| ch != master_channel }
      channels = Builtins.prepend(channels, master_channel)
    end
    channels = Builtins.maplist(
      Convert.convert(channels, :from => "list", :to => "list <string>")
    ) do |ch|
      if Builtins.contains(muted, ch)
        next [ch, 0]
      else
        next [
          ch,
          SCR.Read(
            Builtins.topath(
              Builtins.sformat(
                ".audio.alsa.cards.%1.channels.%2.volume",
                card_id,
                ch
              )
            )
          )
        ]
      end
    end
  else
    vol = Convert.to_integer(
      SCR.Read(
        Builtins.topath(
          Builtins.sformat(".audio.oss.cards.%1.channels.Master", card_id)
        )
      )
    )
    channels = [["Master", vol]]
  end

  # help text - mixer setting
  help = _(
    "<P>With this dialog you can set volume for each channel of the selected sound card. \nPress <B>Next</B> to save your volume settings, press <B>Back</B> to restore the original settings.</P>"
  )

  con = mixerWidget(channels)

  # dialog header, %1 = card id (number), %2 = name
  Wizard.SetContentsButtons(
    Builtins.sformat(_("Volume Settings for Card %1 - %2"), card_id, model),
    con,
    help,
    Label.BackButton,
    Label.OKButton
  )

  ui = nil # value can be `next `abort... or string (channel name)

  UI.ChangeWidget(Id(:test), :Enabled, !Mode.config)
  begin
    ui = UI.UserInput

    if Ops.is_string?(ui)
      # unmute if neccessary
      if Builtins.contains(muted, ui)
        SCR.Write(
          Builtins.topath(
            Builtins.sformat(
              ".audio.alsa.cards.%1.channels.%2.mute",
              card_id,
              ui
            )
          ),
          false
        )
      end
      # set volume
      if Sound.use_alsa
        setVolume(
          Convert.to_string(ui),
          card_id,
          Convert.to_integer(UI.QueryWidget(Id(ui), :Value))
        )
      else
        setVolume(
          "Master",
          card_id,
          Convert.to_integer(UI.QueryWidget(Id(ui), :Value))
        )
      end
    elsif ui == :test
      PlayTest(card_id)
    elsif (ui == :abort || ui == :cancel) && ReallyAbort()
      return { "ui" => :abort }
    end
  end until ui == :back || ui == :next

  if ui == :next
    # store volume settings
    pth2 = Builtins.topath(
      Builtins.sformat(".audio.alsa.cards.%1.store", card_id)
    )
    SCR.Execute(pth2, 0, 0)
  else
    # restore volume settings
    pth2 = Builtins.topath(
      Builtins.sformat(".audio.alsa.cards.%1.restore", card_id)
    )
    SCR.Execute(pth2, 0, 0)
  end

  { "ui" => ui }
end

- (Yast::Term) mixerWidget(channels)

creates a mixer widget with channels obtained from 1st param

Parameters:

  • channels (Array)

    channels to be shown

Returns:

  • (Yast::Term)

    widget



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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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
# File '../../src/include/sound/mixer.rb', line 185

def mixerWidget(channels)
  channels = deep_copy(channels)
  widget = VBox()
  spec = UI.HasSpecialWidget(:Slider)
  nchan = Ops.subtract(Builtins.size(channels), 2) # don't count in 'Master' and 'PCM'
  ncols = 4

  # how many channels per column
  chansPerCol = Builtins.tointeger(
    Ops.add(
      Ops.divide(Builtins.tofloat(nchan), Builtins.tofloat(ncols)),
      0.999
    )
  )

  # 1. group first two elements to one Frame
  ttmp = nil
  if spec
    ttmp = VBox()
  else
    ttmp = HBox()
  end
  pos = 0
  while Ops.less_than(pos, 2) && Ops.less_than(pos, Builtins.size(channels))
    lab = Ops.get_string(channels, [pos, 0], "")
    vol = Ops.get_integer(channels, [pos, 1], 0)
    ttmp = Builtins.add(ttmp, volElement(lab, vol, spec))
    pos = Ops.add(pos, 1)
  end

  ttmp = Builtins.add(ttmp, VSpacing(1))

  # frame label
  mainGroup = Frame(
    _("&Master volume"),
    HBox(
      HSpacing(3),
      ttmp,
      HSpacing(3),
      VBox(
        # push button label
        PushButton(Id(:test), Opt(:key_F6), _("&Test"))
      )
    )
  )

  # 2. now group elements to columns

  counter = 0
  col = HBox(HSpacing(2))

  while Ops.less_than(pos, Builtins.size(channels))
    if ncols == counter
      widget = Builtins.add(widget, Top(col))
      widget = Builtins.add(widget, HStretch()) if !spec
      col = HBox(HSpacing(2))
      counter = 0
    end

    lab = Ops.get_string(channels, [pos, 0], "")
    vol = Ops.get_integer(channels, [pos, 1], 0)

    col = Builtins.add(col, HWeight(1, volElement(lab, vol, false)))
    col = Builtins.add(col, HSpacing(2))
    pos = Ops.add(pos, 1)
    counter = Ops.add(counter, 1)
  end

  while Ops.less_than(counter, ncols)
    col = Builtins.add(col, HWeight(1, Label(" ")))
    col = Builtins.add(col, HSpacing(2))
    counter = Ops.add(counter, 1)
  end
  widget = Builtins.add(widget, Top(col))

  # frame label
  VBox(mainGroup, Frame(_("&Other channels"), widget))
end

- (String) translateChannelName(name)

Translate channel name

Parameters:

  • name (String)

    untranslated channel name

Returns:

  • (String)

    translated name



130
131
132
133
134
135
136
137
# File '../../src/include/sound/mixer.rb', line 130

def translateChannelName(name)
  return "" if name == nil || name == ""

  ret = Ops.get_string(@channel_trans, name, name)
  Builtins.y2debug("translated channel name: %1", ret)

  ret
end

- (Yast::Term) volElement(channel_id, value, spec)

returns intfield (if we are running in ncurses) or slider (for qt)

Parameters:

  • label

    label for slider

  • value (Fixnum)

    initial value

  • spec (Boolean)

    true-slider false-intfield

Returns:

  • (Yast::Term)

    widget



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
# File '../../src/include/sound/mixer.rb', line 145

def volElement(channel_id, value, spec)
  label = channel_id

  # remove the index from the channel ID if it's there
  if Builtins.regexpmatch(channel_id, "^.*_#[0-9]+\#$")
    label = Builtins.regexpsub(channel_id, "^(.*)_#[0-9]+\#$", "\\1")
    index_str = Builtins.regexpsub(channel_id, "^.*_#([0-9]+)\#$", "\\1")
    index = Builtins.tointeger(index_str)

    if index != nil
      # add index + 1 to the channel label
      # so there are channels "Speaker", "Speaker 2", "Speaker 3", ...
      label = Builtins.sformat("%1 %2", label, Ops.add(index, 1))
    end
  end

  if UI.HasSpecialWidget(:Slider)
    return Slider(
      Id(channel_id),
      Opt(:notify),
      translateChannelName(label),
      0,
      100,
      value
    )
  else
    return IntField(
      Id(channel_id),
      Opt(:notify),
      translateChannelName(label),
      0,
      100,
      value
    )
  end
end