summaryrefslogtreecommitdiffstats
path: root/kmix/viewsurround.cpp
blob: 27cc1635f1e62ed8a40b0803d68d63ca54a91727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
182
183
184
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
263
264
265
266
267
268
269
270
/*
 * KMix -- KDE's full featured mini mixer
 *
 *
 * Copyright (C) 1996-2004 Christian Esken <[email protected]>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "viewsurround.h"

// TQt
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqwidget.h>

// KDE
#include <kdebug.h>
#include <kiconloader.h>

// KMix
#include "kmixtoolbox.h"
#include "mdwslider.h"
#include "mixer.h"

/**
 * Demonstration verion of a "surround view"
 * Not really usable right now.
 */
ViewSurround::ViewSurround(TQWidget* parent, const char* name, const TQString & caption, Mixer* mixer, ViewBase::ViewFlags vflags)
      : ViewBase(parent, name, caption, mixer, WStyle_Customize|WStyle_NoBorder, vflags)
{
    _mdSurroundFront = 0;
    _mdSurroundBack  = 0;
    _layoutMDW = new TQHBoxLayout(this);
    _layoutMDW->setMargin(8);
    // Create switch buttonGroup
    if ( _vflags & ViewBase::Vertical ) {
        _layoutSliders = new TQVBoxLayout(_layoutMDW);
    }
    else {
        _layoutSliders = new TQHBoxLayout(_layoutMDW);
    }
    _layoutSurround = new TQGridLayout(_layoutMDW,3,5);
    //    _layoutMDW->setMargin(8);
    init();
}

ViewSurround::~ViewSurround() {
}

void ViewSurround::setMixSet(MixSet *mixset)
{
    MixDevice* md;
    for ( md = mixset->first(); md != 0; md = mixset->next() ) {
	if ( ! md->isSwitch() ) {
	    switch ( md->type() ) {
	    case MixDevice::VOLUME:
	    case MixDevice::SURROUND:
	    case MixDevice::SURROUND_BACK:
	    case MixDevice::SURROUND_LFE:
	    case MixDevice::SURROUND_CENTERFRONT:
	    case MixDevice::SURROUND_CENTERBACK:
	    case MixDevice::AC97:
		_mixSet->append(md);
		break;
	    default:
		// we are not interested in other channels
		break;
	    } // switch(type)
	} // !is_switch()
    } // for
}

int ViewSurround::count()
{
    return ( _mixSet->count() );	
}

int ViewSurround::advice() {
    if (  _mixSet->count() > 0 ) {
        // The standard input and output views are always advised, if there are devices in it
        return 100;
    }
    else {
        return 0;
    }
}

TQWidget* ViewSurround::add(MixDevice *md)
{
    bool small = false;
    Qt::Orientation orientation = Qt::Vertical;
    switch ( md->type() ) {
    case MixDevice::VOLUME:
	_mdSurroundFront = md;
	small = true;
	break;	
    case MixDevice::SURROUND_BACK:
	_mdSurroundBack = md;
	small = true;
	break;
    case MixDevice::SURROUND_LFE:
	orientation = Qt::Horizontal;
	small = true;
	break;
    case MixDevice::SURROUND_CENTERFRONT:
	orientation = Qt::Horizontal;
	small = true;
	break;
    case MixDevice::SURROUND_CENTERBACK:
	orientation = Qt::Horizontal;
	small = true;
	break;
	
    default:
	small       = false;
	// these are the sliders on the left side of the surround View
	orientation = (_vflags & ViewBase::Vertical) ? Qt::Horizontal : Qt::Vertical;
    } // switch(type)

    MixDeviceWidget *mdw = createMDW(md, small, orientation);

    switch ( md->type() ) {
    case MixDevice::VOLUME:
	_layoutSurround->addWidget(mdw ,0,0, TQt::AlignBottom | TQt::AlignLeft);
	break;
	
    case MixDevice::SURROUND_BACK:
	_layoutSurround->addWidget(mdw ,2,0, TQt::AlignTop | TQt::AlignLeft);
	break;
    case MixDevice::SURROUND_LFE:
	_layoutSurround->addWidget(mdw,1,3,  TQt::AlignVCenter | TQt::AlignRight ); break;
	break;
    case MixDevice::SURROUND_CENTERFRONT:
	_layoutSurround->addWidget(mdw,0,2,  TQt::AlignTop | TQt::AlignHCenter); break;
	break;
    case MixDevice::SURROUND_CENTERBACK:
	_layoutSurround->addWidget(mdw,2,2,  TQt::AlignBottom | TQt::AlignHCenter); break;
	break;

    case MixDevice::SURROUND:
    case MixDevice::AC97:
    default:
	// Add as slider to the layout on the left side
	_layoutSliders->add(mdw);
	break;
    } // switch(type)

    return mdw;
}

TQSize ViewSurround::sizeHint() const {
    //    kdDebug(67100) << "ViewSurround::sizeHint(): NewSize is " << _layoutMDW->sizeHint() << "\n";
    return( _layoutMDW->sizeHint() );
}

void ViewSurround::constructionFinished() {
    TQLabel* personLabel = new TQLabel("Listener", this);
    TQPixmap icon = UserIcon( "Listener" );
    if ( ! icon.isNull()) personLabel->setPixmap(icon);
    personLabel->setLineWidth( 4 );
    personLabel->setMidLineWidth( 3 );
    personLabel->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
    int rowOfSpeaker = 0;
    if ( _mdSurroundBack != 0 ) {
       // let the speaker "sit" in the rear of the room, if there is
       // rear speaker support in this sound card
       rowOfSpeaker = 1;
    }
    _layoutSurround->addWidget(personLabel ,rowOfSpeaker, 2, TQt::AlignHCenter | TQt::AlignVCenter);

    if ( _mdSurroundFront != 0 ) {
	MixDeviceWidget *mdw = createMDW(_mdSurroundFront, true, Qt::Vertical);
	_layoutSurround->addWidget(mdw,0,4, TQt::AlignBottom | TQt::AlignRight);
	_mdws.append(mdw);

	TQLabel* speakerIcon = new TQLabel("Speaker", this);
        icon = UserIcon( "SpeakerFrontLeft" );
	if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
        _layoutSurround->addWidget(speakerIcon,0,1, TQt::AlignTop | TQt::AlignLeft);

        speakerIcon = new TQLabel("Speaker", this);
        icon = UserIcon( "SpeakerFrontRight" );
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
	_layoutSurround->addWidget(speakerIcon,0,3, TQt::AlignTop | TQt::AlignRight);

    }

    if ( _mdSurroundBack != 0 ) {
	MixDeviceWidget *mdw = createMDW(_mdSurroundBack, true, Qt::Vertical);
	_layoutSurround->addWidget(mdw,2,4, TQt::AlignTop | TQt::AlignRight);
	_mdws.append(mdw);

        TQLabel* speakerIcon = new TQLabel("Speaker", this);
        icon = UserIcon( "SpeakerRearLeft" );
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
        _layoutSurround->addWidget(speakerIcon,2,1, TQt::AlignBottom | TQt::AlignLeft);

        speakerIcon = new TQLabel("Speaker", this);
        icon = UserIcon( "SpeakerRearRight" );
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
        _layoutSurround->addWidget(speakerIcon,2,3, TQt::AlignBottom | TQt::AlignRight);


    }

    // !! just for the demo version
    KMixToolBox::setIcons (_mdws, true);
    KMixToolBox::setLabels(_mdws, true);
    KMixToolBox::setTicks (_mdws, true);

    _layoutMDW->activate();
}

void ViewSurround::refreshVolumeLevels() {
    //     kdDebug(67100) << "ViewSurround::refreshVolumeLevels()\n";

     TQWidget *mdw = _mdws.first();
     MixDevice* md;
     for ( md = _mixSet->first(); md != 0; md = _mixSet->next() ) {
	 if ( mdw == 0 ) {
	     kdError(67100) << "ViewSurround::refreshVolumeLevels(): mdw == 0\n";
	     break; // sanity check (normally the lists are set up correctly)
	 }
	 else {
	     if ( mdw->inherits("MDWSlider")) {
		 //kdDebug(67100) << "ViewSurround::refreshVolumeLevels(): updating\n";
		 // a slider, fine. Lets update its value
		 static_cast<MDWSlider*>(mdw)->update();
	     }
	     else {
		 kdError(67100) << "ViewSurround::refreshVolumeLevels(): mdw is not slider\n";
		 // no slider. Cannot happen in theory => skip it
	     }
	 }
	 mdw = _mdws.next();
    }
}


MixDeviceWidget* ViewSurround::createMDW(MixDevice *md, bool small, Qt::Orientation orientation)
{
    MixDeviceWidget* mdw = new MDWSlider(
			    _mixer,       // the mixer for this device
			    md,           // MixDevice (parameter)
			    false,         // Show Mute LED
			    false,        // Show Record LED
			    small,        // Small
			    orientation,  // Orientation
			    this,         // parent
			    this,         // View widget
			    md->name().latin1()
			    );
    return mdw;
}

#include "viewsurround.moc"