1er real; slider x ept ok no evts no map
This commit is contained in:
parent
cd2d0b5da8
commit
3ea2e739ae
10 changed files with 317 additions and 51 deletions
11
qtest.pro
11
qtest.pro
|
|
@ -1,7 +1,8 @@
|
|||
CONFIG += debug console
|
||||
QT += widgets
|
||||
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back"
|
||||
DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back"
|
||||
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back"
|
||||
SOURCES += qtestmain.cpp mainwindow.cpp
|
||||
HEADERS += mainwindow.h
|
||||
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
||||
DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
||||
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
||||
SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp contclasses.cpp
|
||||
HEADERS += qtclasses.h backlasses.h contclasses.h
|
||||
#DESTDIR += "build"
|
||||
|
|
|
|||
73
src/back/backlasses.cpp
Normal file
73
src/back/backlasses.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include <backlasses.h>
|
||||
|
||||
Endpoint::Endpoint(IMMDevice* ep){
|
||||
this->endpoint = ep;
|
||||
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); };
|
||||
}
|
||||
|
||||
void Endpoint::setVolume(float volume) {
|
||||
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, NULL))) { log_debugcpp("si"); };
|
||||
}
|
||||
|
||||
|
||||
void Overseer::initCOMLibrary(){
|
||||
if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { log_debugcpp("si"); };
|
||||
|
||||
|
||||
//Retrieving endpoint enumerator
|
||||
//MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear
|
||||
if(FAILED(CoCreateInstance( __uuidof(MMDeviceEnumerator), NULL,
|
||||
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
|
||||
(void**)&deviceEnumerator)) )
|
||||
{ log_debugcpp("si"); };
|
||||
|
||||
}
|
||||
|
||||
void Overseer::reloadEndpoints() {
|
||||
IMMDeviceCollection *deviceCollection;
|
||||
// | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED
|
||||
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection) ))
|
||||
{ log_debugcpp("si"); };
|
||||
|
||||
|
||||
//Counting them
|
||||
if(FAILED(deviceCollection->GetCount(&numPlaybackEndpoints))) { log_debugcpp("si");};
|
||||
if(numPlaybackEndpoints == 0) { log_debugcpp("si"); };
|
||||
|
||||
|
||||
//Retrieving actual endpoints and storing them on their own class
|
||||
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){
|
||||
IMMDevice *temp;
|
||||
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
|
||||
Endpoint *endpoint = new Endpoint(temp);
|
||||
this->playbackDevices.push_back(endpoint);
|
||||
//TODO: le porblemx std::cout << "ola" << std::endl;
|
||||
}
|
||||
|
||||
deviceCollection->Release();
|
||||
}
|
||||
|
||||
Overseer::Overseer(){
|
||||
//Initializing COM library
|
||||
initCOMLibrary();
|
||||
|
||||
//Obtaining playback endpoint collection on this point in time
|
||||
reloadEndpoints();
|
||||
}
|
||||
|
||||
//Overseer::int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint){
|
||||
//if (FAILED(deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr)))
|
||||
// return 1;
|
||||
//return 0;
|
||||
//}
|
||||
|
||||
//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
|
||||
|
||||
std::vector<Endpoint*> Overseer::getPlaybackEndpoints() {
|
||||
return playbackDevices;
|
||||
}
|
||||
|
||||
//int Overseer::getCaptureEndpoints(std::vector<Endpoint*> *captureEndpoints);
|
||||
|
||||
//IMMDeviceEnumerator** Overseer::setOrigin();
|
||||
|
||||
56
src/back/backlasses.h
Normal file
56
src/back/backlasses.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define log_debugcpp(str) do { \
|
||||
std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \
|
||||
} while (0)
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <Windows.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <combaseapi.h>
|
||||
#include <initguid.h>
|
||||
#include <functiondiscoverykeys_devpkey.h>
|
||||
|
||||
#include <endpointvolume.h>
|
||||
#include <audiopolicy.h>
|
||||
#include <audioclient.h>
|
||||
//#include <comdef.h>
|
||||
//#include <comip.h>
|
||||
#include <Winerror.h>
|
||||
|
||||
class Endpoint {
|
||||
|
||||
public:
|
||||
Endpoint(IMMDevice* endpoint);
|
||||
void setVolume(float volume);
|
||||
|
||||
private:
|
||||
IMMDevice* endpoint;
|
||||
IAudioEndpointVolume *endpointVolume;
|
||||
|
||||
};
|
||||
|
||||
class Overseer {
|
||||
//TODO singleton?
|
||||
public:
|
||||
Overseer();
|
||||
std::vector<Endpoint*> getPlaybackEndpoints();
|
||||
void reloadEndpoints();
|
||||
//~Overseer();
|
||||
//int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint);
|
||||
//int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
|
||||
//int getCaptureEndpoints(std::vector<Endpoint*> *captureEndpoints);
|
||||
//IMMDeviceEnumerator** setOrigin();
|
||||
|
||||
private:
|
||||
unsigned int numPlaybackEndpoints;
|
||||
IMMDeviceEnumerator *deviceEnumerator;
|
||||
std::vector<Endpoint*> playbackDevices;
|
||||
void initCOMLibrary();
|
||||
//IMMDeviceCollection *deviceCollection;
|
||||
//int numCaptureEndpoints;
|
||||
//std::vector<Endpoint*> *captureDevices;
|
||||
};
|
||||
|
||||
27
src/cont/contclasses.cpp
Normal file
27
src/cont/contclasses.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "contclasses.h"
|
||||
|
||||
Overseer OverseerHandler::os;
|
||||
|
||||
EndpointHandler::EndpointHandler(Endpoint *ept, QObject *parent) : QObject(parent) {
|
||||
this->ept = ept;
|
||||
}
|
||||
|
||||
void EndpointHandler::setValue(int value){
|
||||
ept->setVolume((float)value / 100);
|
||||
}
|
||||
|
||||
Overseer OverseerHandler::getOverseer(){
|
||||
return os;
|
||||
}
|
||||
|
||||
OverseerHandler::OverseerHandler(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
std::vector<EndpointHandler*>* OverseerHandler::getEndpointHandlers(){
|
||||
return endpointHandlers;
|
||||
}
|
||||
|
||||
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> *ephs){
|
||||
this->endpointHandlers = ephs;
|
||||
}
|
||||
46
src/cont/contclasses.h
Normal file
46
src/cont/contclasses.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
#include <QObject>
|
||||
#include "backlasses.h"
|
||||
|
||||
|
||||
class EndpointHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EndpointHandler(Endpoint *ept, QObject *parent = nullptr);
|
||||
|
||||
|
||||
private:
|
||||
Endpoint *ept;
|
||||
//QSlider *slidy;
|
||||
|
||||
public slots:
|
||||
void setValue(int value);
|
||||
|
||||
|
||||
//signals:
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class OverseerHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OverseerHandler(QObject *parent = nullptr);
|
||||
void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||
std::vector<EndpointHandler*>* getEndpointHandlers();
|
||||
static Overseer getOverseer();
|
||||
|
||||
private:
|
||||
static Overseer os;
|
||||
std::vector<EndpointHandler*> *endpointHandlers;
|
||||
//QSlider *slidy;
|
||||
|
||||
//public slots:
|
||||
//void setValue(int value);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||||
// setWindowState(Qt::WindowFullScreen);
|
||||
// setCentralWidget(centralWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* void MainWindow::setPlotButton() {
|
||||
* button = new QPushButton("push"),
|
||||
* button->setCheckable(true);
|
||||
* connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)))
|
||||
* QHBoxLayout *plotsLayout = new QHBoxLayout;
|
||||
* plotsLayout->setSpacing(10);
|
||||
* plotsLayout->addWidget(funPlot);
|
||||
* QHBoxLayout *buttonsLayout = new QHBoxLayout ;
|
||||
* buttonsLayout->addWidget(button);
|
||||
* QVBoxLayout *widgetLayout = new QVBoxLayout;
|
||||
* widgetLayout->addLayout(plotsLayout);
|
||||
* widgetLayout->addLayout(buttonsLayout);
|
||||
* setLayout(widgetLayout);
|
||||
* ...
|
||||
*/
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
//QWidget *centralWidget;
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
48
src/qt/qtclasses.cpp
Normal file
48
src/qt/qtclasses.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include "qtclasses.h"
|
||||
|
||||
MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : QMainWindow(parent) {
|
||||
// setWindowState(Qt::WindowFullScreen);
|
||||
// setCentralWidget(centralWidget);
|
||||
widget = new QWidget();
|
||||
layout = new QGridLayout();
|
||||
pintas = new QLabel(tr("Defaulto da"));
|
||||
|
||||
widget->setLayout(layout);
|
||||
setCentralWidget(widget);
|
||||
layout->addWidget(pintas, 0, 0);
|
||||
|
||||
setWindowTitle("slidea resbala nu c");
|
||||
|
||||
setEndpointHandlers(ephs);
|
||||
for (unsigned int i = 0; i < this->ephs->size(); i++){
|
||||
QSlider *teSlider = new QSlider(Qt::Horizontal);
|
||||
teSlider->setFocusPolicy(Qt::StrongFocus);
|
||||
teSlider->setTickPosition(QSlider::TicksBothSides);
|
||||
teSlider->setTickInterval(5);
|
||||
teSlider->setSingleStep(1);
|
||||
layout->addWidget(teSlider, 0, i + 1);
|
||||
connect(teSlider, &QSlider::valueChanged, ephs->at(i), &EndpointHandler::setValue);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setEndpointHandlers(std::vector<EndpointHandler*> *ephs){
|
||||
this->ephs = ephs;
|
||||
}
|
||||
|
||||
/*
|
||||
* void MainWindow::setPlotButton() {
|
||||
* button = new QPushButton("push"),
|
||||
* button->setCheckable(true);
|
||||
* connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)))
|
||||
* QHBoxLayout *plotsLayout = new QHBoxLayout;
|
||||
* plotsLayout->setSpacing(10);
|
||||
* plotsLayout->addWidget(funPlot);
|
||||
* QHBoxLayout *buttonsLayout = new QHBoxLayout ;
|
||||
* buttonsLayout->addWidget(button);
|
||||
* QVBoxLayout *widgetLayout = new QVBoxLayout;
|
||||
* widgetLayout->addLayout(plotsLayout);
|
||||
* widgetLayout->addLayout(buttonsLayout);
|
||||
* setLayout(widgetLayout);
|
||||
* ...
|
||||
*/
|
||||
|
||||
38
src/qt/qtclasses.h
Normal file
38
src/qt/qtclasses.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <vector>
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QSlider>
|
||||
#include <QGridLayout>
|
||||
#include "contclasses.h"
|
||||
//#include <Q>
|
||||
//#include <QWidgets>
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
//QWidget *centralWidget;
|
||||
|
||||
public:
|
||||
MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
std::vector<EndpointHandler*> *ephs;
|
||||
std::vector<QSlider> *sliders;
|
||||
QWidget *widget;
|
||||
QGridLayout *layout;
|
||||
QLabel *pintas;
|
||||
|
||||
//public slots:
|
||||
// void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||
|
||||
//signals:
|
||||
//void valueChanged(int value);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,15 +1,20 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
|
||||
//#include <qapplicationstatic.h>
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "qtclasses.h"
|
||||
//TODO david #include "backlasses.h"
|
||||
|
||||
|
||||
//INIT BACK
|
||||
OverseerHandler *osh = new OverseerHandler();
|
||||
|
||||
QApplication* createApplication(int &argc, char *argv[])
|
||||
{
|
||||
return new QApplication(argc, argv);
|
||||
|
|
@ -17,9 +22,21 @@ QApplication* createApplication(int &argc, char *argv[])
|
|||
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
QApplication::setStyle("windowsvista");
|
||||
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
||||
MainWindow window = MainWindow();
|
||||
//QApplication::setStyle("windowsvista");
|
||||
//INIT CONT
|
||||
std::vector<Endpoint*> epts = OverseerHandler::getOverseer().getPlaybackEndpoints();
|
||||
std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
|
||||
for(unsigned int i = 0; i < epts.size(); i++){
|
||||
EndpointHandler *eph = new EndpointHandler(epts.at(i));
|
||||
ephs->push_back(eph);
|
||||
}
|
||||
|
||||
osh->setEndpointHandlers(ephs);
|
||||
//INIT FRONT
|
||||
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
||||
MainWindow window = MainWindow(ephs);
|
||||
window.setEndpointHandlers(ephs);
|
||||
app->setStyle("windowsvista");
|
||||
window.show();
|
||||
return app->exec();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue