Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Finish up the new pc-mixer utility. The main Mixer GUI is done now, a…
Browse files Browse the repository at this point in the history
…nd it all works great!
  • Loading branch information
Ken Moore committed Mar 7, 2014
1 parent 86c3cc9 commit 0c784d0
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 12 deletions.
119 changes: 119 additions & 0 deletions src-qt4/pc-mixer/DeviceWidget.cpp
@@ -0,0 +1,119 @@
#include "DeviceWidget.h"
#include "ui_DeviceWidget.h"

DeviceWidget::DeviceWidget(QWidget *parent) : QWidget(parent), ui(new Ui::DeviceWidget){
ui->setupUi(this); //Load the designer file
//Initialize the rest of the items
islinked = true;
ismuted = false;
changing = false; //if true, slots will be de-activated
CRV = 0; CLV = 0;
//connect the signals/slots
connect(ui->slider_L, SIGNAL(valueChanged(int)), this, SLOT(LSliderChanged(int)) );
connect(ui->slider_R, SIGNAL(valueChanged(int)), this, SLOT(RSliderChanged(int)) );
connect(ui->push_mute, SIGNAL(clicked()), this, SLOT(muteClicked()) );
connect(ui->tool_chain, SIGNAL(clicked()), this, SLOT(linkClicked()) );
}

DeviceWidget::~DeviceWidget(){

}

//===============
// PUBLIC
//===============
void DeviceWidget::setupDevice(QString device, int Lvol, int Rvol){
changing = true; //going to change the sliders
ui->label_device->setText(device);
ui->slider_L->setValue(Lvol);
ui->slider_R->setValue(Rvol);
islinked = (Lvol == Rvol);
ismuted = (islinked && (Lvol == 0) );
changing = false; //done making changes
updateButtons();
}

QString DeviceWidget::device(){
return ui->label_device->text();
}

int DeviceWidget::LVolume(){
return ui->slider_L->value();
}

int DeviceWidget::RVolume(){
return ui->slider_R->value();
}

//===============
// PRIVATE
//===============
void DeviceWidget::updateButtons(){
//Update the button icons/text as necessary
if(islinked){
ui->tool_chain->setIcon(QIcon(":icons/link.png"));
}else{
ui->tool_chain->setIcon(QIcon(":icons/link_break.png"));
}
if(ismuted){
ui->push_mute->setIcon( QIcon(":icons/audio-volume-high.png") );
ui->push_mute->setText( tr("Unmute") );
}else{
ui->push_mute->setIcon( QIcon(":icons/audio-volume-muted.png") );
ui->push_mute->setText( tr("Mute") );
}
}

void DeviceWidget::updateVolumes(int Lvol, int Rvol){
changing=true; //going to change the sliders
//Update the sliders
if(ui->slider_L->value() != Lvol){ ui->slider_L->setValue(Lvol); }
if(ui->slider_R->value() != Rvol){ ui->slider_R->setValue(Rvol); }
changing = false; //done making changes to sliders
ismuted = (Lvol==Rvol) && (Lvol ==0);
updateButtons(); //make sure to update the buttons now
//Now adjust the backend mixer to reflect the changes
Mixer::setValues(ui->label_device->text(), Lvol, Rvol);
emit deviceChanged( ui->label_device->text() );
}

//===============
// PRIVATE SLOTS
//===============
void DeviceWidget::muteClicked(){
if(ismuted){
if(CLV==0 && CRV==0){
updateVolumes(50,50);
}else{
updateVolumes(CLV, CRV);
}
}else{
CLV = ui->slider_L->value(); CRV = ui->slider_R->value(); //save for later
updateVolumes(0,0);
}
}

void DeviceWidget::linkClicked(){
islinked = !islinked; //flip to the other
updateButtons();
}

void DeviceWidget::LSliderChanged(int Lvol){
if(changing){ return; } //no double-taps while class is making adjustments
if(islinked){
updateVolumes(Lvol, Lvol);
}else{
updateVolumes(Lvol, ui->slider_R->value() );
}

}

void DeviceWidget::RSliderChanged(int Rvol){
if(changing){ return; } //no double-taps while class is making adjustments
if(islinked){
updateVolumes(Rvol, Rvol);
}else{
updateVolumes(ui->slider_L->value(), Rvol);
}
}

44 changes: 44 additions & 0 deletions src-qt4/pc-mixer/DeviceWidget.h
@@ -0,0 +1,44 @@
#ifndef _MIXER_DEVICE_WIDGET_H
#define _MIXER_DEVICE_WIDGET_H

#include <QWidget>
#include <QString>

#include "MixerBackend.h"

namespace Ui{
class DeviceWidget;
};

class DeviceWidget : public QWidget{
Q_OBJECT
public:
DeviceWidget(QWidget *parent = 0);
~DeviceWidget();

void setupDevice(QString device, int Lvol, int Rvol);

QString device();
int LVolume();
int RVolume();

private:
Ui::DeviceWidget *ui;
int CRV, CLV; //Current R/L volume (in case it was muted)
bool changing, ismuted, islinked; // internal status flags

void updateVolumes(int, int);
void updateButtons();

private slots:
void muteClicked();
void linkClicked();
void LSliderChanged(int);
void RSliderChanged(int);

signals:
void deviceChanged(QString);

};

#endif
144 changes: 144 additions & 0 deletions src-qt4/pc-mixer/DeviceWidget.ui
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DeviceWidget</class>
<widget class="QWidget" name="DeviceWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>87</width>
<height>191</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_device">
<property name="text">
<string notr="true">device</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QSlider" name="slider_R">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QSlider" name="slider_L">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>0</number>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>L</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tool_chain">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="pc-mixer.qrc">
<normaloff>:/icons/link.png</normaloff>:/icons/link.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>R</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="push_mute">
<property name="text">
<string>Mute</string>
</property>
<property name="icon">
<iconset resource="pc-mixer.qrc">
<normaloff>:/icons/audio-volume-muted.png</normaloff>:/icons/audio-volume-muted.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="pc-mixer.qrc"/>
</resources>
<connections/>
</ui>
17 changes: 14 additions & 3 deletions src-qt4/pc-mixer/MixerGUI.cpp
Expand Up @@ -17,11 +17,14 @@ MixerGUI::~MixerGUI(){
void MixerGUI::updateGUI(){
//Load the list of available devices
QStringList devList = Mixer::getDevices();
devList.sort();
//devList.sort();
//Clear the UI
ui->combo_default->disconnect();
ui->combo_default->clear();

delete ui->scrollArea->widget(); //delete the widget and all children
ui->scrollArea->setWidget( new QWidget() ); //create a new widget in the scroll area
ui->scrollArea->widget()->setContentsMargins(0,0,0,0);
QHBoxLayout *layout = new QHBoxLayout;
//Now Fill the UI with the devices
QString cdefault = settings->value("tray-device", "vol").toString();
for(int i=0; i<devList.length(); i++){
Expand All @@ -30,13 +33,21 @@ void MixerGUI::updateGUI(){
int Lval = devList[i].section(":",1,1).toInt();
int Rval = devList[i].section(":",2,2).toInt();
//Now create the device widget

DeviceWidget *device = new DeviceWidget(this);
device->setupDevice(dev, Lval, Rval);
layout->addWidget(device);
connect(device, SIGNAL(deviceChanged(QString)), this, SLOT(itemChanged(QString)) );
//Now add the device to the default List
ui->combo_default->addItem(dev);
if(dev == cdefault){
ui->combo_default->setCurrentIndex(i);
}
}
layout->addStretch(); //add spacer to the end
layout->setContentsMargins(2,2,2,2);
layout->setSpacing(4);
ui->scrollArea->widget()->setLayout(layout);
ui->scrollArea->setMinimumHeight(ui->scrollArea->widget()->minimumSizeHint().height()+ui->scrollArea->horizontalScrollBar()->height());
//re-connect combobox signal
connect(ui->combo_default, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeDefaultTrayDevice(QString)) );
}
Expand Down
3 changes: 3 additions & 0 deletions src-qt4/pc-mixer/MixerGUI.h
Expand Up @@ -5,7 +5,10 @@
#include <QSettings>
#include <QCloseEvent>
#include <QCoreApplication>
#include <QHBoxLayout>
#include <QScrollBar>

#include "DeviceWidget.h"
#include "MixerBackend.h"

namespace Ui{
Expand Down

0 comments on commit 0c784d0

Please sign in to comment.