/*
    This file is part of kenvy24 KDE multimedia utility
    Copyright (c) 2007  Valentin RUSU kenvy24@rusu.info

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License or (at
    your option) version 3 or, at the discretion of KDE e.V. (which shall
    act as a proxy as in section 14 of the GPLv3), any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "mixerpart.h"
#include "ui_mixerpart.h"
#include "partnames.h"
#include "envycard.h"
#include "envystructs.h"
#include "mixerpartchannel.h"

#include <QTimer>
#include <QResizeEvent>
#include <QGroupBox>
#include <QSpacerItem>

#include <kdemacros.h>
#include <kparts/genericfactory.h>
#include <kdebug.h>

K_PLUGIN_FACTORY(MixerPartFactory, registerPlugin<MixerPart>();)  // produce a factory
K_EXPORT_PLUGIN(MixerPartFactory( KENVY24_MIXER_PART ) )

MixerPart::MixerPart( QWidget *parentWidget, QObject *parent, const QVariantList& )
    : KEnvy24Part< Ui_MixerPart>( parentWidget, parent, KENVY24_MIXER_PART),
        envyCard(0),
        updateTimer(0)
{
    setComponentData( MixerPartFactory::componentData() );

    channelMaster = new MixerPartChannel( uiBuilder->grpMaster, 0, this );
    channelMaster->setVuMeters( uiBuilder->vuMasterLeft, uiBuilder->vuMasterRight );
    channelMaster->setVolumes( uiBuilder->volMaster1, uiBuilder->volMaster2, 127 );
    channelMaster->setStereoLinkButton( uiBuilder->stLinkMaster );
    // there is no mute button for the master section
    channelMaster->connect( this, SIGNAL( envyCardChanged(EnvyCard*) ), SLOT( setEnvyCard( EnvyCard*) ) );
    // there is no hide button for this master section

    channelWav1 = new MixerPartChannel( uiBuilder->grpWav1, 0, this );
    channelWav1->setVuMeters( uiBuilder->vuWav1L, uiBuilder->vuWav1R );
    channelWav1->setVolumes( uiBuilder->volWav1L, uiBuilder->volWav1R );
    channelWav1->setStereoLinkButton( uiBuilder->stLinkWav1 );
    channelWav1->setMuteButtons( uiBuilder->muteWav1L, uiBuilder->muteWav1R );
    channelWav1->connect( this, SIGNAL( envyCardChanged(EnvyCard*) ), SLOT( setEnvyCard( EnvyCard*) ) );
    channelWav1->setHideButton( uiBuilder->btnHideWav1 );

    channelWav2 = new MixerPartChannel( uiBuilder->grpWav2, 1, this );
    channelWav2->setVuMeters( uiBuilder->vuWav2L, uiBuilder->vuWav2R );
    channelWav2->setVolumes( uiBuilder->volWav2L, uiBuilder->volWav2R );
    channelWav2->setStereoLinkButton( uiBuilder->stLinkWav2 );
    channelWav2->setMuteButtons( uiBuilder->muteWav2L, uiBuilder->muteWav2R );
    channelWav2->connect( this, SIGNAL( envyCardChanged(EnvyCard*) ), SLOT( setEnvyCard( EnvyCard*) ) );
    channelWav2->setHideButton( uiBuilder->btnHideWav2 );

    channelWav3 = new MixerPartChannel( uiBuilder->grpWav3, 2, this );
    channelWav3->setVuMeters( uiBuilder->vuWav3L, uiBuilder->vuWav3R );
    channelWav3->setVolumes( uiBuilder->volWav3L, uiBuilder->volWav3R );
    channelWav3->setStereoLinkButton( uiBuilder->stLinkWav3 );
    channelWav3->setMuteButtons( uiBuilder->muteWav3L, uiBuilder->muteWav3R );
    channelWav3->connect( this, SIGNAL( envyCardChanged(EnvyCard*) ), SLOT( setEnvyCard( EnvyCard*) ) );
    channelWav3->setHideButton( uiBuilder->btnHideWav3 );

    channelWav4 = new MixerPartChannel( uiBuilder->grpWav4, 3, this );
    channelWav4->setVuMeters( uiBuilder->vuWav4L, uiBuilder->vuWav4R );
    channelWav4->setVolumes( uiBuilder->volWav4L, uiBuilder->volWav4R );
    channelWav4->setStereoLinkButton( uiBuilder->stLinkWav4 );
    channelWav4->setMuteButtons( uiBuilder->muteWav4L, uiBuilder->muteWav4R );
    channelWav4->connect( this, SIGNAL( envyCardChanged(EnvyCard*) ), SLOT( setEnvyCard( EnvyCard*) ) );
    channelWav4->setHideButton( uiBuilder->btnHideWav4 );

    channelCdIn = new MixerPartChannel( uiBuilder->grpCDIn, 0, this );
    channelCdIn->setVuMeters( uiBuilder->vuCdInLeft,  uiBuilder->vuCdInRight );
    channelCdIn->setVolumes( uiBuilder->volCD1, uiBuilder->volCD2 );
    channelCdIn->setStereoLinkButton( uiBuilder->stLinkCd );
    channelCdIn->setMuteButtons( uiBuilder->muteCDL, uiBuilder->muteCDR );
    channelCdIn->setHideButton( uiBuilder->btnHideCdIn );

    channelLineIn = new MixerPartChannel( uiBuilder->grpLineIn, 1, this );
    channelLineIn->setVuMeters( uiBuilder->vuLineInLeft,  uiBuilder->vuLineInRight );
    channelLineIn->setVolumes( uiBuilder->volLineIn1, uiBuilder->volLineIn2 );
    channelLineIn->setStereoLinkButton( uiBuilder->stLinkLineIn );
    channelLineIn->setMuteButtons( uiBuilder->muteLineInL, uiBuilder->muteLineInR );
    channelLineIn->setHideButton( uiBuilder->btnHideLineIn );

    channelMicIn = new MixerPartChannel( uiBuilder->grpMicIn, 2, this );
    channelMicIn->setVuMeters( uiBuilder->vuMicInLeft,  uiBuilder->vuMicInRight );
    channelMicIn->setVolumes( uiBuilder->volMic1, uiBuilder->volMic2 );
    channelMicIn->setStereoLinkButton( uiBuilder->stLinkMic );
    channelMicIn->setMuteButtons( uiBuilder->muteMicL, uiBuilder->muteMicR );
    channelMicIn->setHideButton( uiBuilder->btnHideMicIn );

    channelDigitalIn = new MixerPartChannel( uiBuilder->grpDigitalIn, 2, this );
    channelDigitalIn->setVuMeters( uiBuilder->vuDigitalInL,  uiBuilder->vuDigitalInR );
    channelDigitalIn->setVolumes( uiBuilder->volDigitalInL, uiBuilder->volDigitalInR );
    channelDigitalIn->setStereoLinkButton( uiBuilder->stLinkDigitalIn );
    channelDigitalIn->setMuteButtons( uiBuilder->muteDigitalInL, uiBuilder->muteDigitalInR );
    channelDigitalIn->setHideButton( uiBuilder->btnHideDigitalIn );

}

MixerPart::~MixerPart()
{
    if ( updateTimer )
    {
        updateTimer->stop();
        delete updateTimer, updateTimer = 0;
    }
}

bool MixerPart::saveFile ()
{
    kDebug() << "saveFile()";
    // nothing
    return true;
}

bool MixerPart::openFile ()
{
    kDebug() << "openFile()";
    // nothing
    return true;
}

void MixerPart::setActiveCard( EnvyCard* theCard )
{
    assert( theCard != 0 );
    kDebug() << "setActiveCard " << theCard->getCardName();

    if ( envyCard )
    {
        if (updateTimer)
            updateTimer->stop();
        // disconnect last used card
        disconnectCard();
    }

    if ( updateTimer == 0)
    {
        updateTimer = new QTimer( this );
        connect( updateTimer, SIGNAL( timeout() ), SLOT( updateMeters() ) );

        channelMaster->connect( updateTimer, SIGNAL( timeout() ), SLOT( timerTick() ) );
        channelWav1->connect( updateTimer, SIGNAL( timeout() ), SLOT( timerTick() ) );
        channelCdIn->connect( updateTimer, SIGNAL( timeout() ), SLOT( timerTick() ) );
        channelLineIn->connect( updateTimer, SIGNAL( timeout() ), SLOT( timerTick() ) );
        channelMicIn->connect( updateTimer, SIGNAL( timeout() ), SLOT( timerTick() ) );
    }

    // change the card
    envyCard = theCard;

    // reconfigure user interface
    configureForCard();

    // connect to this card
    connectCard();


    emit envyCardChanged( envyCard );

    // finally, start updating the displays
    envyCard->pulseSignals();
    updateTimer->start( UPDATE_TIMER_INTERVAL );
}

void MixerPart::disconnectCard()
{
    assert( envyCard != 0 );
    switch ( envyCard->getCardDevice() )
    {
        case EnvyCard::ICE1712_SUBDEVICE_DMX6FIRE:
            disconnect( envyCard, 0, channelWav1, 0 );
            disconnect( envyCard, 0, channelMaster, 0 );
            disconnect( envyCard, 0, channelCdIn, 0);
            disconnect( envyCard, 0, channelLineIn, 0);
            disconnect( envyCard, 0, channelMicIn, 0);
            disconnect( channelMaster, 0, envyCard, 0);
            disconnect( channelWav1, 0, envyCard, 0);
            disconnect( channelWav2, 0, envyCard, 0);
            disconnect( channelWav3, 0, envyCard, 0);
            disconnect( channelWav4, 0, envyCard, 0);
            disconnect( channelCdIn, 0, envyCard, 0);
            disconnect( channelLineIn, 0, envyCard, 0 );
            disconnect( channelMicIn, 0, envyCard, 0 );
            disconnect( channelDigitalIn, 0, envyCard, 0);
            disconnect( uiBuilder->lineInSourceCombo, 0, envyCard, 0);
            disconnect( uiBuilder->micInSourceCombo, 0, envyCard, 0);
            break;

        case EnvyCard::ICE1712_SUBDEVICE_AUDIOPHILE:
            disconnect( envyCard, 0, channelWav1, 0 );
            disconnect( envyCard, 0, channelMaster, 0 );
            disconnect( envyCard, 0, channelCdIn, 0);
            disconnect( channelMaster, 0, envyCard, 0);
            disconnect( channelWav1, 0, envyCard, 0);
            disconnect( channelWav2, 0, envyCard, 0);
            disconnect( channelWav3, 0, envyCard, 0);
            disconnect( channelWav4, 0, envyCard, 0);
            disconnect( channelCdIn, 0, envyCard, 0);
            disconnect( channelDigitalIn, 0, envyCard, 0);
            break;

        default:
            kError() << "UNKNOWN CARD DEVICE " << envyCard->getCardDevice();
    }
}

void MixerPart::connectCard()
{
    assert( envyCard != 0 );

    // disable these combos for all cards
    // they are only working on DMX6FIRE
    uiBuilder->lineInSourceCombo->setEnabled(false);
    uiBuilder->micInSourceCombo->setEnabled(false);

    switch ( envyCard->getCardDevice() )
    {
        case EnvyCard::ICE1712_SUBDEVICE_DMX6FIRE:
            // Master Channel connections
            channelMaster->connect( envyCard, SIGNAL( mixerLevelUpdated( const StereoLevels& ) ), SLOT( levelUpdated( const StereoLevels& ) ) );
            channelMaster->connect( envyCard, SIGNAL( analogUpdateDACVolume( int, LeftRight, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int ) ) );
            envyCard->connect( channelMaster, SIGNAL( volumeChange( LeftRight, int) ), SLOT( setDACVolume( LeftRight, int ) ) );

            // PCM1 channel connections
            channelWav1->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav1->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav1->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav1, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav1, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // PCM2 channel connections
            channelWav2->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav2->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav2->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav2, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav2, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // PCM3 channel connections
            channelWav3->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav3->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav3->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav3, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav3, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // CD In channel connctions
            channelCdIn->connect( envyCard, SIGNAL( inputLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelCdIn->connect( envyCard, SIGNAL( mixerUpdateAnalogInVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelCdIn, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerCaptureVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelCdIn, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMuteCaptureChannel( int, LeftRight, bool ) ) );

            // Line In channel connections
            channelLineIn->connect( envyCard, SIGNAL( inputLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelLineIn->connect( envyCard, SIGNAL( mixerUpdateAnalogInVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelLineIn, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerCaptureVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelLineIn, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMuteCaptureChannel( int, LeftRight, bool ) ) );
            envyCard->connect( uiBuilder->lineInSourceCombo, SIGNAL(currentIndexChanged(int)), SLOT( setLineInSource(int)));
            uiBuilder->lineInSourceCombo->setEnabled(true);

            // Mic In Channel Connections
            channelMicIn->connect( envyCard, SIGNAL( inputLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelMicIn->connect( envyCard, SIGNAL( mixerUpdateAnalogInVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelMicIn, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerCaptureVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelMicIn, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMuteCaptureChannel( int, LeftRight, bool ) ) );
            envyCard->connect( uiBuilder->micInSourceCombo, SIGNAL(currentIndexChanged(int)), SLOT(setMicInSource(int)));
            uiBuilder->micInSourceCombo->setEnabled(true);

        case EnvyCard::ICE1712_SUBDEVICE_AUDIOPHILE:
            // Master Channel connections
            channelMaster->connect( envyCard, SIGNAL( mixerLevelUpdated( const StereoLevels& ) ), SLOT( levelUpdated( const StereoLevels& ) ) );
            channelMaster->connect( envyCard, SIGNAL( analogUpdateDACVolume( int, LeftRight, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int ) ) );
            envyCard->connect( channelMaster, SIGNAL( volumeChange( LeftRight, int) ), SLOT( setDACVolume( LeftRight, int ) ) );

            // PCM1 channel connections
            channelWav1->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav1->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav1->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav1, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav1, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // PCM2 channel connections
            channelWav2->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav2->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav2->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav2, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav2, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // PCM3 channel connections
            channelWav3->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav3->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav3->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav3, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav3, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // PCM4 channel connections
            channelWav4->connect( envyCard, SIGNAL( pcmLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelWav4->connect( envyCard, SIGNAL( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            channelWav4->connect( envyCard, SIGNAL( mixerUpdatePCMMuteSwitch( int, LeftRight, bool) ), SLOT( mixerUpdateMuteSwitch(int, LeftRight, bool) ) );
            envyCard->connect( channelWav4, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerPlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelWav4, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMutePlaybackChannel( int, LeftRight, bool ) ) );

            // H/W in channel connctions
            channelCdIn->connect( envyCard, SIGNAL( inputLevelUpdated( int, const StereoLevels& ) ), SLOT( levelUpdated( int, const StereoLevels& ) ) );
            channelCdIn->connect( envyCard, SIGNAL( mixerUpdateAnalogInVolume( int, LeftRight, int, int ) ), SLOT( mixerUpdatePlaybackVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelCdIn, SIGNAL( volumeChange( int, LeftRight, int, int ) ), SLOT( setMixerCaptureVolume( int, LeftRight, int, int ) ) );
            envyCard->connect( channelCdIn, SIGNAL( muteChanged( int, LeftRight, bool) ), SLOT( mixerMuteCaptureChannel( int, LeftRight, bool ) ) );

            break;

        default:
            kError() << "UNKNOWN CARD DEVICE " << envyCard->getCardDevice();
    }
}

void MixerPart::configureForCard()
{
    assert( envyCard != 0 );
    // TODO: load visible state for channels below from the configuration file
    switch ( envyCard->getCardDevice() )
    {
        case EnvyCard::ICE1712_SUBDEVICE_DMX6FIRE:
            channelCdIn->setVisible( true );
            channelCdIn->setTitle( i18n("CD In"));
            uiBuilder->btnHideCdIn->setText( i18n("Cd In") );
            uiBuilder->btnHideCdIn->setVisible(true);
            uiBuilder->btnHideCdIn->setChecked(true);

            channelLineIn->setVisible(true);
            channelLineIn->setTitle( i18n("Line In") );
            uiBuilder->btnHideLineIn->setText( i18n("Line In") );
            uiBuilder->btnHideLineIn->setVisible(true);
            uiBuilder->ledHideLineIn->setVisible(true);
            uiBuilder->btnHideLineIn->setChecked(true);

            channelMicIn->setVisible( true );
            channelMicIn->setTitle( i18n("Phono/Mic In") );
            uiBuilder->btnHideMicIn->setText( i18n("Mic In") );
            uiBuilder->btnHideMicIn->setVisible(true);
            uiBuilder->btnHideMicIn->setChecked(true);
            uiBuilder->ledHideMicIn->setVisible(true);

            channelDigitalIn->setVisible( true );
            uiBuilder->btnHideDigitalIn->setText( i18n("Digital In"));
            uiBuilder->btnHideDigitalIn->setVisible(true);
            uiBuilder->btnHideDigitalIn->setChecked(true);

            channelWav1->setVisible( true );
            channelWav1->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav1->setText( i18n( "Wav 1" ));
            uiBuilder->btnHideWav1->setVisible(true);
            uiBuilder->btnHideWav1->setChecked(true);

            channelWav2->setVisible( true );
            channelWav2->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav2->setText( i18n( "Wav 2" ));
            uiBuilder->btnHideWav2->setVisible(true);
            uiBuilder->btnHideWav2->setChecked(true);

            channelWav3->setVisible( true );
            channelWav3->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav3->setText( i18n( "Wav 3" ));
            uiBuilder->btnHideWav3->setVisible(true);
            uiBuilder->btnHideWav3->setChecked(true);

            channelWav4->setVisible( false );
            channelWav4->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav4->setVisible( false );
            uiBuilder->ledHideWav4->setVisible( false );
            uiBuilder->btnHideWav4->setChecked(false);

            channelMaster->setVisible( true );
            channelMaster->setTitle( i18n("Master") );

            break;

        case EnvyCard::ICE1712_SUBDEVICE_AUDIOPHILE:
            channelCdIn->setVisible( true );
            channelCdIn->setTitle( i18n("H/W In") );
            uiBuilder->btnHideCdIn->setText( i18n("H/W In") );
            uiBuilder->btnHideCdIn->setChecked(true);

            channelLineIn->setVisible( false );
            uiBuilder->btnHideLineIn->setVisible( false );
            uiBuilder->btnHideLineIn->setChecked( false );
            uiBuilder->ledHideLineIn->setVisible( false );

            channelMicIn->setVisible( false );
            uiBuilder->btnHideMicIn->setVisible(false);
            uiBuilder->btnHideMicIn->setChecked(false);
            uiBuilder->ledHideMicIn->setVisible(false);

            channelDigitalIn->setVisible( true );
            uiBuilder->btnHideDigitalIn->setText( i18n( "Digital In"));
            uiBuilder->btnHideDigitalIn->setChecked(true);

            channelWav1->setVisible( true );
            channelWav1->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav1->setText( i18n( "Wav 1" ));
            uiBuilder->btnHideWav1->setChecked(true);

            channelWav2->setVisible( true );
            channelWav2->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav2->setText( i18n( "Wav 2" ));
            uiBuilder->btnHideWav2->setChecked(true);

            channelWav3->setVisible( true );
            channelWav3->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav3->setText( i18n( "Wav 3" ));
            uiBuilder->btnHideWav3->setChecked(true);

            channelWav4->setVisible( true );
            channelWav4->setTitle( i18n("Wave Play") );
            uiBuilder->btnHideWav4->setText( i18n( "Wav 4" ));
            uiBuilder->btnHideWav4->setChecked( true );
            uiBuilder->btnHideWav4->setVisible( true );
            uiBuilder->ledHideWav4->setVisible( true );

            channelMaster->setVisible( true );
            channelMaster->setTitle( i18n("Master") );

            break;

        default:
            kError() << "UNKNOWN CARD DEVICE " << envyCard->getCardDevice();
    }
    // TODO find out how to adjust main window as it has now more or less controls
}

void MixerPart::updateMeters()
{
    assert(envyCard != 0);
    envyCard->updatePeaks();
    channelMaster->levelUpdated( 0, envyCard->getMixerLevels() );
}

void MixerPart::widgetResizeEvent( QResizeEvent* )
{
    channelWav1->parentResizeEvent();
}

void MixerPart::saveConfig( KConfigGroup* config )
{
    kDebug() << "saveConfig()";

    channelWav1->saveConfig( config );
    channelWav2->saveConfig( config );
    channelWav3->saveConfig( config );
    channelWav4->saveConfig( config );
    channelMaster->saveConfig( config );
    channelCdIn->saveConfig( config );
    channelLineIn->saveConfig( config );
    channelMicIn->saveConfig( config );
    channelDigitalIn->saveConfig( config );
}

void MixerPart::loadConfig( KConfigGroup* config )
{
    kDebug() << "loadConfig()";

    channelWav1->loadConfig( config );
    channelWav2->loadConfig( config );
    channelWav3->loadConfig( config );
    channelWav4->loadConfig( config );
    channelMaster->loadConfig( config );
    channelCdIn->loadConfig( config );
    channelLineIn->loadConfig( config );
    channelMicIn->loadConfig( config );
    channelDigitalIn->loadConfig( config );
}

void MixerPart::lineInSourceChanged(int)
{
}

void MixerPart::micInSourceChanged(int)
{
}


#include "mixerpart.moc"
// kate: space-indent on; indent-width 4; replace-tabs on;
