~ubuntu-branches/ubuntu/dapper/kdemultimedia/dapper

« back to all changes in this revision

Viewing changes to kmix/mixer_alsa9.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-01-23 14:26:07 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060123142607-4cj5fiu4gef3wypf
Tags: 4:3.5.1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
 
204
204
        bool canRecord = false;
205
205
        bool canMute = false;
 
206
        bool canCapture = false;
206
207
        long maxVolumePlay= 0, minVolumePlay= 0;
207
208
        long maxVolumeRec = 0, minVolumeRec = 0;
208
209
        validDevice = true;
224
225
 
225
226
                //kdDebug() << "--- Loop: name=" << snd_mixer_selem_id_get_name( sid ) << " , mixerIdx=" << mixerIdx << "------------" << endl;
226
227
 
227
 
            Volume* vol = 0;
 
228
            Volume* volPlay = 0, *volCapture = 0;
228
229
            QPtrList<QString> enumList;
229
230
            if ( snd_mixer_selem_is_enumerated(elem) ) {
230
231
                cc = MixDevice::ENUM;
231
 
                vol = new Volume(); // Dummy, unused
 
232
                volPlay = new Volume(); // Dummy, unused
 
233
                volCapture = new Volume();
232
234
                mixer_elem_list.append( elem );
233
235
                mixer_sid_list.append( sid );
234
236
 
261
263
                                ? Volume::MLEFT : (Volume::ChannelMask)(Volume::MLEFT | Volume::MRIGHT);
262
264
                        chn = (Volume::ChannelMask) (chn | chnTmp);
263
265
                        cc = MixDevice::SLIDER;
 
266
                        volPlay = new Volume( chn, maxVolumePlay, minVolumePlay );
 
267
                } else {
 
268
                        volPlay = new Volume();
264
269
                }
265
 
                else if ( snd_mixer_selem_has_capture_volume(elem) ) {
 
270
                if ( snd_mixer_selem_has_capture_volume(elem) ) {
266
271
                        //kdDebug(67100) << "has_capture_volume()" << endl;
267
272
                        chnTmp = snd_mixer_selem_is_capture_mono( elem )
268
273
                                ? Volume::MLEFT : (Volume::ChannelMask)(Volume::MLEFT | Volume::MRIGHT );
269
274
                        chn = (Volume::ChannelMask) (chn | chnTmp);
270
275
                        cc = MixDevice::SLIDER;
271
 
                        // We can have Playback OR Capture. Not both at same time
272
 
                        // It's not best coding ever, anyway
273
 
                        snd_mixer_selem_get_capture_volume_range( elem, &minVolumePlay, &maxVolumePlay );
 
276
                        canCapture = true;
 
277
                        volCapture = new Volume( chn, maxVolumeRec, minVolumeRec, true );
 
278
                } else {
 
279
                        volCapture = new Volume();
274
280
                }
275
281
 
276
282
                /* Create Volume object. If there is no volume on this device,
277
283
                 * it will be created with maxVolume == 0 && minVolume == 0 */
278
 
                vol = new Volume( chn, maxVolumePlay, minVolumePlay, maxVolumeRec, minVolumeRec );
279
284
                mixer_elem_list.append( elem );
280
285
                mixer_sid_list.append( sid );
281
286
 
301
306
                }
302
307
            } // is ordinary mixer element (NOT an enum)
303
308
 
304
 
                MixDevice* md =
305
 
                    new MixDevice( mixerIdx,
306
 
                                   *vol,
 
309
                MixDevice* md = new MixDevice( mixerIdx,
 
310
                                   *volPlay,
307
311
                                        canRecord,
308
312
                                   canMute,
309
313
                                   snd_mixer_selem_id_get_name( sid ),
310
314
                                   ct,
311
315
                                   cc );
312
 
        if (!masterChosen && ct==MixDevice::VOLUME) {
313
 
           // Determine a nicer MasterVolume
314
 
           m_recommendedMaster = md;
315
 
           masterChosen = true;
316
 
        }
 
316
 
 
317
                        m_mixDevices.append( md );
 
318
 
 
319
 
 
320
                if (!masterChosen && ct==MixDevice::VOLUME) {
 
321
                // Determine a nicer MasterVolume
 
322
                m_recommendedMaster = md;
 
323
                masterChosen = true;
 
324
                }
 
325
 
 
326
                if ( canCapture && !canRecord ) {
 
327
                        MixDevice *mdCapture =
 
328
                        new MixDevice( mixerIdx,
 
329
                                   *volCapture,
 
330
                                        true,
 
331
                                   canMute,
 
332
                                   snd_mixer_selem_id_get_name( sid ),
 
333
                                   ct,
 
334
                                   cc );
 
335
                        m_mixDevices.append( mdCapture );
 
336
                }
317
337
 
318
338
                if ( enumList.count() > 0 ) {
319
339
                  int maxEnumId= enumList.count();
324
344
                    enumValuesRef.append(enumList.at(i) );
325
345
                  }
326
346
                }
327
 
                m_mixDevices.append( md );
328
347
                //kdDebug(67100) << "ALSA create MDW, vol= " << *vol << endl;
329
 
                delete vol;
 
348
                delete volPlay;
 
349
                delete volCapture;
330
350
            } // virginOpen
331
351
            else
332
352
            {
333
 
                MixDevice* md = m_mixDevices.at( mixerIdx );
334
 
                if( !md )
335
 
                {
336
 
                    return Mixer::ERR_INCOMPATIBLESET;
337
 
                }
338
 
                writeVolumeToHW( mixerIdx, md->getVolume() );
 
353
                        MixDevice* md;
 
354
                        bool found = false;
 
355
                for ( md = m_mixDevices.first(); md != 0; md = m_mixDevices.next() ) {
 
356
                                if ( md->num() == mixerIdx ) {
 
357
                                        found = true;
 
358
                                        writeVolumeToHW( mixerIdx, md->getVolume() );
 
359
                                }
 
360
                        }
 
361
                        if( !found )
 
362
                        {
 
363
                                return Mixer::ERR_INCOMPATIBLESET;
 
364
                        }
339
365
            } // !virginOpen
340
366
    } // for all elems
341
367
 
681
707
 
682
708
 
683
709
        // *** READ PLAYBACK VOLUMES *************
684
 
        if ( snd_mixer_selem_has_playback_volume( elem ) )
 
710
        if ( snd_mixer_selem_has_playback_volume( elem ) && !volume.isCapture() )
685
711
        {
686
712
                int ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT, &left );
687
713
                if ( ret != 0 ) kdDebug(67100) << "readVolumeFromHW(" << mixerIdx << ") [has_playback_volume,R] failed, errno=" << ret << endl;
697
723
                }
698
724
        }
699
725
        else
700
 
        if ( snd_mixer_selem_has_capture_volume ( elem ) )
 
726
        if ( snd_mixer_selem_has_capture_volume ( elem ) && volume.isCapture() )
701
727
        {
702
728
            int ret = snd_mixer_selem_get_capture_volume ( elem, SND_MIXER_SCHN_FRONT_LEFT, &left );
703
729
            if ( ret != 0 ) kdDebug(67100) << "readVolumeFromHW(" << mixerIdx << ") [get_capture_volume,L] failed, errno=" << ret << endl;
740
766
        left = volume[ Volume::LEFT ];
741
767
        right = volume[ Volume::RIGHT ];
742
768
 
743
 
        if (snd_mixer_selem_has_playback_volume( elem ) ) {
 
769
        if (snd_mixer_selem_has_playback_volume( elem ) && !volume.isCapture() ) {
744
770
                snd_mixer_selem_set_playback_volume ( elem, SND_MIXER_SCHN_FRONT_LEFT, left );
745
771
                if ( ! snd_mixer_selem_is_playback_mono ( elem ) )
746
772
                        snd_mixer_selem_set_playback_volume ( elem, SND_MIXER_SCHN_FRONT_RIGHT, right );
747
773
        }
748
 
        else if ( snd_mixer_selem_has_capture_volume( elem ) ) {
 
774
        else if ( snd_mixer_selem_has_capture_volume( elem ) && volume.isCapture() ) {
749
775
                snd_mixer_selem_set_capture_volume ( elem, SND_MIXER_SCHN_FRONT_LEFT, left );
750
776
                if ( ! snd_mixer_selem_is_playback_mono ( elem ) )
751
777
                        snd_mixer_selem_set_capture_volume ( elem, SND_MIXER_SCHN_FRONT_RIGHT, right );